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