From 029bb90781fbbde04b587994693167f0584c2598 Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Thu, 30 Mar 2017 14:39:18 +0100 Subject: [PATCH] crypto/scheduler: add API to get attached slaves This patch adds an API to get the run-time slaves number and list of a cryptodev scheduler PMD. Signed-off-by: Fan Zhang Acked-by: Pablo de Lara --- .../scheduler/rte_cryptodev_scheduler.c | 34 ++++++++++++++++++- .../scheduler/rte_cryptodev_scheduler.h | 24 +++++++++++++ .../rte_pmd_crypto_scheduler_version.map | 7 ++++ drivers/crypto/scheduler/scheduler_pmd.c | 4 +-- .../crypto/scheduler/scheduler_pmd_private.h | 10 ++---- .../crypto/scheduler/scheduler_roundrobin.c | 5 +-- 6 files changed, 72 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/scheduler/rte_cryptodev_scheduler.c b/drivers/crypto/scheduler/rte_cryptodev_scheduler.c index 9c33be822e..6018857bfb 100644 --- a/drivers/crypto/scheduler/rte_cryptodev_scheduler.c +++ b/drivers/crypto/scheduler/rte_cryptodev_scheduler.c @@ -209,7 +209,8 @@ rte_cryptodev_scheduler_slave_attach(uint8_t scheduler_id, uint8_t slave_id) } sched_ctx = dev->data->dev_private; - if (sched_ctx->nb_slaves >= MAX_SLAVES_NUM) { + if (sched_ctx->nb_slaves >= + RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES) { CS_LOG_ERR("Too many slaves attached"); return -ENOMEM; } @@ -483,3 +484,34 @@ rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id, return 0; } + +int +rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves) +{ + struct rte_cryptodev *dev = rte_cryptodev_pmd_get_dev(scheduler_id); + struct scheduler_ctx *sched_ctx; + uint32_t nb_slaves = 0; + + if (!dev) { + CS_LOG_ERR("Operation not supported"); + return -ENOTSUP; + } + + if (dev->dev_type != RTE_CRYPTODEV_SCHEDULER_PMD) { + CS_LOG_ERR("Operation not supported"); + return -ENOTSUP; + } + + sched_ctx = dev->data->dev_private; + + nb_slaves = sched_ctx->nb_slaves; + + if (slaves && nb_slaves) { + uint32_t i; + + for (i = 0; i < nb_slaves; i++) + slaves[i] = sched_ctx->slaves[i].dev_id; + } + + return (int)nb_slaves; +} diff --git a/drivers/crypto/scheduler/rte_cryptodev_scheduler.h b/drivers/crypto/scheduler/rte_cryptodev_scheduler.h index 306dfea5c6..1b522613d0 100644 --- a/drivers/crypto/scheduler/rte_cryptodev_scheduler.h +++ b/drivers/crypto/scheduler/rte_cryptodev_scheduler.h @@ -40,6 +40,11 @@ extern "C" { #endif +/**< Maximum number of bonded devices per device */ +#ifndef RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES +#define RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES (8) +#endif + /** * Crypto scheduler PMD operation modes */ @@ -147,6 +152,25 @@ rte_cryptodev_scheduler_ordering_set(uint8_t scheduler_id, int rte_cryptodev_scheduler_ordering_get(uint8_t scheduler_id); +/** + * Get the the attached slaves' count and/or ID + * + * @param scheduler_id + * The target scheduler device ID + * @param slaves + * If successful, the function will write back + * all slaves' device IDs to it. This + * parameter SHALL either be an uint8_t array + * of RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES + * elements or NULL. + * + * @return + * - non-negative number: the number of slaves attached + * - negative integer if error occurs. + */ +int +rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves); + typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx, struct rte_crypto_op **ops, uint16_t nb_ops); diff --git a/drivers/crypto/scheduler/rte_pmd_crypto_scheduler_version.map b/drivers/crypto/scheduler/rte_pmd_crypto_scheduler_version.map index a485b435a8..69cf0c61d1 100644 --- a/drivers/crypto/scheduler/rte_pmd_crypto_scheduler_version.map +++ b/drivers/crypto/scheduler/rte_pmd_crypto_scheduler_version.map @@ -10,3 +10,10 @@ DPDK_17.02 { rte_cryptodev_scheduler_ordering_get; }; + +DPDK_17.05 { + global: + + rte_cryptodev_scheduler_slaves_get; + +} DPDK_17.02; diff --git a/drivers/crypto/scheduler/scheduler_pmd.c b/drivers/crypto/scheduler/scheduler_pmd.c index c1679ecf41..dc7192f546 100644 --- a/drivers/crypto/scheduler/scheduler_pmd.c +++ b/drivers/crypto/scheduler/scheduler_pmd.c @@ -44,7 +44,7 @@ struct scheduler_init_params { struct rte_crypto_vdev_init_params def_p; uint32_t nb_slaves; - uint8_t slaves[MAX_SLAVES_NUM]; + uint8_t slaves[RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES]; }; #define RTE_CRYPTODEV_VDEV_NAME ("name") @@ -222,7 +222,7 @@ parse_slave_arg(const char *key __rte_unused, return -1; } - if (param->nb_slaves >= MAX_SLAVES_NUM - 1) { + if (param->nb_slaves >= RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES - 1) { CS_LOG_ERR("Too many slaves.\n"); return -1; } diff --git a/drivers/crypto/scheduler/scheduler_pmd_private.h b/drivers/crypto/scheduler/scheduler_pmd_private.h index f0861cd799..2f4feeaee0 100644 --- a/drivers/crypto/scheduler/scheduler_pmd_private.h +++ b/drivers/crypto/scheduler/scheduler_pmd_private.h @@ -36,11 +36,6 @@ #include "rte_cryptodev_scheduler.h" -/**< Maximum number of bonded devices per devices */ -#ifndef MAX_SLAVES_NUM -#define MAX_SLAVES_NUM (8) -#endif - #define PER_SLAVE_BUFF_SIZE (256) #define CS_LOG_ERR(fmt, args...) \ @@ -80,7 +75,7 @@ struct scheduler_ctx { uint32_t max_nb_queue_pairs; - struct scheduler_slave slaves[MAX_SLAVES_NUM]; + struct scheduler_slave slaves[RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES]; uint32_t nb_slaves; enum rte_cryptodev_scheduler_mode mode; @@ -103,7 +98,8 @@ struct scheduler_qp_ctx { } __rte_cache_aligned; struct scheduler_session { - struct rte_cryptodev_sym_session *sessions[MAX_SLAVES_NUM]; + struct rte_cryptodev_sym_session *sessions[ + RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES]; }; static inline uint16_t __attribute__((always_inline)) diff --git a/drivers/crypto/scheduler/scheduler_roundrobin.c b/drivers/crypto/scheduler/scheduler_roundrobin.c index f276132731..1fb6ce7ac1 100644 --- a/drivers/crypto/scheduler/scheduler_roundrobin.c +++ b/drivers/crypto/scheduler/scheduler_roundrobin.c @@ -37,7 +37,7 @@ #include "scheduler_pmd_private.h" struct rr_scheduler_qp_ctx { - struct scheduler_slave slaves[MAX_SLAVES_NUM]; + struct scheduler_slave slaves[RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES]; uint32_t nb_slaves; uint32_t last_enq_slave_idx; @@ -211,7 +211,8 @@ scheduler_start(struct rte_cryptodev *dev) qp_ctx->private_qp_ctx; uint32_t j; - memset(rr_qp_ctx->slaves, 0, MAX_SLAVES_NUM * + memset(rr_qp_ctx->slaves, 0, + RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES * sizeof(struct scheduler_slave)); for (j = 0; j < sched_ctx->nb_slaves; j++) { rr_qp_ctx->slaves[j].dev_id = -- 2.20.1