drivers/crypto: invoke probing finish function
[dpdk.git] / drivers / crypto / caam_jr / caam_jr.c
index e87c989..8c56610 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <rte_byteorder.h>
 #include <rte_common.h>
-#include <rte_cryptodev_pmd.h>
+#include <cryptodev_pmd.h>
 #include <rte_crypto.h>
 #include <rte_cryptodev.h>
 #include <rte_bus_vdev.h>
 #include <caam_jr_log.h>
 
 /* RTA header files */
-#include <hw/desc/common.h>
-#include <hw/desc/algo.h>
-#include <of.h>
+#include <desc/common.h>
+#include <desc/algo.h>
+#include <dpaa_of.h>
 #ifdef RTE_LIBRTE_PMD_CAAM_JR_DEBUG
-#define CAAM_JR_DBG    1
+#define CAAM_JR_DBG    1
 #else
 #define CAAM_JR_DBG    0
 #endif
 #define CRYPTODEV_NAME_CAAM_JR_PMD     crypto_caam_jr
 static uint8_t cryptodev_driver_id;
-int caam_jr_logtype;
-
-enum rta_sec_era rta_sec_era;
 
 /* Lists the states possible for the SEC user space driver. */
 enum sec_driver_state_e {
@@ -336,7 +333,6 @@ caam_jr_prep_cdb(struct caam_jr_session *ses)
                shared_desc_len = cnstr_shdsc_blkcipher(
                                                cdb->sh_desc, true,
                                                swap, SHR_NEVER, &alginfo_c,
-                                               NULL,
                                                ses->iv.length,
                                                ses->dir);
        } else if (is_auth_only(ses)) {
@@ -450,13 +446,11 @@ caam_jr_prep_cdb(struct caam_jr_session *ses)
                                                &alginfo_c, &alginfo_a);
                        }
                } else {
-                       /* Auth_only_len is set as 0 here and it will be
-                        * overwritten in fd for each packet.
-                        */
+                       /* Auth_only_len is overwritten in fd for each job */
                        shared_desc_len = cnstr_shdsc_authenc(cdb->sh_desc,
                                        true, swap, SHR_SERIAL,
                                        &alginfo_c, &alginfo_a,
-                                       ses->iv.length, 0,
+                                       ses->iv.length,
                                        ses->digest_length, ses->dir);
                }
        }
@@ -1066,10 +1060,11 @@ build_cipher_auth_sg(struct rte_crypto_op *op, struct caam_jr_session *ses)
        uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
                        ses->iv.offset);
        struct sec_job_descriptor_t *jobdescr;
-       uint32_t auth_only_len;
-
-       auth_only_len = op->sym->auth.data.length -
-                               op->sym->cipher.data.length;
+       uint16_t auth_hdr_len = sym->cipher.data.offset -
+                       sym->auth.data.offset;
+       uint16_t auth_tail_len = sym->auth.data.length -
+                       sym->cipher.data.length - auth_hdr_len;
+       uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
 
        if (sym->m_dst) {
                mbuf = sym->m_dst;
@@ -1208,10 +1203,11 @@ build_cipher_auth(struct rte_crypto_op *op, struct caam_jr_session *ses)
        uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
                        ses->iv.offset);
        struct sec_job_descriptor_t *jobdescr;
-       uint32_t auth_only_len;
-
-       auth_only_len = op->sym->auth.data.length -
-                               op->sym->cipher.data.length;
+       uint16_t auth_hdr_len = sym->cipher.data.offset -
+                       sym->auth.data.offset;
+       uint16_t auth_tail_len = sym->auth.data.length -
+                       sym->cipher.data.length - auth_hdr_len;
+       uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
 
        src_start_addr = rte_pktmbuf_iova(sym->m_src);
        if (sym->m_dst)
@@ -1354,6 +1350,9 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp)
        struct caam_jr_session *ses;
        struct caam_jr_op_ctx *ctx = NULL;
        struct sec_job_descriptor_t *jobdescr __rte_unused;
+#if CAAM_JR_DBG
+       int i;
+#endif
 
        switch (op->sess_type) {
        case RTE_CRYPTO_OP_WITH_SESSION:
@@ -1416,7 +1415,7 @@ err1:
                        rte_pktmbuf_data_len(op->sym->m_src));
 
        printf("\n JD before conversion\n");
-       for (int i = 0; i < 12; i++)
+       for (i = 0; i < 12; i++)
                printf("\n 0x%08x", ctx->jobdes.desc[i]);
 #endif
 
@@ -1539,15 +1538,6 @@ caam_jr_queue_pair_setup(
        return 0;
 }
 
-/* Return the number of allocated queue pairs */
-static uint32_t
-caam_jr_queue_pair_count(struct rte_cryptodev *dev)
-{
-       PMD_INIT_FUNC_TRACE();
-
-       return dev->data->nb_queue_pairs;
-}
-
 /* Returns the size of the aesni gcm session structure */
 static unsigned int
 caam_jr_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
@@ -1893,6 +1883,8 @@ caam_jr_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
                        PDBOPTS_ESP_OIHI_PDB_INL |
                        PDBOPTS_ESP_IVSRC |
                        PDBHMO_ESP_ENCAP_DTTL;
+               if (ipsec_xform->options.esn)
+                       session->encap_pdb.options |= PDBOPTS_ESP_ESN;
                session->encap_pdb.spi = ipsec_xform->spi;
                session->encap_pdb.ip_hdr_len = sizeof(struct ip);
 
