From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 626245934 for ; Fri, 2 Dec 2016 16:16:38 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 02 Dec 2016 07:16:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,287,1477983600"; d="scan'208";a="12695656" Received: from unknown (HELO Sent) ([10.103.102.73]) by orsmga002.jf.intel.com with SMTP; 02 Dec 2016 07:16:26 -0800 Received: by Sent (sSMTP sendmail emulation); Fri, 02 Dec 2016 16:16:04 +0100 From: Michal Jastrzebski To: dev@dpdk.org Cc: pablo.de.lara.guarch@intel.com, Declan Doherty , Slawomir Mrozowicz , Marcin Kerlin Date: Fri, 2 Dec 2016 16:15:01 +0100 Message-Id: <1480691702-4600-2-git-send-email-michalx.k.jastrzebski@intel.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1480691702-4600-1-git-send-email-michalx.k.jastrzebski@intel.com> References: <1480691702-4600-1-git-send-email-michalx.k.jastrzebski@intel.com> Subject: [dpdk-dev] [PATCH 1/2] lib/librte_cryptodev: functions for new performance test application X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Dec 2016 15:16:39 -0000 This patch adds helper functions for new performance application. Application can be used to measute throughput and latency of cryptography operation performed by crypto device. Signed-off-by: Declan Doherty Signed-off-by: Slawomir Mrozowicz Signed-off-by: Marcin Kerlin --- lib/librte_cryptodev/rte_crypto_sym.h | 16 +++ lib/librte_cryptodev/rte_cryptodev.c | 177 +++++++++++++++++++++++++++++++++ lib/librte_cryptodev/rte_cryptodev.h | 120 +++++++++++++--------- 3 files changed, 267 insertions(+), 46 deletions(-) diff --git a/lib/librte_cryptodev/rte_crypto_sym.h b/lib/librte_cryptodev/rte_crypto_sym.h index d3d38e4..e905ad6 100644 --- a/lib/librte_cryptodev/rte_crypto_sym.h +++ b/lib/librte_cryptodev/rte_crypto_sym.h @@ -108,6 +108,10 @@ enum rte_crypto_cipher_algorithm { RTE_CRYPTO_CIPHER_LIST_END }; +/** Cipher algorithm name strings */ +extern const char * +rte_crypto_cipher_algorithm_strings[]; + /** Symmetric Cipher Direction */ enum rte_crypto_cipher_operation { RTE_CRYPTO_CIPHER_OP_ENCRYPT, @@ -116,6 +120,10 @@ enum rte_crypto_cipher_operation { /**< Decrypt cipher operation */ }; +/** Cipher operation name strings */ +extern const char * +rte_crypto_cipher_operation_strings[]; + /** * Symmetric Cipher Setup Data. * @@ -241,12 +249,20 @@ enum rte_crypto_auth_algorithm { RTE_CRYPTO_AUTH_LIST_END }; +/** Authentication algorithm name strings */ +extern const char * +rte_crypto_auth_algorithm_strings[]; + /** Symmetric Authentication / Hash Operations */ enum rte_crypto_auth_operation { RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */ RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */ }; +/** Authentication operation name strings */ +extern const char * +rte_crypto_auth_operation_strings[]; + /** * Authentication / Hash transform data. * diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 127e8d0..af0e554 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -111,6 +111,86 @@ struct rte_cryptodev_callback { RTE_CRYPTODEV_VDEV_SOCKET_ID }; +/** + * The crypto cipher algorithm strings identifiers. + * It could be used in application command line. + */ +const char * +rte_crypto_cipher_algorithm_strings[] = { + [RTE_CRYPTO_CIPHER_3DES_CBC] = "3des-cbc", + [RTE_CRYPTO_CIPHER_3DES_ECB] = "3des-ecb", + [RTE_CRYPTO_CIPHER_3DES_CTR] = "3des-ctr", + + [RTE_CRYPTO_CIPHER_AES_CBC] = "aes-cbc", + [RTE_CRYPTO_CIPHER_AES_CCM] = "aes-ccm", + [RTE_CRYPTO_CIPHER_AES_CTR] = "aes-ctr", + [RTE_CRYPTO_CIPHER_AES_ECB] = "aes-ecb", + [RTE_CRYPTO_CIPHER_AES_GCM] = "aes-gcm", + [RTE_CRYPTO_CIPHER_AES_F8] = "aes-f8", + [RTE_CRYPTO_CIPHER_AES_XTS] = "aes-xts", + + [RTE_CRYPTO_CIPHER_ARC4] = "arc4", + + [RTE_CRYPTO_CIPHER_NULL] = "null", + + [RTE_CRYPTO_CIPHER_KASUMI_F8] = "kasumi-f8", + [RTE_CRYPTO_CIPHER_SNOW3G_UEA2] = "snow3g-uea2", + [RTE_CRYPTO_CIPHER_ZUC_EEA3] = "zuc-eea3" +}; + +/** + * The crypto cipher operation strings identifiers. + * It could be used in application command line. + */ +const char * +rte_crypto_cipher_operation_strings[] = { + [RTE_CRYPTO_CIPHER_OP_ENCRYPT] = "encrypt", + [RTE_CRYPTO_CIPHER_OP_DECRYPT] = "decrypt" +}; + +/** + * The crypto auth algorithm strings identifiers. + * It could be used in application command line. + */ +const char * +rte_crypto_auth_algorithm_strings[] = { + [RTE_CRYPTO_AUTH_AES_CBC_MAC] = "aes-cbc-mac", + [RTE_CRYPTO_AUTH_AES_CCM] = "aes-ccm", + [RTE_CRYPTO_AUTH_AES_CMAC] = "aes-cmac", + [RTE_CRYPTO_AUTH_AES_GCM] = "aes-gcm", + [RTE_CRYPTO_AUTH_AES_GMAC] = "aes-gmac", + [RTE_CRYPTO_AUTH_AES_XCBC_MAC] = "aes-xcbc-mac", + + [RTE_CRYPTO_AUTH_MD5] = "md5", + [RTE_CRYPTO_AUTH_MD5_HMAC] = "md5-hmac", + + [RTE_CRYPTO_AUTH_SHA1] = "sha1", + [RTE_CRYPTO_AUTH_SHA1_HMAC] = "sha1-hmac", + + [RTE_CRYPTO_AUTH_SHA224] = "sha2-224", + [RTE_CRYPTO_AUTH_SHA224_HMAC] = "sha2-224-hmac", + [RTE_CRYPTO_AUTH_SHA256] = "sha2-256", + [RTE_CRYPTO_AUTH_SHA256_HMAC] = "sha2-256-hmac", + [RTE_CRYPTO_AUTH_SHA384] = "sha2-384", + [RTE_CRYPTO_AUTH_SHA384_HMAC] = "sha2-384-hmac", + [RTE_CRYPTO_AUTH_SHA512] = "sha2-512", + [RTE_CRYPTO_AUTH_SHA512_HMAC] = "sha2-512-hmac", + + [RTE_CRYPTO_AUTH_KASUMI_F9] = "kasumi-f9", + [RTE_CRYPTO_AUTH_SNOW3G_UIA2] = "snow3g-uia2", + [RTE_CRYPTO_AUTH_ZUC_EIA3] = "zuc-eia3" +}; + +/** + * The crypto auth operation strings identifiers. + * It could be used in application command line. + */ +const char * +rte_crypto_auth_operation_strings[] = { + [RTE_CRYPTO_AUTH_OP_VERIFY] = "verify", + [RTE_CRYPTO_AUTH_OP_GENERATE] = "generate" +}; + static uint8_t number_of_sockets(void) { @@ -191,6 +271,75 @@ struct rte_cryptodev_callback { return ret; } +const struct rte_cryptodev_symmetric_capability * +rte_cryptodev_capbility_get(uint8_t dev_id, + const struct rte_cryptodev_capbility_idx *idx) +{ + const struct rte_cryptodev_capabilities *capability; + struct rte_cryptodev_info dev_info; + int i; + + rte_cryptodev_info_get(dev_id, &dev_info); + + i = 0; + + while ((capability = &dev_info.capabilities[i++])->op != + RTE_CRYPTO_OP_TYPE_UNDEFINED) { + if (capability->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC) + continue; + + if (capability->sym.xform_type != idx->type) + continue; + + if (idx->type == RTE_CRYPTO_SYM_XFORM_AUTH && + capability->sym.auth.algo == idx->algo.auth) + return &capability->sym; + + if (idx->type == RTE_CRYPTO_SYM_XFORM_CIPHER && + capability->sym.cipher.algo == idx->algo.cipher) + return &capability->sym; + } + + return NULL; + +} + +#define param_range_check(x, y) \ + (((x < y.min && y.min != -1) || (x > y.max && y.min != -1)) || \ + ((y.increment != -1) && (y.increment != 0 && (x % y.increment) != 0))) + +int +rte_cryptodev_capability_check_cipher( + const struct rte_cryptodev_symmetric_capability *capability, + uint16_t key_size, uint16_t iv_size) +{ + if (param_range_check(key_size, capability->cipher.key_size)) + return -1; + + if (param_range_check(iv_size, capability->cipher.iv_size)) + return -1; + + return 0; +} + +int +rte_cryptodev_capability_check_auth( + const struct rte_cryptodev_symmetric_capability *capability, + uint16_t key_size, uint16_t digest_size, uint16_t aad_size) +{ + if (param_range_check(key_size, capability->auth.key_size)) + return -1; + + if (param_range_check(digest_size, capability->auth.digest_size)) + return -1; + + if (param_range_check(aad_size, capability->auth.aad_size)) + return -1; + + return 0; +} + + const char * rte_cryptodev_get_feature_name(uint64_t flag) { @@ -262,6 +411,34 @@ struct rte_cryptodev_callback { } int +rte_cryptodev_devices_get(const char *drv_name, uint8_t *devices, + uint8_t nb_devices) +{ + uint8_t i, cmp, count = 0; + struct rte_cryptodev **devs = &rte_cryptodev_globals->devs; + + for (i = 0; i < rte_cryptodev_globals->max_devs && count < nb_devices; + i++) { + + if ((*devs + i) + && (*devs + i)->attached == RTE_CRYPTODEV_ATTACHED) { + + if ((*devs + i)->pci_dev) + cmp = strncmp((*devs + i)->pci_dev->driver->driver.name, + drv_name, strlen(drv_name)); + else + cmp = strncmp((*devs + i)->data->name, drv_name, + strlen(drv_name)); + + if (cmp == 0) + devices[count++] = (*devs + i)->data->dev_id; + } + } + + return count; +} + +int rte_cryptodev_socket_id(uint8_t dev_id) { struct rte_cryptodev *dev; diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h index 8f63e8f..43041df 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -76,7 +76,7 @@ enum rte_cryptodev_type { RTE_CRYPTODEV_SNOW3G_PMD, /**< SNOW 3G PMD */ RTE_CRYPTODEV_KASUMI_PMD, /**< KASUMI PMD */ RTE_CRYPTODEV_ZUC_PMD, /**< ZUC PMD */ - RTE_CRYPTODEV_OPENSSL_PMD, /**< OpenSSL PMD */ + RTE_CRYPTODEV_OPENSSL_PMD, /**< OpenSSL PMD */ }; extern const char **rte_cyptodev_names; @@ -110,6 +110,20 @@ enum rte_cryptodev_type { #endif /** + * Crypto parameters range description + */ +struct rte_crypto_param_range { + int min; /**< minimum size */ + int max; /**< maximum size */ + int increment; + /**< if a range of sizes are supported, + * this parameter is used to indicate + * increments in byte size that are supported + * between the minimum and maximum + */ +}; + +/** * Symmetric Crypto Capability */ struct rte_cryptodev_symmetric_capability { @@ -122,35 +136,11 @@ struct rte_cryptodev_symmetric_capability { /**< authentication algorithm */ uint16_t block_size; /**< algorithm block size */ - struct { - uint16_t min; /**< minimum key size */ - uint16_t max; /**< maximum key size */ - uint16_t increment; - /**< if a range of sizes are supported, - * this parameter is used to indicate - * increments in byte size that are supported - * between the minimum and maximum */ - } key_size; + struct rte_crypto_param_range key_size; /**< auth key size range */ - struct { - uint16_t min; /**< minimum digest size */ - uint16_t max; /**< maximum digest size */ - uint16_t increment; - /**< if a range of sizes are supported, - * this parameter is used to indicate - * increments in byte size that are supported - * between the minimum and maximum */ - } digest_size; + struct rte_crypto_param_range digest_size; /**< digest size range */ - struct { - uint16_t min; /**< minimum aad size */ - uint16_t max; /**< maximum aad size */ - uint16_t increment; - /**< if a range of sizes are supported, - * this parameter is used to indicate - * increments in byte size that are supported - * between the minimum and maximum */ - } aad_size; + struct rte_crypto_param_range aad_size; /**< Additional authentication data size range */ } auth; /**< Symmetric Authentication transform capabilities */ @@ -159,25 +149,9 @@ struct rte_cryptodev_symmetric_capability { /**< cipher algorithm */ uint16_t block_size; /**< algorithm block size */ - struct { - uint16_t min; /**< minimum key size */ - uint16_t max; /**< maximum key size */ - uint16_t increment; - /**< if a range of sizes are supported, - * this parameter is used to indicate - * increments in byte size that are supported - * between the minimum and maximum */ - } key_size; + struct rte_crypto_param_range key_size; /**< cipher key size range */ - struct { - uint16_t min; /**< minimum iv size */ - uint16_t max; /**< maximum iv size */ - uint16_t increment; - /**< if a range of sizes are supported, - * this parameter is used to indicate - * increments in byte size that are supported - * between the minimum and maximum */ - } iv_size; + struct rte_crypto_param_range iv_size; /**< Initialisation vector data size range */ } cipher; /**< Symmetric Cipher transform capabilities */ @@ -196,6 +170,38 @@ struct rte_cryptodev_capabilities { }; }; +/** Structure used to describe crypto algorithms */ +struct rte_cryptodev_capbility_idx { + enum rte_crypto_sym_xform_type type; + union { + enum rte_crypto_cipher_algorithm cipher; + enum rte_crypto_auth_algorithm auth; + } algo; +}; + +/** Provide capabilities available for defined device and algorithm */ +const struct rte_cryptodev_symmetric_capability * +rte_cryptodev_capbility_get(uint8_t dev_id, + const struct rte_cryptodev_capbility_idx *idx); + +/** + * Check if key size and initial vector are supported + * in crypto cipher capability + */ +int +rte_cryptodev_capability_check_cipher( + const struct rte_cryptodev_symmetric_capability *capability, + uint16_t key_size, uint16_t iv_size); + +/** + * Check if key size and initial vector are supported + * in crypto auth capability + */ +int +rte_cryptodev_capability_check_auth( + const struct rte_cryptodev_symmetric_capability *capability, + uint16_t key_size, uint16_t digest_size, uint16_t aad_size); + /** Macro used at end of crypto PMD list */ #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \ { RTE_CRYPTO_OP_TYPE_UNDEFINED } @@ -365,8 +371,30 @@ struct rte_crypto_vdev_init_params { extern uint8_t rte_cryptodev_count(void); +/** + * Get number of crypto device defined type. + * + * @param type type of device. + * + * @return + * Returns number of crypto device. + */ extern uint8_t rte_cryptodev_count_devtype(enum rte_cryptodev_type type); + +/** + * Get number and identifiers of attached crypto device. + * + * @param drv_name device name. + * @param devices output devices identifiers. + * @param nb_devices maximal number of devices. + * + * @return + * Returns number of attached crypto device. + */ +int +rte_cryptodev_devices_get(const char *drv_name, uint8_t *devices, + uint8_t nb_devices); /* * Return the NUMA socket to which a device is connected * -- 1.7.9.5