cryptodev: add API to associate session with queue pair

HW based crypto drivers may only support limited number of
sessions per queue pair. This requires support for attaching
sessions to specific queue pair.  New APIs  are introduced to
attach/detach a session with/from a particular queue pair.
These are optional APIs.

Application can call attach API after creating a session
and can call detach API before deleting a session.

Application needs to check if max_nb_sessions_per_qp > 0,
then it should call the attach API.

max_nb_sessions_per_qp = 0 means infinite sessions per qp

Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
This commit is contained in:
Akhil Goyal 2017-03-24 14:59:20 +05:30 committed by Pablo de Lara
parent 59c51be41c
commit d816fdea55
6 changed files with 115 additions and 5 deletions

View File

@ -75,8 +75,3 @@ Deprecation Notices
PMDs that implement the latter.
Target release for removal of the legacy API will be defined once most
PMDs have switched to rte_flow.
* cryptodev: A new parameter ``max_nb_sessions_per_qp`` will be added to
``rte_cryptodev_info.sym``. Some drivers may support limited number of
sessions per queue_pair. With this new parameter application will know
how many sessions can be mapped to each queue_pair of a device.

View File

@ -408,6 +408,9 @@ ABI Changes
The order and size of the fields in the ``mbuf`` structure changed,
as described in the `New Features`_ section.
* The ``rte_cryptodev_info.sym`` structure has new field ``max_nb_sessions_per_qp``
to support drivers which may support limited number of sessions per queue_pair.
Removed Items
-------------

View File

@ -1399,6 +1399,53 @@ rte_cryptodev_sym_session_create(uint8_t dev_id,
return sess;
}
int
rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
struct rte_cryptodev_sym_session *sess)
{
struct rte_cryptodev *dev;
if (!rte_cryptodev_pmd_is_valid_dev(sess->dev_id)) {
CDEV_LOG_ERR("Invalid dev_id=%d", sess->dev_id);
return -EINVAL;
}
dev = &rte_crypto_devices[sess->dev_id];
/* The API is optional, not returning error if driver do not suuport */
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->qp_attach_session, 0);
if (dev->dev_ops->qp_attach_session(dev, qp_id, sess->_private)) {
CDEV_LOG_ERR("dev_id %d failed to attach qp: %d with session",
sess->dev_id, qp_id);
return -EPERM;
}
return 0;
}
int
rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
struct rte_cryptodev_sym_session *sess)
{
struct rte_cryptodev *dev;
if (!rte_cryptodev_pmd_is_valid_dev(sess->dev_id)) {
CDEV_LOG_ERR("Invalid dev_id=%d", sess->dev_id);
return -EINVAL;
}
dev = &rte_crypto_devices[sess->dev_id];
/* The API is optional, not returning error if driver do not suuport */
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->qp_detach_session, 0);
if (dev->dev_ops->qp_detach_session(dev, qp_id, sess->_private)) {
CDEV_LOG_ERR("dev_id %d failed to detach qp: %d from session",
sess->dev_id, qp_id);
return -EPERM;
}
return 0;
}
struct rte_cryptodev_sym_session *
rte_cryptodev_sym_session_free(uint8_t dev_id,
struct rte_cryptodev_sym_session *sess)

View File

@ -332,6 +332,10 @@ struct rte_cryptodev_info {
struct {
unsigned max_nb_sessions;
/**< Maximum number of sessions supported by device. */
unsigned int max_nb_sessions_per_qp;
/**< Maximum number of sessions per queue pair.
* Default 0 for infinite sessions
*/
} sym;
};
@ -915,6 +919,36 @@ extern struct rte_cryptodev_sym_session *
rte_cryptodev_sym_session_free(uint8_t dev_id,
struct rte_cryptodev_sym_session *session);
/**
* Attach queue pair with sym session.
*
* @param qp_id Queue pair to which session will be attached.
* @param session Session pointer previously allocated by
* *rte_cryptodev_sym_session_create*.
*
* @return
* - On success, zero.
* - On failure, a negative value.
*/
int
rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
struct rte_cryptodev_sym_session *session);
/**
* Detach queue pair with sym session.
*
* @param qp_id Queue pair to which session is attached.
* @param session Session pointer previously allocated by
* *rte_cryptodev_sym_session_create*.
*
* @return
* - On success, zero.
* - On failure, a negative value.
*/
int
rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
struct rte_cryptodev_sym_session *session);
#ifdef __cplusplus
}

View File

@ -383,6 +383,31 @@ typedef void * (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
void *session_private);
/**
* Optional API for drivers to attach sessions with queue pair.
* @param dev Crypto device pointer
* @param qp_id queue pair id for attaching session
* @param priv_sess Pointer to cryptodev's private session structure
* @return
* - Return 0 on success
*/
typedef int (*cryptodev_sym_queue_pair_attach_session_t)(
struct rte_cryptodev *dev,
uint16_t qp_id,
void *session_private);
/**
* Optional API for drivers to detach sessions from queue pair.
* @param dev Crypto device pointer
* @param qp_id queue pair id for detaching session
* @param priv_sess Pointer to cryptodev's private session structure
* @return
* - Return 0 on success
*/
typedef int (*cryptodev_sym_queue_pair_detach_session_t)(
struct rte_cryptodev *dev,
uint16_t qp_id,
void *session_private);
/** Crypto device operations function pointer table */
struct rte_cryptodev_ops {
@ -417,6 +442,10 @@ struct rte_cryptodev_ops {
/**< Configure a Crypto session. */
cryptodev_sym_free_session_t session_clear;
/**< Clear a Crypto sessions private data. */
cryptodev_sym_queue_pair_attach_session_t qp_attach_session;
/**< Attach session to queue pair. */
cryptodev_sym_queue_pair_attach_session_t qp_detach_session;
/**< Detach session from queue pair. */
};

View File

@ -70,5 +70,7 @@ DPDK_17.05 {
rte_cryptodev_get_auth_algo_enum;
rte_cryptodev_get_cipher_algo_enum;
rte_cryptodev_queue_pair_attach_sym_session;
rte_cryptodev_queue_pair_detach_sym_session;
} DPDK_17.02;