struct rte_cryptodev_asym_session_pool_private_data {
uint16_t max_priv_session_sz;
/**< Size of private session data used when creating mempool */
+ uint16_t user_data_sz;
+ /**< Session user data will be placed after sess_private_data */
};
int
struct rte_mempool *
rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
- uint32_t cache_size, int socket_id)
+ uint32_t cache_size, uint16_t user_data_size, int socket_id)
{
struct rte_mempool *mp;
struct rte_cryptodev_asym_session_pool_private_data *pool_priv;
return NULL;
}
- obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz;
+ obj_sz = rte_cryptodev_asym_get_header_session_size() + max_priv_sz +
+ user_data_size;
obj_sz_aligned = RTE_ALIGN_CEIL(obj_sz, RTE_CACHE_LINE_SIZE);
mp = rte_mempool_create(name, nb_elts, obj_sz_aligned, cache_size,
return NULL;
}
pool_priv->max_priv_session_sz = max_priv_sz;
+ pool_priv->user_data_sz = user_data_size;
rte_cryptodev_trace_asym_session_pool_create(name, nb_elts,
- cache_size, mp);
+ user_data_size, cache_size, mp);
return mp;
}
return sess;
}
-struct rte_cryptodev_asym_session *
+int
rte_cryptodev_asym_session_create(uint8_t dev_id,
- struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp)
+ struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
+ void **session)
{
struct rte_cryptodev_asym_session *sess;
uint32_t session_priv_data_sz;
if (!rte_cryptodev_is_valid_dev(dev_id)) {
CDEV_LOG_ERR("Invalid dev_id=%" PRIu8, dev_id);
- return NULL;
+ return -EINVAL;
}
dev = rte_cryptodev_pmd_get_dev(dev_id);
if (dev == NULL)
- return NULL;
+ return -EINVAL;
if (!mp) {
CDEV_LOG_ERR("invalid mempool\n");
- return NULL;
+ return -EINVAL;
}
session_priv_data_sz = rte_cryptodev_asym_get_private_session_size(
if (pool_priv->max_priv_session_sz < session_priv_data_sz) {
CDEV_LOG_DEBUG(
"The private session data size used when creating the mempool is smaller than this device's private session data.");
- return NULL;
+ return -EINVAL;
}
/* Verify if provided mempool can hold elements big enough. */
if (mp->elt_size < session_header_size + session_priv_data_sz) {
CDEV_LOG_ERR(
"mempool elements too small to hold session objects");
- return NULL;
+ return -EINVAL;
}
/* Allocate a session structure from the session pool */
- if (rte_mempool_get(mp, (void **)&sess)) {
+ if (rte_mempool_get(mp, session)) {
CDEV_LOG_ERR("couldn't get object from session mempool");
- return NULL;
+ return -ENOMEM;
}
+ sess = *session;
sess->driver_id = dev->driver_id;
+ sess->user_data_sz = pool_priv->user_data_sz;
sess->max_priv_data_sz = pool_priv->max_priv_session_sz;
/* Clear device session pointer.*/
- memset(sess->sess_private_data, 0, session_priv_data_sz);
+ memset(sess->sess_private_data, 0, session_priv_data_sz + sess->user_data_sz);
- RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, NULL);
+ RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->asym_session_configure, -ENOTSUP);
if (sess->sess_private_data[0] == 0) {
ret = dev->dev_ops->asym_session_configure(dev, xforms, sess);
CDEV_LOG_ERR(
"dev_id %d failed to configure session details",
dev_id);
- return NULL;
+ return ret;
}
}
- rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp);
- return sess;
+ rte_cryptodev_trace_asym_session_create(dev_id, xforms, mp, sess);
+ return 0;
}
int
}
int
-rte_cryptodev_asym_session_free(uint8_t dev_id,
- struct rte_cryptodev_asym_session *sess)
+rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess)
{
struct rte_mempool *sess_mp;
struct rte_cryptodev *dev;
return (void *)(sess->sess_data + sess->nb_drivers);
}
+int
+rte_cryptodev_asym_session_set_user_data(void *session, void *data, uint16_t size)
+{
+ struct rte_cryptodev_asym_session *sess = session;
+ if (sess == NULL)
+ return -EINVAL;
+
+ if (sess->user_data_sz < size)
+ return -ENOMEM;
+
+ rte_memcpy(sess->sess_private_data +
+ sess->max_priv_data_sz,
+ data, size);
+ return 0;
+}
+
+void *
+rte_cryptodev_asym_session_get_user_data(void *session)
+{
+ struct rte_cryptodev_asym_session *sess = session;
+ if (sess == NULL || sess->user_data_sz == 0)
+ return NULL;
+
+ return (void *)(sess->sess_private_data +
+ sess->max_priv_data_sz);
+}
+
static inline void
sym_crypto_fill_status(struct rte_crypto_sym_vec *vec, int32_t errnum)
{