crypto/qat: support DOCSIS protocol
[dpdk.git] / drivers / crypto / qat / qat_sym.c
index 25b6dd5..55251d1 100644 (file)
@@ -9,6 +9,9 @@
 #include <rte_crypto_sym.h>
 #include <rte_bus_pci.h>
 #include <rte_byteorder.h>
+#ifdef RTE_LIBRTE_SECURITY
+#include <rte_net_crc.h>
+#endif
 
 #include "qat_sym.h"
 
@@ -99,6 +102,29 @@ qat_bpicipher_preprocess(struct qat_sym_session *ctx,
        return sym_op->cipher.data.length - last_block_len;
 }
 
+#ifdef RTE_LIBRTE_SECURITY
+static inline void
+qat_crc_generate(struct qat_sym_session *ctx,
+                       struct rte_crypto_op *op)
+{
+       struct rte_crypto_sym_op *sym_op = op->sym;
+       uint32_t *crc, crc_length;
+       uint8_t *crc_data;
+
+       if (ctx->qat_dir == ICP_QAT_HW_CIPHER_ENCRYPT &&
+                       sym_op->auth.data.length != 0) {
+
+               crc_length = sym_op->auth.data.length;
+               crc_data = rte_pktmbuf_mtod_offset(sym_op->m_src, uint8_t *,
+                               sym_op->auth.data.offset);
+               crc = (uint32_t *)(crc_data + crc_length);
+
+               *crc = rte_net_crc_calc(crc_data, crc_length,
+                               RTE_NET_CRC32_ETH);
+       }
+}
+#endif
+
 static inline void
 set_cipher_iv(uint16_t iv_length, uint16_t iv_offset,
                struct icp_qat_fw_la_cipher_req_params *cipher_param,
@@ -149,7 +175,7 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
                void *op_cookie, enum qat_device_gen qat_dev_gen)
 {
        int ret = 0;
-       struct qat_sym_session *ctx;
+       struct qat_sym_session *ctx = NULL;
        struct icp_qat_fw_la_cipher_req_params *cipher_param;
        struct icp_qat_fw_la_auth_req_params *auth_param;
        register struct icp_qat_fw_la_bulk_req *qat_req;
@@ -161,6 +187,7 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
        uint64_t auth_data_end = 0;
        uint8_t do_sgl = 0;
        uint8_t in_place = 1;
+       uint8_t is_docsis_sec = 0;
        int alignment_adjustment = 0;
        struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
        struct qat_sym_op_cookie *cookie =
@@ -177,11 +204,23 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
                QAT_DP_LOG(ERR, "QAT PMD only supports session oriented"
                                " requests, op (%p) is sessionless.", op);
                return -EINVAL;
+       } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
+               ctx = (struct qat_sym_session *)get_sym_session_private_data(
+                               op->sym->session, cryptodev_qat_driver_id);
+#ifdef RTE_LIBRTE_SECURITY
+       } else {
+               ctx = (struct qat_sym_session *)get_sec_session_private_data(
+                               op->sym->sec_session);
+               if (ctx && ctx->bpi_ctx == NULL) {
+                       QAT_DP_LOG(ERR, "QAT PMD only supports security"
+                                       " operation requests for DOCSIS, op"
+                                       " (%p) is not for DOCSIS.", op);
+                       return -EINVAL;
+               }
+               is_docsis_sec = 1;
+#endif
        }
 
-       ctx = (struct qat_sym_session *)get_sym_session_private_data(
-                       op->sym->session, cryptodev_qat_driver_id);
-
        if (unlikely(ctx == NULL)) {
                QAT_DP_LOG(ERR, "Session was not created for this device");
                return -EINVAL;
@@ -242,7 +281,29 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
                        cipher_ofs = op->sym->cipher.data.offset >> 3;
 
                } else if (ctx->bpi_ctx) {
-                       /* DOCSIS - only send complete blocks to device
+                       /* DOCSIS processing */
+#ifdef RTE_LIBRTE_SECURITY
+                       if (is_docsis_sec) {
+                               /* Check for OOP */
+                               if (unlikely((op->sym->m_dst != NULL) &&
+                                               (op->sym->m_dst !=
+                                               op->sym->m_src))) {
+                                       QAT_DP_LOG(ERR,
+                                               "OOP not supported for DOCSIS "
+                                               "security");
+                                       op->status =
+                                       RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+                                       return -EINVAL;
+                               }
+
+                               /* Calculate CRC */
+                               qat_crc_generate(ctx, op);
+                       }
+#else
+                       RTE_SET_USED(is_docsis_sec);
+#endif
+
+                       /* Only send complete blocks to device.
                         * Process any partial block using CFB mode.
                         * Even if 0 complete blocks, still send this to device
                         * to get into rx queue for post-process and dequeuing