X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fvhost_crypto%2Fmain.c;h=dea7dcbd0771b8031fc29e828fbb2ce7de6fe71c;hb=d2794d6719db49ede1370d1be2d56bd96d73c418;hp=cbb5e49d292dd680c45d7c5f343eb8e9c96001ee;hpb=709521f4c2cdf9f8c8ca4cb455cdac2e3a539238;p=dpdk.git diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c index cbb5e49d29..dea7dcbd07 100644 --- a/examples/vhost_crypto/main.c +++ b/examples/vhost_crypto/main.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,7 @@ struct vhost_crypto_info { int vids[MAX_NB_SOCKETS]; uint32_t nb_vids; struct rte_mempool *sess_pool; + struct rte_mempool *sess_priv_pool; struct rte_mempool *cop_pool; uint8_t cid; uint32_t qid; @@ -60,10 +62,16 @@ struct vhost_crypto_options { uint32_t guest_polling; } options; -#define CONFIG_KEYWORD "config" -#define SOCKET_FILE_KEYWORD "socket-file" -#define ZERO_COPY_KEYWORD "zero-copy" -#define POLLING_KEYWORD "guest-polling" +enum { +#define OPT_CONFIG "config" + OPT_CONFIG_NUM = 256, +#define OPT_SOCKET_FILE "socket-file" + OPT_SOCKET_FILE_NUM, +#define OPT_ZERO_COPY "zero-copy" + OPT_ZERO_COPY_NUM, +#define OPT_POLLING "guest-polling" + OPT_POLLING_NUM, +}; #define NB_SOCKET_FIELDS (2) @@ -193,11 +201,11 @@ vhost_crypto_usage(const char *prgname) { printf("%s [EAL options] --\n" " --%s ,SOCKET-FILE-PATH\n" - " --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]" + " --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]\n" " --%s: zero copy\n" " --%s: guest polling\n", - prgname, SOCKET_FILE_KEYWORD, CONFIG_KEYWORD, - ZERO_COPY_KEYWORD, POLLING_KEYWORD); + prgname, OPT_SOCKET_FILE, OPT_CONFIG, + OPT_ZERO_COPY, OPT_POLLING); } static int @@ -208,48 +216,56 @@ vhost_crypto_parse_args(int argc, char **argv) char **argvopt; int option_index; struct option lgopts[] = { - {SOCKET_FILE_KEYWORD, required_argument, 0, 0}, - {CONFIG_KEYWORD, required_argument, 0, 0}, - {ZERO_COPY_KEYWORD, no_argument, 0, 0}, - {POLLING_KEYWORD, no_argument, 0, 0}, - {NULL, 0, 0, 0} + {OPT_SOCKET_FILE, required_argument, + NULL, OPT_SOCKET_FILE_NUM}, + {OPT_CONFIG, required_argument, + NULL, OPT_CONFIG_NUM}, + {OPT_ZERO_COPY, no_argument, + NULL, OPT_ZERO_COPY_NUM}, + {OPT_POLLING, no_argument, + NULL, OPT_POLLING_NUM}, + {NULL, 0, 0, 0} }; argvopt = argv; - while ((opt = getopt_long(argc, argvopt, "s:", + while ((opt = getopt_long(argc, argvopt, "", lgopts, &option_index)) != EOF) { + if (opt == '?') { + vhost_crypto_usage(prgname); + return -1; + } + switch (opt) { - case 0: - if (strcmp(lgopts[option_index].name, - SOCKET_FILE_KEYWORD) == 0) { - ret = parse_socket_arg(optarg); - if (ret < 0) { - vhost_crypto_usage(prgname); - return ret; - } - } else if (strcmp(lgopts[option_index].name, - CONFIG_KEYWORD) == 0) { - ret = parse_config(optarg); - if (ret < 0) { - vhost_crypto_usage(prgname); - return ret; - } - } else if (strcmp(lgopts[option_index].name, - ZERO_COPY_KEYWORD) == 0) { - options.zero_copy = - RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE; - } else if (strcmp(lgopts[option_index].name, - POLLING_KEYWORD) == 0) { - options.guest_polling = 1; - } else { + case OPT_SOCKET_FILE_NUM: + ret = parse_socket_arg(optarg); + if (ret < 0) { vhost_crypto_usage(prgname); - return -EINVAL; + return ret; } break; + + case OPT_CONFIG_NUM: + ret = parse_config(optarg); + if (ret < 0) { + vhost_crypto_usage(prgname); + return ret; + } + break; + + case OPT_ZERO_COPY_NUM: + options.zero_copy = + RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE; + break; + + case OPT_POLLING_NUM: + options.guest_polling = 1; + break; + default: - return -1; + vhost_crypto_usage(prgname); + return -EINVAL; } } @@ -288,6 +304,7 @@ new_device(int vid) } ret = rte_vhost_crypto_create(vid, info->cid, info->sess_pool, + info->sess_priv_pool, rte_lcore_to_socket_id(options.los[i].lcore_id)); if (ret) { RTE_LOG(ERR, USER1, "Cannot create vhost crypto\n"); @@ -351,12 +368,6 @@ static const struct vhost_device_ops virtio_crypto_device_ops = { .destroy_device = destroy_device, }; -__attribute__((unused)) -static void clrscr(void) -{ - system("@cls||clear"); -} - static int vhost_crypto_worker(void *arg) { @@ -442,8 +453,12 @@ free_resource(void) struct lcore_option *lo = &options.los[i]; struct vhost_crypto_info *info = options.infos[i]; + if (!info) + continue; + rte_mempool_free(info->cop_pool); rte_mempool_free(info->sess_pool); + rte_mempool_free(info->sess_priv_pool); for (j = 0; j < lo->nb_sockets; j++) { rte_vhost_driver_unregister(lo->socket_files[i]); @@ -454,12 +469,15 @@ free_resource(void) } memset(&options, 0, sizeof(options)); + + /* clean up the EAL */ + rte_eal_cleanup(); } int main(int argc, char *argv[]) { - struct rte_cryptodev_qp_conf qp_conf = {NB_CRYPTO_DESCRIPTORS}; + struct rte_cryptodev_qp_conf qp_conf; struct rte_cryptodev_config config; struct rte_cryptodev_info dev_info; char name[128]; @@ -493,6 +511,20 @@ main(int argc, char *argv[]) info->nb_vids = lo->nb_sockets; rte_cryptodev_info_get(info->cid, &dev_info); + if (options.zero_copy == RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE) { +#define VHOST_CRYPTO_CDEV_NAME_AESNI_MB_PMD crypto_aesni_mb +#define VHOST_CRYPTO_CDEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm + if (strstr(dev_info.driver_name, + RTE_STR(VHOST_CRYPTO_CDEV_NAME_AESNI_MB_PMD)) || + strstr(dev_info.driver_name, + RTE_STR(VHOST_CRYPTO_CDEV_NAME_AESNI_GCM_PMD))) { + RTE_LOG(ERR, USER1, "Cannot enable zero-copy in %s\n", + dev_info.driver_name); + ret = -EPERM; + goto error_exit; + } + } + if (dev_info.max_nb_queue_pairs < info->qid + 1) { RTE_LOG(ERR, USER1, "Number of queues cannot over %u", dev_info.max_nb_queue_pairs); @@ -501,6 +533,7 @@ main(int argc, char *argv[]) config.nb_queue_pairs = dev_info.max_nb_queue_pairs; config.socket_id = rte_lcore_to_socket_id(lo->lcore_id); + config.ff_disable = RTE_CRYPTODEV_FF_SECURITY; ret = rte_cryptodev_configure(info->cid, &config); if (ret < 0) { @@ -510,11 +543,17 @@ main(int argc, char *argv[]) } snprintf(name, 127, "SESS_POOL_%u", lo->lcore_id); - info->sess_pool = rte_mempool_create(name, SESSION_MAP_ENTRIES, + info->sess_pool = rte_cryptodev_sym_session_pool_create(name, + SESSION_MAP_ENTRIES, 0, 0, 0, + rte_lcore_to_socket_id(lo->lcore_id)); + + snprintf(name, 127, "SESS_POOL_PRIV_%u", lo->lcore_id); + info->sess_priv_pool = rte_mempool_create(name, + SESSION_MAP_ENTRIES, rte_cryptodev_sym_get_private_session_size( info->cid), 64, 0, NULL, NULL, NULL, NULL, rte_lcore_to_socket_id(lo->lcore_id), 0); - if (!info->sess_pool) { + if (!info->sess_priv_pool || !info->sess_pool) { RTE_LOG(ERR, USER1, "Failed to create mempool"); goto error_exit; } @@ -522,7 +561,7 @@ main(int argc, char *argv[]) snprintf(name, 127, "COPPOOL_%u", lo->lcore_id); info->cop_pool = rte_crypto_op_pool_create(name, RTE_CRYPTO_OP_TYPE_SYMMETRIC, NB_MEMPOOL_OBJS, - NB_CACHE_OBJS, 0, + NB_CACHE_OBJS, VHOST_CRYPTO_MAX_IV_LEN, rte_lcore_to_socket_id(lo->lcore_id)); if (!info->cop_pool) { @@ -533,11 +572,14 @@ main(int argc, char *argv[]) options.infos[i] = info; + qp_conf.nb_descriptors = NB_CRYPTO_DESCRIPTORS; + qp_conf.mp_session = info->sess_pool; + qp_conf.mp_session_private = info->sess_priv_pool; + for (j = 0; j < dev_info.max_nb_queue_pairs; j++) { ret = rte_cryptodev_queue_pair_setup(info->cid, j, &qp_conf, rte_lcore_to_socket_id( - lo->lcore_id), - info->sess_pool); + lo->lcore_id)); if (ret < 0) { RTE_LOG(ERR, USER1, "Failed to configure qp\n"); goto error_exit; @@ -563,7 +605,7 @@ main(int argc, char *argv[]) for (j = 0; j < lo->nb_sockets; j++) { ret = rte_vhost_driver_register(lo->socket_files[j], - RTE_VHOST_USER_DEQUEUE_ZERO_COPY); + RTE_VHOST_USER_ASYNC_COPY); if (ret < 0) { RTE_LOG(ERR, USER1, "socket %s already exists\n", lo->socket_files[j]); @@ -573,7 +615,8 @@ main(int argc, char *argv[]) rte_vhost_driver_callback_register(lo->socket_files[j], &virtio_crypto_device_ops); - ret = rte_vhost_driver_start(lo->socket_files[j]); + ret = rte_vhost_crypto_driver_start( + lo->socket_files[j]); if (ret < 0) { RTE_LOG(ERR, USER1, "failed to start vhost.\n"); goto error_exit;