crypto/dpaa_sec: support scatter gather for PDCP
[dpdk.git] / lib / librte_cryptodev / rte_cryptodev.c
index 871d7dd..43bc335 100644 (file)
@@ -250,7 +250,7 @@ rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
        return -1;
 }
 
-int __rte_experimental
+int
 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
                const char *xform_string)
 {
@@ -338,7 +338,7 @@ param_range_check(uint16_t size, const struct rte_crypto_param_range *range)
        return -1;
 }
 
-const struct rte_cryptodev_asymmetric_xform_capability * __rte_experimental
+const struct rte_cryptodev_asymmetric_xform_capability *
 rte_cryptodev_asym_capability_get(uint8_t dev_id,
                const struct rte_cryptodev_asym_capability_idx *idx)
 {
@@ -411,7 +411,7 @@ rte_cryptodev_sym_capability_check_aead(
 
        return 0;
 }
-int __rte_experimental
+int
 rte_cryptodev_asym_xform_capability_check_optype(
        const struct rte_cryptodev_asymmetric_xform_capability *capability,
        enum rte_crypto_asym_op_type op_type)
@@ -422,7 +422,7 @@ rte_cryptodev_asym_xform_capability_check_optype(
        return 0;
 }
 
-int __rte_experimental
+int
 rte_cryptodev_asym_xform_capability_check_modlen(
        const struct rte_cryptodev_asymmetric_xform_capability *capability,
        uint16_t modlen)
@@ -486,6 +486,12 @@ rte_cryptodev_get_feature_name(uint64_t flag)
                return "CPU_ARM_CE";
        case RTE_CRYPTODEV_FF_SECURITY:
                return "SECURITY_PROTOCOL";
+       case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP:
+               return "RSA_PRIV_OP_KEY_EXP";
+       case RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT:
+               return "RSA_PRIV_OP_KEY_QT";
+       case RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED:
+               return "DIGEST_ENCRYPTED";
        default:
                return NULL;
        }
