xref: /dpdk/lib/security/rte_security_driver.h (revision af0785a2447b307965377b62f46a5f39457a85a3)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017 NXP.
3  * Copyright(c) 2017 Intel Corporation.
4  */
5 
6 #ifndef _RTE_SECURITY_DRIVER_H_
7 #define _RTE_SECURITY_DRIVER_H_
8 
9 /**
10  * @file rte_security_driver.h
11  *
12  * RTE Security Common Definitions
13  *
14  */
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <rte_compat.h>
21 #include "rte_security.h"
22 
23 /**
24  * @internal
25  * Security session to be used by library for internal usage
26  */
27 struct rte_security_session {
28 	RTE_MARKER cacheline0;
29 	uint64_t opaque_data;
30 	/**< Opaque user defined data */
31 	uint64_t fast_mdata;
32 	/**< Fast metadata to be used for inline path */
33 	rte_iova_t driver_priv_data_iova;
34 	/**< session private data IOVA address */
35 
36 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
37 	uint8_t driver_priv_data[0];
38 	/**< Private session material, variable size (depends on driver) */
39 };
40 
41 /**
42  * Helper macro to get driver private data
43  */
44 #define SECURITY_GET_SESS_PRIV(s) \
45 	((void *)(((struct rte_security_session *)s)->driver_priv_data))
46 #define SECURITY_GET_SESS_PRIV_IOVA(s) \
47 	(((struct rte_security_session *)s)->driver_priv_data_iova)
48 
49 /**
50  * Configure a security session on a device.
51  *
52  * @param	device		Crypto/eth device pointer
53  * @param	conf		Security session configuration
54  * @param	sess		Pointer to Security private session structure
55  *
56  * @return
57  *  - Returns 0 if private session structure have been created successfully.
58  *  - Returns -EINVAL if input parameters are invalid.
59  *  - Returns -ENOTSUP if crypto device does not support the crypto transform.
60  */
61 typedef int (*security_session_create_t)(void *device,
62 		struct rte_security_session_conf *conf,
63 		struct rte_security_session *sess);
64 
65 /**
66  * Free driver private session data.
67  *
68  * @param	device		Crypto/eth device pointer
69  * @param	sess		Security session structure
70  */
71 typedef int (*security_session_destroy_t)(void *device,
72 		struct rte_security_session *sess);
73 
74 /**
75  * Update driver private session data.
76  *
77  * @param	device		Crypto/eth device pointer
78  * @param	sess		Pointer to Security private session structure
79  * @param	conf		Security session configuration
80  *
81  * @return
82  *  - Returns 0 if private session structure have been updated successfully.
83  *  - Returns -EINVAL if input parameters are invalid.
84  *  - Returns -ENOTSUP if crypto device does not support the crypto transform.
85  */
86 typedef int (*security_session_update_t)(void *device,
87 		struct rte_security_session *sess,
88 		struct rte_security_session_conf *conf);
89 
90 /**
91  * Configure a MACsec secure channel (SC) on a device.
92  *
93  * @param	device		Crypto/eth device pointer
94  * @param	conf		MACsec SC configuration params
95  *
96  * @return
97  *  - positive sc_id if SC is created successfully.
98  *  - -EINVAL if input parameters are invalid.
99  *  - -ENOTSUP if device does not support MACsec.
100  *  - -ENOMEM if the SC cannot be created.
101  */
102 typedef int (*security_macsec_sc_create_t)(void *device, struct rte_security_macsec_sc *conf);
103 
104 /**
105  * Free MACsec secure channel (SC).
106  *
107  * @param	device		Crypto/eth device pointer
108  * @param	sc_id		MACsec SC ID
109  */
110 typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id);
111 
112 /**
113  * Configure a MACsec security Association (SA) on a device.
114  *
115  * @param	device		Crypto/eth device pointer
116  * @param	conf		MACsec SA configuration params
117  *
118  * @return
119  *  - positive sa_id if SA is created successfully.
120  *  - -EINVAL if input parameters are invalid.
121  *  - -ENOTSUP if device does not support MACsec.
122  *  - -ENOMEM if the SA cannot be created.
123  */
124 typedef int (*security_macsec_sa_create_t)(void *device, struct rte_security_macsec_sa *conf);
125 
126 /**
127  * Free MACsec security association (SA).
128  *
129  * @param	device		Crypto/eth device pointer
130  * @param	sa_id		MACsec SA ID
131  */
132 typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id);
133 
134 /**
135  * Get the size of a security session
136  *
137  * @param	device		Crypto/eth device pointer
138  *
139  * @return
140  *  - On success returns the size of the session structure for device
141  *  - On failure returns 0
142  */
143 typedef unsigned int (*security_session_get_size)(void *device);
144 
145 /**
146  * Get stats from the PMD.
147  *
148  * @param	device		Crypto/eth device pointer
149  * @param	sess		Pointer to Security private session structure
150  * @param	stats		Security stats of the driver
151  *
152  * @return
153  *  - Returns 0 if private session structure have been updated successfully.
154  *  - Returns -EINVAL if session parameters are invalid.
155  */
156 typedef int (*security_session_stats_get_t)(void *device,
157 		struct rte_security_session *sess,
158 		struct rte_security_stats *stats);
159 
160 /**
161  * Get MACsec secure channel stats from the PMD.
162  *
163  * @param	device		Crypto/eth device pointer
164  * @param	sc_id		secure channel ID created by rte_security_macsec_sc_create()
165  * @param	stats		SC stats of the driver
166  *
167  * @return
168  *  - 0 if success.
169  *  - -EINVAL if sc_id or device is invalid.
170  */
171 typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
172 		struct rte_security_macsec_sc_stats *stats);
173 
174 /**
175  * Get MACsec SA stats from the PMD.
176  *
177  * @param	device		Crypto/eth device pointer
178  * @param	sa_id		secure channel ID created by rte_security_macsec_sc_create()
179  * @param	stats		SC stats of the driver
180  *
181  * @return
182  *  - 0 if success.
183  *  - -EINVAL if sa_id or device is invalid.
184  */
185 typedef int (*security_macsec_sa_stats_get_t)(void *device, uint16_t sa_id,
186 		struct rte_security_macsec_sa_stats *stats);
187 
188 
189 
190 __rte_internal
191 int rte_security_dynfield_register(void);
192 
193 /**
194  * Update the mbuf with provided metadata.
195  *
196  * @param	device		Crypto/eth device pointer
197  * @param	sess		Security session structure
198  * @param	mb		Packet buffer
199  * @param	params		Metadata
200  *
201  * @return
202  *  - Returns 0 if metadata updated successfully.
203  *  - Returns -ve value for errors.
204  */
205 typedef int (*security_set_pkt_metadata_t)(void *device,
206 		struct rte_security_session *sess, struct rte_mbuf *mb,
207 		void *params);
208 
209 /**
210  * Get security capabilities of the device.
211  *
212  * @param	device		crypto/eth device pointer
213  *
214  * @return
215  *  - Returns rte_security_capability pointer on success.
216  *  - Returns NULL on error.
217  */
218 typedef const struct rte_security_capability *(*security_capabilities_get_t)(
219 		void *device);
220 
221 /** Security operations function pointer table */
222 struct rte_security_ops {
223 	security_session_create_t session_create;
224 	/**< Configure a security session. */
225 	security_session_update_t session_update;
226 	/**< Update a security session. */
227 	security_session_get_size session_get_size;
228 	/**< Return size of security session. */
229 	security_session_stats_get_t session_stats_get;
230 	/**< Get security session statistics. */
231 	security_session_destroy_t session_destroy;
232 	/**< Clear a security sessions private data. */
233 	security_set_pkt_metadata_t set_pkt_metadata;
234 	/**< Update mbuf metadata. */
235 	security_capabilities_get_t capabilities_get;
236 	/**< Get security capabilities. */
237 	security_macsec_sc_create_t macsec_sc_create;
238 	/**< Configure a MACsec security channel (SC). */
239 	security_macsec_sc_destroy_t macsec_sc_destroy;
240 	/**< Free a MACsec security channel (SC). */
241 	security_macsec_sa_create_t macsec_sa_create;
242 	/**< Configure a MACsec security association (SA). */
243 	security_macsec_sa_destroy_t macsec_sa_destroy;
244 	/**< Free a MACsec security association (SA). */
245 	security_macsec_sc_stats_get_t macsec_sc_stats_get;
246 	/**< Get MACsec SC statistics. */
247 	security_macsec_sa_stats_get_t macsec_sa_stats_get;
248 	/**< Get MACsec SA statistics. */
249 };
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 #endif /* _RTE_SECURITY_DRIVER_H_ */
256