bus/fslmc: support static dequeue from portal
[dpdk.git] / drivers / crypto / snow3g / rte_snow3g_pmd.c
index a4a2a0f..107e1b4 100644 (file)
@@ -47,6 +47,8 @@
 #define SNOW3G_MAX_BURST 8
 #define BYTE_LEN 8
 
+static uint8_t cryptodev_driver_id;
+
 /** Get xform chain order. */
 static enum snow3g_operation
 snow3g_get_mode(const struct rte_crypto_sym_xform *xform)
@@ -132,6 +134,12 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
                /* Only SNOW 3G UIA2 supported */
                if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_SNOW3G_UIA2)
                        return -EINVAL;
+
+               if (auth_xform->auth.digest_length != SNOW3G_DIGEST_LENGTH) {
+                       SNOW3G_LOG_ERR("Wrong digest length");
+                       return -EINVAL;
+               }
+
                sess->auth_op = auth_xform->auth.op;
 
                if (auth_xform->auth.iv.length != SNOW3G_IV_LENGTH) {
@@ -155,27 +163,41 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
 static struct snow3g_session *
 snow3g_get_session(struct snow3g_qp *qp, struct rte_crypto_op *op)
 {
-       struct snow3g_session *sess;
+       struct snow3g_session *sess = NULL;
 
        if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-               if (unlikely(op->sym->session->dev_type !=
-                               RTE_CRYPTODEV_SNOW3G_PMD))
+               if (likely(op->sym->session != NULL))
+                       sess = (struct snow3g_session *)
+                                       get_session_private_data(
+                                       op->sym->session,
+                                       cryptodev_driver_id);
+       } else {
+               void *_sess = NULL;
+               void *_sess_private_data = NULL;
+
+               if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
                        return NULL;
 
-               sess = (struct snow3g_session *)op->sym->session->_private;
-       } else  {
-               struct rte_cryptodev_session *c_sess = NULL;
-
-               if (rte_mempool_get(qp->sess_mp, (void **)&c_sess))
+               if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
                        return NULL;
 
-               sess = (struct snow3g_session *)c_sess->_private;
+               sess = (struct snow3g_session *)_sess_private_data;
 
                if (unlikely(snow3g_set_session_parameters(sess,
-                               op->sym->xform) != 0))
-                       return NULL;
+                               op->sym->xform) != 0)) {
+                       rte_mempool_put(qp->sess_mp, _sess);
+                       rte_mempool_put(qp->sess_mp, _sess_private_data);
+                       sess = NULL;
+               }
+               op->sym->session = (struct rte_cryptodev_sym_session *)_sess;
+               set_session_private_data(op->sym->session, cryptodev_driver_id,
+                       _sess_private_data);
        }
 
+       if (unlikely(sess == NULL))
+               op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
+
+
        return sess;
 }
 
@@ -252,12 +274,6 @@ process_snow3g_hash_op(struct rte_crypto_op **ops,
        uint8_t *iv;
 
        for (i = 0; i < num_ops; i++) {
-               if (unlikely(ops[i]->sym->auth.digest.length != SNOW3G_DIGEST_LENGTH)) {
-                       ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
-                       SNOW3G_LOG_ERR("digest");
-                       break;
-               }
-
                /* Data must be byte aligned */
                if ((ops[i]->sym->auth.data.offset % BYTE_LEN) != 0) {
                        ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
@@ -274,19 +290,19 @@ process_snow3g_hash_op(struct rte_crypto_op **ops,
 
                if (session->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
                        dst = (uint8_t *)rte_pktmbuf_append(ops[i]->sym->m_src,
-                                       ops[i]->sym->auth.digest.length);
+                                       SNOW3G_DIGEST_LENGTH);
 
                        sso_snow3g_f9_1_buffer(&session->pKeySched_hash,
                                        iv, src,
                                        length_in_bits, dst);
                        /* Verify digest. */
                        if (memcmp(dst, ops[i]->sym->auth.digest.data,
-                                       ops[i]->sym->auth.digest.length) != 0)
+                                       SNOW3G_DIGEST_LENGTH) != 0)
                                ops[i]->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
 
                        /* Trim area used for digest from mbuf. */
                        rte_pktmbuf_trim(ops[i]->sym->m_src,
-                                       ops[i]->sym->auth.digest.length);
+                                       SNOW3G_DIGEST_LENGTH);
                } else  {
                        dst = ops[i]->sym->auth.digest.data;
 
@@ -357,6 +373,10 @@ process_ops(struct rte_crypto_op **ops, struct snow3g_session *session,
                        ops[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
                /* Free session if a session-less crypto op. */
                if (ops[i]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
+                       memset(session, 0, sizeof(struct snow3g_session));
+                       memset(ops[i]->sym->session, 0,
+                                       rte_cryptodev_get_header_session_size());
+                       rte_mempool_put(qp->sess_mp, session);
                        rte_mempool_put(qp->sess_mp, ops[i]->sym->session);
                        ops[i]->sym->session = NULL;
                }
@@ -409,7 +429,8 @@ process_op_bit(struct rte_crypto_op *op, struct snow3g_session *session,
 
        /* Free session if a session-less crypto op. */
        if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
-               rte_mempool_put(qp->sess_mp, op->sym->session);
+               memset(op->sym->session, 0, sizeof(struct snow3g_session));
+               rte_cryptodev_sym_session_free(op->sym->session);
                op->sym->session = NULL;
        }
 
@@ -562,7 +583,7 @@ cryptodev_snow3g_create(const char *name,
                goto init_error;
        }
 
-       dev->dev_type = RTE_CRYPTODEV_SNOW3G_PMD;
+       dev->driver_id = cryptodev_driver_id;
        dev->dev_ops = rte_snow3g_pmd_ops;
 
        /* Register RX/TX burst functions for data path. */
@@ -646,3 +667,4 @@ RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_SNOW3G_PMD,
        "max_nb_queue_pairs=<int> "
        "max_nb_sessions=<int> "
        "socket_id=<int>");
+RTE_PMD_REGISTER_CRYPTO_DRIVER(cryptodev_snow3g_pmd_drv, cryptodev_driver_id);