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_security.h"
21 
22 /**
23  * Configure a security session on a device.
24  *
25  * @param	device		Crypto/eth device pointer
26  * @param	conf		Security session configuration
27  * @param	sess		Pointer to Security private session structure
28  * @param	mp		Mempool where the private session is allocated
29  *
30  * @return
31  *  - Returns 0 if private session structure have been created successfully.
32  *  - Returns -EINVAL if input parameters are invalid.
33  *  - Returns -ENOTSUP if crypto device does not support the crypto transform.
34  *  - Returns -ENOMEM if the private session could not be allocated.
35  */
36 typedef int (*security_session_create_t)(void *device,
37 		struct rte_security_session_conf *conf,
38 		struct rte_security_session *sess,
39 		struct rte_mempool *mp);
40 
41 /**
42  * Free driver private session data.
43  *
44  * @param	dev		Crypto/eth device pointer
45  * @param	sess		Security session structure
46  */
47 typedef int (*security_session_destroy_t)(void *device,
48 		struct rte_security_session *sess);
49 
50 /**
51  * Update driver private session data.
52  *
53  * @param	device		Crypto/eth device pointer
54  * @param	sess		Pointer to Security private session structure
55  * @param	conf		Security session configuration
56  *
57  * @return
58  *  - Returns 0 if private session structure have been updated successfully.
59  *  - Returns -EINVAL if input parameters are invalid.
60  *  - Returns -ENOTSUP if crypto device does not support the crypto transform.
61  */
62 typedef int (*security_session_update_t)(void *device,
63 		struct rte_security_session *sess,
64 		struct rte_security_session_conf *conf);
65 
66 /**
67  * Get the size of a security session
68  *
69  * @param	device		Crypto/eth device pointer
70  *
71  * @return
72  *  - On success returns the size of the session structure for device
73  *  - On failure returns 0
74  */
75 typedef unsigned int (*security_session_get_size)(void *device);
76 
77 /**
78  * Get stats from the PMD.
79  *
80  * @param	device		Crypto/eth device pointer
81  * @param	sess		Pointer to Security private session structure
82  * @param	stats		Security stats of the driver
83  *
84  * @return
85  *  - Returns 0 if private session structure have been updated successfully.
86  *  - Returns -EINVAL if session parameters are invalid.
87  */
88 typedef int (*security_session_stats_get_t)(void *device,
89 		struct rte_security_session *sess,
90 		struct rte_security_stats *stats);
91 
92 __rte_experimental
93 int rte_security_dynfield_register(void);
94 
95 /**
96  * Update the mbuf with provided metadata.
97  *
98  * @param	sess		Security session structure
99  * @param	mb		Packet buffer
100  * @param	mt		Metadata
101  *
102  * @return
103  *  - Returns 0 if metadata updated successfully.
104  *  - Returns -ve value for errors.
105  */
106 typedef int (*security_set_pkt_metadata_t)(void *device,
107 		struct rte_security_session *sess, struct rte_mbuf *m,
108 		void *params);
109 
110 /**
111  * Get application specific userdata associated with the security session.
112  * Device specific metadata provided would be used to uniquely identify
113  * the security session being referred to.
114  *
115  * @param	device		Crypto/eth device pointer
116  * @param	md		Metadata
117  * @param	userdata	Pointer to receive userdata
118  *
119  * @return
120  *  - Returns 0 if userdata is retrieved successfully.
121  *  - Returns -ve value for errors.
122  */
123 typedef int (*security_get_userdata_t)(void *device,
124 		uint64_t md, void **userdata);
125 
126 /**
127  * Get security capabilities of the device.
128  *
129  * @param	device		crypto/eth device pointer
130  *
131  * @return
132  *  - Returns rte_security_capability pointer on success.
133  *  - Returns NULL on error.
134  */
135 typedef const struct rte_security_capability *(*security_capabilities_get_t)(
136 		void *device);
137 
138 /** Security operations function pointer table */
139 struct rte_security_ops {
140 	security_session_create_t session_create;
141 	/**< Configure a security session. */
142 	security_session_update_t session_update;
143 	/**< Update a security session. */
144 	security_session_get_size session_get_size;
145 	/**< Return size of security session. */
146 	security_session_stats_get_t session_stats_get;
147 	/**< Get security session statistics. */
148 	security_session_destroy_t session_destroy;
149 	/**< Clear a security sessions private data. */
150 	security_set_pkt_metadata_t set_pkt_metadata;
151 	/**< Update mbuf metadata. */
152 	security_get_userdata_t get_userdata;
153 	/**< Get userdata associated with session which processed the packet. */
154 	security_capabilities_get_t capabilities_get;
155 	/**< Get security capabilities. */
156 };
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif /* _RTE_SECURITY_DRIVER_H_ */
163