@@ -623,7 +629,7 @@ static inline int
 rte_cryptodev_data_alloc(uint8_t dev_id, struct rte_cryptodev_data **data,
                int socket_id)
 {
-       char mz_name[RTE_CRYPTODEV_NAME_MAX_LEN];
+       char mz_name[RTE_MEMZONE_NAMESIZE];
        const struct rte_memzone *mz;
        int n;
 
@@ -649,6 +655,31 @@ rte_cryptodev_data_alloc(uint8_t dev_id, struct rte_cryptodev_data **data,
        return 0;
 }
 
+static inline int
+rte_cryptodev_data_free(uint8_t dev_id, struct rte_cryptodev_data **data)
+{
+       char mz_name[RTE_MEMZONE_NAMESIZE];
+       const struct rte_memzone *mz;
+       int n;
+
+       /* generate memzone name */
+       n = snprintf(mz_name, sizeof(mz_name), "rte_cryptodev_data_%u", dev_id);
+       if (n >= (int)sizeof(mz_name))
+               return -EINVAL;
+
+       mz = rte_memzone_lookup(mz_name);
+       if (mz == NULL)
+               return -ENOMEM;
+
+       RTE_ASSERT(*data == mz->addr);
+       *data = NULL;
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               return rte_memzone_free(mz);
+
+       return 0;
+}
+
 static uint8_t
 rte_cryptodev_find_free_device_index(void)
 {
@@ -683,19 +714,19 @@ rte_cryptodev_pmd_allocate(const char *name, int socket_id)
        cryptodev = rte_cryptodev_pmd_get_dev(dev_id);
 
        if (cryptodev->data == NULL) {
-               struct rte_cryptodev_data *cryptodev_data =
-                               cryptodev_globals.data[dev_id];
+               struct rte_cryptodev_data **cryptodev_data =
+                               &cryptodev_globals.data[dev_id];
 
-               int retval = rte_cryptodev_data_alloc(dev_id, &cryptodev_data,
+               int retval = rte_cryptodev_data_alloc(dev_id, cryptodev_data,
                                socket_id);
 
-               if (retval < 0 || cryptodev_data == NULL)
+               if (retval < 0 || *cryptodev_data == NULL)
                        return NULL;
 
-               cryptodev->data = cryptodev_data;
+               cryptodev->data = *cryptodev_data;
 
-               snprintf(cryptodev->data->name, RTE_CRYPTODEV_NAME_MAX_LEN,
-                               "%s", name);
+               strlcpy(cryptodev->data->name, name,
+                       RTE_CRYPTODEV_NAME_MAX_LEN);
 
                cryptodev->data->dev_id = dev_id;
                cryptodev->data->socket_id = socket_id;
@@ -716,17 +747,24 @@ int
 rte_cryptodev_pmd_release_device(struct rte_cryptodev *cryptodev)
 {
        int ret;
+       uint8_t dev_id;
 
        if (cryptodev == NULL)
                return -EINVAL;
 
+       dev_id = cryptodev->data->dev_id;
+
        /* Close device only if device operations have been set */
        if (cryptodev->dev_ops) {
-               ret = rte_cryptodev_close(cryptodev->data->dev_id);
+               ret = rte_cryptodev_close(dev_id);
                if (ret < 0)
                        return ret;
        }
 
+       ret = rte_cryptodev_data_free(dev_id, &cryptodev_globals.data[dev_id]);
+       if (ret < 0)
+               return ret;
+
        cryptodev->attached = RTE_CRYPTODEV_DETACHED;
        cryptodev_globals.nb_devs--;
        return 0;
@@ -1231,7 +1269,7 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
        return 0;
 }
 
-int __rte_experimental
+int
 rte_cryptodev_asym_session_init(uint8_t dev_id,
                struct rte_cryptodev_asym_session *sess,
                struct rte_crypto_asym_xform *xforms,
@@ -1266,7 +1304,7 @@ rte_cryptodev_asym_session_init(uint8_t dev_id,
        return 0;
 }
 
-struct rte_mempool * __rte_experimental
+struct rte_mempool *
 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
        uint32_t elt_size, uint32_t cache_size, uint16_t user_data_size,
        int socket_id)
@@ -1350,7 +1388,7 @@ rte_cryptodev_sym_session_create(struct rte_mempool *mp)
        return sess;
 }
 
-struct rte_cryptodev_asym_session * __rte_experimental
+struct rte_cryptodev_asym_session *
 rte_cryptodev_asym_session_create(struct rte_mempool *mp)
 {
        struct rte_cryptodev_asym_session *sess;
@@ -1382,6 +1420,8 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id,
                return -EINVAL;
 
        driver_id = dev->driver_id;
+       if (sess->sess_data[driver_id].refcnt == 0)
+               return 0;
        if (--sess->sess_data[driver_id].refcnt != 0)
                return -EBUSY;
 
@@ -1392,7 +1432,7 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id,
        return 0;
 }
 
-int __rte_experimental
+int
 rte_cryptodev_asym_session_clear(uint8_t dev_id,
                struct rte_cryptodev_asym_session *sess)
 {
@@ -1432,7 +1472,7 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess)
        return 0;
 }
 
-int __rte_experimental
+int
 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess)
 {
        uint8_t i;
@@ -1472,7 +1512,7 @@ rte_cryptodev_sym_get_header_session_size(void)
                        rte_cryptodev_sym_session_data_size(&s));
 }
 
-unsigned int __rte_experimental
+unsigned int
 rte_cryptodev_sym_get_existing_header_session_size(
                struct rte_cryptodev_sym_session *sess)
 {
@@ -1483,7 +1523,7 @@ rte_cryptodev_sym_get_existing_header_session_size(
                                rte_cryptodev_sym_session_data_size(sess));
 }
 
-unsigned int __rte_experimental
+unsigned int
 rte_cryptodev_asym_get_header_session_size(void)
 {
        /*
@@ -1513,7 +1553,7 @@ rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
        return priv_sess_size;
 }
 
-unsigned int __rte_experimental
+unsigned int
 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 {
        struct rte_cryptodev *dev;
@@ -1536,7 +1576,7 @@ rte_cryptodev_asym_get_private_session_size(uint8_t dev_id)
 
 }
 
-int __rte_experimental
+int
 rte_cryptodev_sym_session_set_user_data(
                                        struct rte_cryptodev_sym_session *sess,
                                        void *data,
@@ -1552,7 +1592,7 @@ rte_cryptodev_sym_session_set_user_data(
        return 0;
 }
 
-void * __rte_experimental
+void *
 rte_cryptodev_sym_session_get_user_data(
                                        struct rte_cryptodev_sym_session *sess)
 {