@@ -1901,6 +1893,8 @@ caam_jr_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
                        RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
                memset(&session->decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
                session->decap_pdb.options = sizeof(struct ip) << 16;
+               if (ipsec_xform->options.esn)
+                       session->decap_pdb.options |= PDBOPTS_ESP_ESN;
                session->dir = DIR_DEC;
        } else
                goto out;
@@ -2059,7 +2053,6 @@ static struct rte_cryptodev_ops caam_jr_ops = {
        .stats_reset          = caam_jr_stats_reset,
        .queue_pair_setup     = caam_jr_queue_pair_setup,
        .queue_pair_release   = caam_jr_queue_pair_release,
-       .queue_pair_count     = caam_jr_queue_pair_count,
        .sym_session_get_size = caam_jr_sym_session_get_size,
        .sym_session_configure = caam_jr_sym_session_configure,
        .sym_session_clear    = caam_jr_sym_session_clear
@@ -2081,7 +2074,7 @@ static struct rte_security_ops caam_jr_security_ops = {
 static void
 close_job_ring(struct sec_job_ring_t *job_ring)
 {
-       if (job_ring->irq_fd) {
+       if (job_ring->irq_fd != -1) {
                /* Producer index is frozen. If consumer index is not equal
                 * with producer index, then we have descs to flush.
                 */
@@ -2090,7 +2083,7 @@ close_job_ring(struct sec_job_ring_t *job_ring)
 
                /* free the uio job ring */
                free_job_ring(job_ring->irq_fd);
-               job_ring->irq_fd = 0;
+               job_ring->irq_fd = -1;
                caam_jr_dma_free(job_ring->input_ring);
                caam_jr_dma_free(job_ring->output_ring);
                g_job_rings_no--;
@@ -2194,7 +2187,7 @@ caam_jr_dev_uninit(struct rte_cryptodev *dev)
  *
  */
 static void *
-init_job_ring(void *reg_base_addr, uint32_t irq_id)
+init_job_ring(void *reg_base_addr, int irq_id)
 {
        struct sec_job_ring_t *job_ring = NULL;
        int i, ret = 0;
@@ -2204,7 +2197,7 @@ init_job_ring(void *reg_base_addr, uint32_t irq_id)
        int irq_coalescing_count = 0;
 
        for (i = 0; i < MAX_SEC_JOB_RINGS; i++) {
-               if (g_job_rings[i].irq_fd == 0) {
+               if (g_job_rings[i].irq_fd == -1) {
                        job_ring = &g_job_rings[i];
                        g_job_rings_no++;
                        break;
@@ -2375,6 +2368,8 @@ caam_jr_dev_init(const char *name,
        security_instance->sess_cnt = 0;
        dev->security_ctx = security_instance;
 
+       rte_cryptodev_pmd_probing_finish(dev);
+
        RTE_LOG(INFO, PMD, "%s cryptodev init\n", dev->data->name);
 
        return 0;
@@ -2395,6 +2390,8 @@ init_error:
 static int
 cryptodev_caam_jr_probe(struct rte_vdev_device *vdev)
 {
+       int ret;
+
        struct rte_cryptodev_pmd_init_params init_params = {
                "",
                sizeof(struct sec_job_ring_t),
@@ -2411,6 +2408,12 @@ cryptodev_caam_jr_probe(struct rte_vdev_device *vdev)
        input_args = rte_vdev_device_args(vdev);
        rte_cryptodev_pmd_parse_input_args(&init_params, input_args);
 
+       ret = of_init();
+       if (ret) {
+               RTE_LOG(ERR, PMD,
+               "of_init failed\n");
+               return -EINVAL;
+       }
        /* if sec device version is not configured */
        if (!rta_get_sec_era()) {
                const struct device_node *caam_node;
@@ -2421,7 +2424,7 @@ cryptodev_caam_jr_probe(struct rte_vdev_device *vdev)
                                        NULL);
                        if (prop) {
                                rta_set_sec_era(
-                                       INTL_SEC_ERA(cpu_to_caam32(*prop)));
+                                       INTL_SEC_ERA(rte_be_to_cpu_32(*prop)));
                                break;
                        }
                }
@@ -2457,6 +2460,15 @@ cryptodev_caam_jr_remove(struct rte_vdev_device *vdev)
        return rte_cryptodev_pmd_destroy(cryptodev);
 }
 
+static void
+sec_job_rings_init(void)
+{
+       int i;
+
+       for (i = 0; i < MAX_SEC_JOB_RINGS; i++)
+               g_job_rings[i].irq_fd = -1;
+}
+
 static struct rte_vdev_driver cryptodev_caam_jr_drv = {
        .probe = cryptodev_caam_jr_probe,
        .remove = cryptodev_caam_jr_remove
@@ -2471,9 +2483,10 @@ RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_CAAM_JR_PMD,
 RTE_PMD_REGISTER_CRYPTO_DRIVER(caam_jr_crypto_drv, cryptodev_caam_jr_drv.driver,
                cryptodev_driver_id);
 
-RTE_INIT(caam_jr_init_log)
+RTE_INIT(caam_jr_init)
 {
-       caam_jr_logtype = rte_log_register("pmd.crypto.caam");
-       if (caam_jr_logtype >= 0)
-               rte_log_set_level(caam_jr_logtype, RTE_LOG_NOTICE);
+       sec_uio_job_rings_init();
+       sec_job_rings_init();
 }
+
+RTE_LOG_REGISTER(caam_jr_logtype, pmd.crypto.caam, NOTICE);