From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 23C75F60E for ; Wed, 11 Jan 2017 15:10:19 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 11 Jan 2017 06:10:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,346,1477983600"; d="scan'208";a="29034365" Received: from gklab-246-019.igk.intel.com (HELO intel.com) ([10.217.246.19]) by orsmga002.jf.intel.com with SMTP; 11 Jan 2017 06:10:16 -0800 Received: by intel.com (sSMTP sendmail emulation); Wed, 11 Jan 2017 17:09:37 +0100 From: Slawomir Mrozowicz To: dev@dpdk.org Cc: Slawomir Mrozowicz , Declan Doherty , Marcin Kerlin Date: Wed, 11 Jan 2017 17:07:08 +0100 Message-Id: <1484150829-20734-2-git-send-email-slawomirx.mrozowicz@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484150829-20734-1-git-send-email-slawomirx.mrozowicz@intel.com> References: <1483635001-15473-1-git-send-email-slawomirx.mrozowicz@intel.com> <1484150829-20734-1-git-send-email-slawomirx.mrozowicz@intel.com> Subject: [dpdk-dev] [PATCH v3 1/2] cryptodev: add functions to retrieve device info 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: Wed, 11 Jan 2017 14:10:21 -0000 This patch adds helper functions for new performance application which provide identifiers and number of crypto device and provide and check capabilities available for defined device and algorithm. The performance application can be used to measure 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 --- To be applied on top of: [dpdk-dev,v4] crypto/aesni_gcm: migration from MB library to ISA-L v2 changes: - code style fix - add information in version.map about changes v3 changes: - title of the cryptodev patch - supply information in version.map about changes --- lib/librte_cryptodev/rte_crypto_sym.h | 16 +++ lib/librte_cryptodev/rte_cryptodev.c | 181 +++++++++++++++++++++++++ lib/librte_cryptodev/rte_cryptodev.h | 120 +++++++++------- lib/librte_cryptodev/rte_cryptodev_version.map | 14 ++ 4 files changed, 285 insertions(+), 46 deletions(-) diff --git a/lib/librte_cryptodev/rte_crypto_sym.h b/lib/librte_cryptodev/rte_crypto_sym.h index 0e20b30..c782588 100644 --- a/lib/librte_cryptodev/rte_crypto_sym.h +++ b/lib/librte_cryptodev/rte_crypto_sym.h @@ -112,6 +112,10 @@ enum rte_crypto_cipher_algorithm { }; +/** 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, @@ -120,6 +124,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. * @@ -245,12 +253,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 bbab4b3..c126b1b 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -111,6 +111,86 @@ static const char *cryptodev_vdev_valid_params[] = { 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,73 @@ rte_cryptodev_parse_vdev_init_params(struct rte_crypto_vdev_init_params *params, return ret; } +const struct rte_cryptodev_symmetric_capability * +rte_cryptodev_capability_get(uint8_t dev_id, + const struct rte_cryptodev_capability_idx *idx) +{ + const struct rte_cryptodev_capabilities *capability; + struct rte_cryptodev_info dev_info; + int i = 0; + + rte_cryptodev_info_get(dev_id, &dev_info); + + 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) || (x > y.max)) || \ + (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) { @@ -263,6 +410,40 @@ rte_cryptodev_count_devtype(enum rte_cryptodev_type type) } int +rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices, + uint8_t nb_devices) +{ + uint8_t i, cmp, count = 0; + struct rte_cryptodev **devs = &rte_cryptodev_globals->devs; + struct rte_pci_device *pci; + + for (i = 0; i < rte_cryptodev_globals->max_devs && count < nb_devices; + i++) { + + if ((*devs + i) + && (*devs + i)->attached == + RTE_CRYPTODEV_ATTACHED) { + + pci = (*devs + i)->pci_dev; + + if (pci) + cmp = strncmp(pci->driver->driver.name, + dev_name, + strlen(dev_name)); + else + cmp = strncmp((*devs + i)->data->name, + dev_name, + strlen(dev_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 fa311a9..97d1a86 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 @@ extern const char **rte_cyptodev_names; #endif /** + * Crypto parameters range description + */ +struct rte_crypto_param_range { + uint16_t min; /**< minimum size */ + uint16_t max; /**< maximum 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 + */ +}; + +/** * 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_capability_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_capability_get(uint8_t dev_id, + const struct rte_cryptodev_capability_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 } @@ -369,8 +375,30 @@ rte_cryptodev_get_dev_id(const char *name); 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 dev_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 *dev_name, uint8_t *devices, + uint8_t nb_devices); /* * Return the NUMA socket to which a device is connected * diff --git a/lib/librte_cryptodev/rte_cryptodev_version.map b/lib/librte_cryptodev/rte_cryptodev_version.map index 9dde0e7..bdd5e5d 100644 --- a/lib/librte_cryptodev/rte_cryptodev_version.map +++ b/lib/librte_cryptodev/rte_cryptodev_version.map @@ -46,3 +46,17 @@ DPDK_16.11 { rte_cryptodev_pci_remove; } DPDK_16.07; + +DPDK_17.02 { + global: + + rte_cryptodev_capability_check_auth; + rte_cryptodev_capability_check_cipher; + rte_cryptodev_capability_get; + rte_cryptodev_devices_get; + rte_crypto_auth_algorithm_strings; + rte_crypto_auth_operation_strings; + rte_crypto_cipher_algorithm_strings; + rte_crypto_cipher_operation_strings; + +} DPDK_16.11; -- 2.5.0