xref: /dpdk/lib/security/rte_security_driver.h (revision a8ca598cd8e696b4135f04cdd86a93b12fd5642a)
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  * @param	dir		Direction of SC
110  */
111 typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id,
112 		enum rte_security_macsec_direction dir);
113 
114 /**
115  * Configure a MACsec security Association (SA) on a device.
116  *
117  * @param	device		Crypto/eth device pointer
118  * @param	conf		MACsec SA configuration params
119  *
120  * @return
121  *  - positive sa_id if SA is created successfully.
122  *  - -EINVAL if input parameters are invalid.
123  *  - -ENOTSUP if device does not support MACsec.
124  *  - -ENOMEM if the SA cannot be created.
125  */
126 typedef int (*security_macsec_sa_create_t)(void *device, struct rte_security_macsec_sa *conf);
127 
128 /**
129  * Free MACsec security association (SA).
130  *
131  * @param	device		Crypto/eth device pointer
132  * @param	sa_id		MACsec SA ID
133  * @param	dir		Direction of SA
134  */
135 typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id,
136 		enum rte_security_macsec_direction dir);
137 
138 /**
139  * Get the size of a security session
140  *
141  * @param	device		Crypto/eth device pointer
142  *
143  * @return
144  *  - On success returns the size of the session structure for device
145  *  - On failure returns 0
146  */
147 typedef unsigned int (*security_session_get_size)(void *device);
148 
149 /**
150  * Get stats from the PMD.
151  *
152  * @param	device		Crypto/eth device pointer
153  * @param	sess		Pointer to Security private session structure
154  * @param	stats		Security stats of the driver
155  *
156  * @return
157  *  - Returns 0 if private session structure have been updated successfully.
158  *  - Returns -EINVAL if session parameters are invalid.
159  */
160 typedef int (*security_session_stats_get_t)(void *device,
161 		struct rte_security_session *sess,
162 		struct rte_security_stats *stats);
163 
164 /**
165  * Get MACsec secure channel stats from the PMD.
166  *
167  * @param	device		Crypto/eth device pointer
168  * @param	sc_id		secure channel ID created by rte_security_macsec_sc_create()
169  * @param	dir		direction of SC
170  * @param	stats		SC stats of the driver
171  *
172  * @return
173  *  - 0 if success.
174  *  - -EINVAL if sc_id or device is invalid.
175  */
176 typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
177 		enum rte_security_macsec_direction dir,
178 		struct rte_security_macsec_sc_stats *stats);
179 
180 /**
181  * Get MACsec SA stats from the PMD.
182  *
183  * @param	device		Crypto/eth device pointer
184  * @param	sa_id		secure channel ID created by rte_security_macsec_sc_create()
185  * @param	dir		direction of SA
186  * @param	stats		SC stats of the driver
187  *
188  * @return
189  *  - 0 if success.
190  *  - -EINVAL if sa_id or device is invalid.
191  */
192 typedef int (*security_macsec_sa_stats_get_t)(void *device, uint16_t sa_id,
193 		enum rte_security_macsec_direction dir,
194 		struct rte_security_macsec_sa_stats *stats);
195 
196 
197 
198 __rte_internal
199 int rte_security_dynfield_register(void);
200 
201 /**
202  * Update the mbuf with provided metadata.
203  *
204  * @param	device		Crypto/eth device pointer
205  * @param	sess		Security session structure
206  * @param	mb		Packet buffer
207  * @param	params		Metadata
208  *
209  * @return
210  *  - Returns 0 if metadata updated successfully.
211  *  - Returns -ve value for errors.
212  */
213 typedef int (*security_set_pkt_metadata_t)(void *device,
214 		struct rte_security_session *sess, struct rte_mbuf *mb,
215 		void *params);
216 
217 /**
218  * Get security capabilities of the device.
219  *
220  * @param	device		crypto/eth device pointer
221  *
222  * @return
223  *  - Returns rte_security_capability pointer on success.
224  *  - Returns NULL on error.
225  */
226 typedef const struct rte_security_capability *(*security_capabilities_get_t)(
227 		void *device);
228 
229 /** Security operations function pointer table */
230 struct rte_security_ops {
231 	security_session_create_t session_create;
232 	/**< Configure a security session. */
233 	security_session_update_t session_update;
234 	/**< Update a security session. */
235 	security_session_get_size session_get_size;
236 	/**< Return size of security session. */
237 	security_session_stats_get_t session_stats_get;
238 	/**< Get security session statistics. */
239 	security_session_destroy_t session_destroy;
240 	/**< Clear a security sessions private data. */
241 	security_set_pkt_metadata_t set_pkt_metadata;
242 	/**< Update mbuf metadata. */
243 	security_capabilities_get_t capabilities_get;
244 	/**< Get security capabilities. */
245 	security_macsec_sc_create_t macsec_sc_create;
246 	/**< Configure a MACsec security channel (SC). */
247 	security_macsec_sc_destroy_t macsec_sc_destroy;
248 	/**< Free a MACsec security channel (SC). */
249 	security_macsec_sa_create_t macsec_sa_create;
250 	/**< Configure a MACsec security association (SA). */
251 	security_macsec_sa_destroy_t macsec_sa_destroy;
252 	/**< Free a MACsec security association (SA). */
253 	security_macsec_sc_stats_get_t macsec_sc_stats_get;
254 	/**< Get MACsec SC statistics. */
255 	security_macsec_sa_stats_get_t macsec_sa_stats_get;
256 	/**< Get MACsec SA statistics. */
257 };
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif /* _RTE_SECURITY_DRIVER_H_ */
264