uint32_t is_path_folder;
uint32_t dev_id;
struct rte_mempool *mpool;
+ struct rte_mempool *sess_mpool;
+ struct rte_mempool *sess_priv_mpool;
struct rte_mempool *op_pool;
struct rte_mbuf *mbuf;
struct rte_crypto_op *op;
{
struct rte_cryptodev_config conf = {rte_socket_id(), 1};
struct rte_cryptodev_qp_conf qp_conf = {128, NULL, NULL};
+ uint32_t sess_sz = rte_cryptodev_sym_get_private_session_size(
+ env.dev_id);
int ret;
ret = rte_cryptodev_configure(env.dev_id, &conf);
ret = -ENOMEM;
+ env.sess_mpool = rte_cryptodev_sym_session_pool_create(
+ "FIPS_SESS_MEMPOOL", 16, 0, 0, 0, rte_socket_id());
+ if (!env.sess_mpool)
+ goto error_exit;
+
+ env.sess_priv_mpool = rte_mempool_create("FIPS_SESS_PRIV_MEMPOOL",
+ 16, sess_sz, 0, 0, NULL, NULL, NULL,
+ NULL, rte_socket_id(), 0);
+ if (!env.sess_priv_mpool)
+ goto error_exit;
+
env.op_pool = rte_crypto_op_pool_create(
"FIPS_OP_POOL",
RTE_CRYPTO_OP_TYPE_SYMMETRIC,
if (!env.op)
goto error_exit;
+ qp_conf.mp_session = env.sess_mpool;
+ qp_conf.mp_session_private = env.sess_priv_mpool;
+
+ ret = rte_cryptodev_queue_pair_setup(env.dev_id, 0, &qp_conf,
+ rte_socket_id());
+ if (ret < 0)
+ goto error_exit;
+
return 0;
error_exit:
+
rte_mempool_free(env.mpool);
+ if (env.sess_mpool)
+ rte_mempool_free(env.sess_mpool);
+ if (env.sess_priv_mpool)
+ rte_mempool_free(env.sess_priv_mpool);
if (env.op_pool)
rte_mempool_free(env.op_pool);
rte_cryptodev_sym_session_clear(env.dev_id, env.sess);
rte_cryptodev_sym_session_free(env.sess);
rte_mempool_free(env.mpool);
+ rte_mempool_free(env.sess_mpool);
+ rte_mempool_free(env.sess_priv_mpool);
rte_mempool_free(env.op_pool);
}
if (ret < 0)
return ret;
- env.sess = rte_cryptodev_sym_session_create(env.mpool);
+ env.sess = rte_cryptodev_sym_session_create(env.sess_mpool);
if (!env.sess)
return -ENOMEM;
ret = rte_cryptodev_sym_session_init(env.dev_id,
- env.sess, &xform, env.mpool);
+ env.sess, &xform, env.sess_priv_mpool);
if (ret < 0) {
RTE_LOG(ERR, USER1, "Error %i: Init session\n",
ret);
static const char cmd_cryptodev_help[] =
"cryptodev <cryptodev_name>\n"
" dev <device_name> | dev_id <device_id>\n"
-" queue <n_queues> <queue_size>\n";
+" queue <n_queues> <queue_size>\n"
+" max_sessions <n_sessions>";
static void
cmd_cryptodev(char **tokens,
char *name;
memset(¶ms, 0, sizeof(params));
- if (n_tokens != 7) {
+ if (n_tokens != 9) {
snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
return;
}
if (strcmp(tokens[4], "queue")) {
snprintf(out, out_size, MSG_ARG_NOT_FOUND,
- "4");
+ "queue");
return;
}
return;
}
+ if (strcmp(tokens[7], "max_sessions")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND,
+ "max_sessions");
+ return;
+ }
+
+ if (parser_read_uint32(¶ms.session_pool_size, tokens[8]) < 0) {
+ snprintf(out, out_size, MSG_ARG_INVALID,
+ "queue_size");
+ return;
+ }
+
if (cryptodev_create(name, ¶ms) == NULL) {
snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
return;
" stats none | pkts]\n"
" [stats pkts | bytes | both]\n"
" [time]\n"
-" [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset> "
-" mempool_create <mempool_name>\n"
-" mempool_init <mempool_name>]\n"
+" [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
" [tag]\n"
" [decap]\n";
if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
struct cryptodev *cryptodev;
- struct mempool *mempool;
- if (n_tokens < t0 + 9 ||
+ if (n_tokens < t0 + 5 ||
strcmp(tokens[t0 + 1], "dev") ||
- strcmp(tokens[t0 + 3], "offset") ||
- strcmp(tokens[t0 + 5], "mempool_create") ||
- strcmp(tokens[t0 + 7], "mempool_init")) {
+ strcmp(tokens[t0 + 3], "offset")) {
snprintf(out, out_size, MSG_ARG_MISMATCH,
"table action profile sym_crypto");
return;
return;
}
- mempool = mempool_find(tokens[t0 + 6]);
- if (mempool == NULL) {
- snprintf(out, out_size, MSG_ARG_INVALID,
- "table action profile sym_crypto");
- return;
- }
- p.sym_crypto.mp_create = mempool->m;
-
- mempool = mempool_find(tokens[t0 + 8]);
- if (mempool == NULL) {
- snprintf(out, out_size, MSG_ARG_INVALID,
- "table action profile sym_crypto");
- return;
- }
- p.sym_crypto.mp_init = mempool->m;
+ p.sym_crypto.mp_create = cryptodev->mp_create;
+ p.sym_crypto.mp_init = cryptodev->mp_init;
p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
- t0 += 9;
+ t0 += 5;
} /* sym_crypto */
if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
#include "cryptodev.h"
+#define PIPELINE_CRYPTO_SESSION_CACHE_SIZE 128
+
static struct cryptodev_list cryptodev_list;
int
struct cryptodev *cryptodev;
uint32_t dev_id, i;
uint32_t socket_id;
+ uint32_t cache_size;
+ char mp_name[NAME_SIZE];
int status;
/* Check input params */
if ((name == NULL) ||
cryptodev_find(name) ||
(params->n_queues == 0) ||
- (params->queue_size == 0))
+ (params->queue_size == 0) ||
+ (params->session_pool_size == 0))
return NULL;
if (params->dev_name) {
dev_id = params->dev_id;
}
+ cache_size = (params->session_pool_size / 2 <
+ PIPELINE_CRYPTO_SESSION_CACHE_SIZE) ?
+ (params->session_pool_size / 2) :
+ PIPELINE_CRYPTO_SESSION_CACHE_SIZE;
+
socket_id = rte_cryptodev_socket_id(dev_id);
rte_cryptodev_info_get(dev_id, &dev_info);
cryptodev->dev_id = dev_id;
cryptodev->n_queues = params->n_queues;
+ snprintf(mp_name, NAME_SIZE, "%s_mp%u", name, dev_id);
+ cryptodev->mp_create = rte_cryptodev_sym_session_pool_create(
+ mp_name,
+ params->session_pool_size,
+ 0,
+ cache_size,
+ 0,
+ socket_id);
+ if (!cryptodev->mp_create)
+ goto error_exit;
+
+ snprintf(mp_name, NAME_SIZE, "%s_mp_priv%u", name, dev_id);
+ cryptodev->mp_init = rte_mempool_create(
+ NULL,
+ params->session_pool_size,
+ rte_cryptodev_sym_get_private_session_size(dev_id),
+ cache_size,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ socket_id,
+ 0);
+ if (!cryptodev->mp_init)
+ goto error_exit;
+
TAILQ_INSERT_TAIL(&cryptodev_list, cryptodev, node);
return cryptodev;
+
+error_exit:
+ if (cryptodev->mp_create)
+ rte_mempool_free(cryptodev->mp_create);
+ if (cryptodev->mp_init)
+ rte_mempool_free(cryptodev->mp_init);
+
+ free(cryptodev);
+
+ return NULL;
}
char name[NAME_SIZE];
uint16_t dev_id;
uint32_t n_queues;
+ struct rte_mempool *mp_create;
+ struct rte_mempool *mp_init;
};
TAILQ_HEAD(cryptodev_list, cryptodev);
uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
uint32_t n_queues;
uint32_t queue_size;
+ uint32_t session_pool_size;
};
struct cryptodev *
; 5 Crypto Operation 1792 160
mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 1
-mempool MEMPOOL_SESSION0 buffer 1024 pool 1024 cache 128 cpu 1
-link LINK0 dev 0000:81:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK0 dev 81:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
#Cryptodev
-cryptodev CRYPTO0 dev crypto_aesni_gcm0 queue 1 1024
+cryptodev CRYPTO0 dev crypto_aesni_gcm0 queue 1 1024 max_sessions 512
-table action profile AP0 ipv4 offset 270 fwd sym_crypto dev CRYPTO0 offset 1792 mempool_create MEMPOOL_SESSION0 mempool_init MEMPOOL_SESSION0
+table action profile AP0 ipv4 offset 270 fwd sym_crypto dev CRYPTO0 offset 1792
table action profile AP1 ipv4 offset 270 fwd
pipeline PIPELINE0 period 10 offset_port_id 0 cpu 1
pipeline PIPELINE0 port in 0 table 0
pipeline PIPELINE0 port in 1 table 1
-thread 24 pipeline PIPELINE0 enable
+thread 2 pipeline PIPELINE0 enable
pipeline PIPELINE0 table 0 rule add match default action fwd port 2
#define CDEV_QUEUE_DESC 2048
#define CDEV_MAP_ENTRIES 16384
-#define CDEV_MP_NB_OBJS 2048
+#define CDEV_MP_NB_OBJS 1024
#define CDEV_MP_CACHE_SZ 64
#define MAX_QUEUE_PAIRS 1
qconf->inbound.sa_ctx = socket_ctx[socket_id].sa_in;
qconf->inbound.cdev_map = cdev_map_in;
qconf->inbound.session_pool = socket_ctx[socket_id].session_pool;
+ qconf->inbound.session_priv_pool =
+ socket_ctx[socket_id].session_priv_pool;
qconf->outbound.sp4_ctx = socket_ctx[socket_id].sp_ip4_out;
qconf->outbound.sp6_ctx = socket_ctx[socket_id].sp_ip6_out;
qconf->outbound.sa_ctx = socket_ctx[socket_id].sa_out;
qconf->outbound.cdev_map = cdev_map_out;
qconf->outbound.session_pool = socket_ctx[socket_id].session_pool;
+ qconf->outbound.session_priv_pool =
+ socket_ctx[socket_id].session_priv_pool;
if (qconf->nb_rx_queue == 0) {
RTE_LOG(INFO, IPSEC, "lcore %u has nothing to do\n", lcore_id);
dev_conf.nb_queue_pairs = qp;
uint32_t dev_max_sess = cdev_info.sym.max_nb_sessions;
- if (dev_max_sess != 0 && dev_max_sess < (CDEV_MP_NB_OBJS / 2))
+ if (dev_max_sess != 0 && dev_max_sess < CDEV_MP_NB_OBJS)
rte_exit(EXIT_FAILURE,
"Device does not support at least %u "
- "sessions", CDEV_MP_NB_OBJS / 2);
+ "sessions", CDEV_MP_NB_OBJS);
if (!socket_ctx[dev_conf.socket_id].session_pool) {
char mp_name[RTE_MEMPOOL_NAMESIZE];
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
"sess_mp_%u", dev_conf.socket_id);
+ sess_mp = rte_cryptodev_sym_session_pool_create(
+ mp_name, CDEV_MP_NB_OBJS,
+ 0, CDEV_MP_CACHE_SZ, 0,
+ dev_conf.socket_id);
+ socket_ctx[dev_conf.socket_id].session_pool = sess_mp;
+ }
+
+ if (!socket_ctx[dev_conf.socket_id].session_priv_pool) {
+ char mp_name[RTE_MEMPOOL_NAMESIZE];
+ struct rte_mempool *sess_mp;
+
+ snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
+ "sess_mp_priv_%u", dev_conf.socket_id);
sess_mp = rte_mempool_create(mp_name,
CDEV_MP_NB_OBJS,
max_sess_sz,
0, NULL, NULL, NULL,
NULL, dev_conf.socket_id,
0);
- if (sess_mp == NULL)
- rte_exit(EXIT_FAILURE,
- "Cannot create session pool on socket %d\n",
- dev_conf.socket_id);
- else
- printf("Allocated session pool on socket %d\n",
- dev_conf.socket_id);
- socket_ctx[dev_conf.socket_id].session_pool = sess_mp;
+ socket_ctx[dev_conf.socket_id].session_priv_pool =
+ sess_mp;
}
+ if (!socket_ctx[dev_conf.socket_id].session_priv_pool ||
+ !socket_ctx[dev_conf.socket_id].session_pool)
+ rte_exit(EXIT_FAILURE,
+ "Cannot create session pool on socket %d\n",
+ dev_conf.socket_id);
+ else
+ printf("Allocated session pool on socket %d\n",
+ dev_conf.socket_id);
+
if (rte_cryptodev_configure(cdev_id, &dev_conf))
rte_panic("Failed to initialize cryptodev %u\n",
cdev_id);
qp_conf.nb_descriptors = CDEV_QUEUE_DESC;
qp_conf.mp_session =
- socket_ctx[dev_conf.socket_id].session_pool;
+ socket_ctx[dev_conf.socket_id].session_pool;
qp_conf.mp_session_private =
- socket_ctx[dev_conf.socket_id].session_pool;
+ socket_ctx[dev_conf.socket_id].session_priv_pool;
for (qp = 0; qp < dev_conf.nb_queue_pairs; qp++)
if (rte_cryptodev_queue_pair_setup(cdev_id, qp,
&qp_conf, dev_conf.socket_id))
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
"sess_mp_%u", socket_id);
sess_mp = rte_mempool_create(mp_name,
- CDEV_MP_NB_OBJS,
+ (CDEV_MP_NB_OBJS * 2),
max_sess_sz,
CDEV_MP_CACHE_SZ,
0, NULL, NULL, NULL,
ipsec_ctx->session_pool);
rte_cryptodev_sym_session_init(ipsec_ctx->tbl[cdev_id_qp].id,
sa->crypto_session, sa->xforms,
- ipsec_ctx->session_pool);
+ ipsec_ctx->session_priv_pool);
rte_cryptodev_info_get(ipsec_ctx->tbl[cdev_id_qp].id,
&cdev_info);
uint16_t last_qp;
struct cdev_qp tbl[MAX_QP_PER_LCORE];
struct rte_mempool *session_pool;
+ struct rte_mempool *session_priv_pool;
struct rte_mbuf *ol_pkts[MAX_PKT_BURST] __rte_aligned(sizeof(void *));
uint16_t ol_pkts_cnt;
};
struct rt_ctx *rt_ip6;
struct rte_mempool *mbuf_pool;
struct rte_mempool *session_pool;
+ struct rte_mempool *session_priv_pool;
};
struct cnt_blk {
include $(RTE_SDK)/mk/rte.vars.mk
+CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
struct rte_mempool *l2fwd_pktmbuf_pool;
struct rte_mempool *l2fwd_crypto_op_pool;
-struct rte_mempool *session_pool_socket[RTE_MAX_NUMA_NODES] = { 0 };
+static struct {
+ struct rte_mempool *sess_mp;
+ struct rte_mempool *priv_mp;
+} session_pool_socket[RTE_MAX_NUMA_NODES];
/* Per-port statistics struct */
struct l2fwd_port_statistics {
return NULL;
uint8_t socket_id = (uint8_t) retval;
- struct rte_mempool *sess_mp = session_pool_socket[socket_id];
if (options->xform_chain == L2FWD_CRYPTO_AEAD) {
first_xform = &options->aead_xform;
first_xform = &options->auth_xform;
}
- session = rte_cryptodev_sym_session_create(sess_mp);
-
+ session = rte_cryptodev_sym_session_create(
+ session_pool_socket[socket_id].sess_mp);
if (session == NULL)
return NULL;
if (rte_cryptodev_sym_session_init(cdev_id, session,
- first_xform, sess_mp) < 0)
+ first_xform,
+ session_pool_socket[socket_id].priv_mp) < 0)
return NULL;
return session;
rte_cryptodev_scheduler_slaves_get(cdev_id,
NULL);
- sessions_needed = 2 * enabled_cdev_count * nb_slaves;
+ sessions_needed = enabled_cdev_count * nb_slaves;
#endif
} else
- sessions_needed = 2 * enabled_cdev_count;
+ sessions_needed = enabled_cdev_count;
- if (session_pool_socket[socket_id] == NULL) {
+ if (session_pool_socket[socket_id].priv_mp == NULL) {
char mp_name[RTE_MEMPOOL_NAMESIZE];
- struct rte_mempool *sess_mp;
snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
- "sess_mp_%u", socket_id);
+ "priv_sess_mp_%u", socket_id);
- /*
- * Create enough objects for session headers and
- * device private data
- */
- sess_mp = rte_mempool_create(mp_name,
+ session_pool_socket[socket_id].priv_mp =
+ rte_mempool_create(mp_name,
sessions_needed,
max_sess_sz,
- SESSION_POOL_CACHE_SIZE,
- 0, NULL, NULL, NULL,
+ 0, 0, NULL, NULL, NULL,
NULL, socket_id,
0);
- if (sess_mp == NULL) {
- printf("Cannot create session pool on socket %d\n",
+ if (session_pool_socket[socket_id].priv_mp == NULL) {
+ printf("Cannot create pool on socket %d\n",
+ socket_id);
+ return -ENOMEM;
+ }
+
+ printf("Allocated pool \"%s\" on socket %d\n",
+ mp_name, socket_id);
+ }
+
+ if (session_pool_socket[socket_id].sess_mp == NULL) {
+ char mp_name[RTE_MEMPOOL_NAMESIZE];
+ snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
+ "sess_mp_%u", socket_id);
+
+ session_pool_socket[socket_id].sess_mp =
+ rte_cryptodev_sym_session_pool_create(
+ mp_name,
+ sessions_needed,
+ 0, 0, 0, socket_id);
+
+ if (session_pool_socket[socket_id].sess_mp == NULL) {
+ printf("Cannot create pool on socket %d\n",
socket_id);
return -ENOMEM;
}
- printf("Allocated session pool on socket %d\n", socket_id);
- session_pool_socket[socket_id] = sess_mp;
+ printf("Allocated pool \"%s\" on socket %d\n",
+ mp_name, socket_id);
}
/* Set AEAD parameters */
}
qp_conf.nb_descriptors = 2048;
- qp_conf.mp_session = session_pool_socket[socket_id];
- qp_conf.mp_session_private = session_pool_socket[socket_id];
+ qp_conf.mp_session = session_pool_socket[socket_id].sess_mp;
+ qp_conf.mp_session_private =
+ session_pool_socket[socket_id].priv_mp;
retval = rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf,
socket_id);
# DPDK instance, use 'make'
deps += 'cryptodev'
+allow_experimental_apis = true
sources = files(
'main.c'
)