crypto/qat: rework request builder for performance
[dpdk.git] / drivers / crypto / qat / qat_adf / qat_algs_build_desc.c
index 198b551..8900668 100644 (file)
@@ -454,7 +454,7 @@ int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cdesc,
        struct icp_qat_fw_auth_cd_ctrl_hdr *hash_cd_ctrl = ptr;
        enum icp_qat_hw_cipher_convert key_convert;
        uint32_t total_key_size;
-       uint16_t proto = ICP_QAT_FW_LA_NO_PROTO;        /* no CCM/GCM/Snow3G */
+       uint16_t proto = ICP_QAT_FW_LA_NO_PROTO;        /* no CCM/GCM/SNOW 3G */
        uint16_t cipher_offset, cd_size;
        uint32_t wordIndex  = 0;
        uint32_t *temp_key = NULL;
@@ -512,6 +512,10 @@ int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cdesc,
                cipher_cd_ctrl->cipher_state_sz = ICP_QAT_HW_KASUMI_BLK_SZ >> 3;
                cipher_cd_ctrl->cipher_padding_sz =
                                        (2 * ICP_QAT_HW_KASUMI_BLK_SZ) >> 3;
+       } else if (cdesc->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES) {
+               total_key_size = ICP_QAT_HW_3DES_KEY_SZ;
+               cipher_cd_ctrl->cipher_state_sz = ICP_QAT_HW_3DES_BLK_SZ >> 3;
+               proto = ICP_QAT_FW_LA_PROTO_GET(header->serv_specif_flags);
        } else {
                total_key_size = cipherkeylen;
                cipher_cd_ctrl->cipher_state_sz = ICP_QAT_HW_AES_BLK_SZ >> 3;
@@ -525,7 +529,8 @@ int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cdesc,
        qat_alg_init_common_hdr(header, proto);
 
        cipher = (struct icp_qat_hw_cipher_algo_blk *)cdesc->cd_cur_ptr;
-       cipher->aes.cipher_config.val =
+
+       cipher->cipher_config.val =
            ICP_QAT_HW_CIPHER_CONFIG_BUILD(cdesc->qat_mode,
                                        cdesc->qat_cipher_alg, key_convert,
                                        cdesc->qat_dir);
@@ -534,7 +539,7 @@ int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cdesc,
                temp_key = (uint32_t *)(cdesc->cd_cur_ptr +
                                        sizeof(struct icp_qat_hw_cipher_config)
                                        + cipherkeylen);
-               memcpy(cipher->aes.key, cipherkey, cipherkeylen);
+               memcpy(cipher->key, cipherkey, cipherkeylen);
                memcpy(temp_key, cipherkey, cipherkeylen);
 
                /* XOR Key with KASUMI F8 key modifier at 4 bytes level */
@@ -545,15 +550,19 @@ int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cdesc,
                cdesc->cd_cur_ptr += sizeof(struct icp_qat_hw_cipher_config) +
                                        cipherkeylen + cipherkeylen;
        } else {
-               memcpy(cipher->aes.key, cipherkey, cipherkeylen);
+               memcpy(cipher->key, cipherkey, cipherkeylen);
                cdesc->cd_cur_ptr += sizeof(struct icp_qat_hw_cipher_config) +
                                        cipherkeylen;
        }
 
        if (total_key_size > cipherkeylen) {
                uint32_t padding_size =  total_key_size-cipherkeylen;
-
-               memset(cdesc->cd_cur_ptr, 0, padding_size);
+               if ((cdesc->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES)
+                       && (cipherkeylen == QAT_3DES_KEY_SZ_OPT2))
+                       /* K3 not provided so use K1 = K3*/
+                       memcpy(cdesc->cd_cur_ptr, cipherkey, padding_size);
+               else
+                       memset(cdesc->cd_cur_ptr, 0, padding_size);
                cdesc->cd_cur_ptr += padding_size;
        }
        cd_size = cdesc->cd_cur_ptr-(uint8_t *)&cdesc->cd;
@@ -581,7 +590,7 @@ int qat_alg_aead_session_create_content_desc_auth(struct qat_session *cdesc,
                (struct icp_qat_fw_la_auth_req_params *)
                ((char *)&req_tmpl->serv_specif_rqpars +
                sizeof(struct icp_qat_fw_la_cipher_req_params));
-       uint16_t proto = ICP_QAT_FW_LA_NO_PROTO;        /* no CCM/GCM/Snow3G */
+       uint16_t proto = ICP_QAT_FW_LA_NO_PROTO;        /* no CCM/GCM/SNOW 3G */
        uint16_t state1_size = 0, state2_size = 0;
        uint16_t hash_offset, cd_size;
        uint32_t *aad_len = NULL;
@@ -616,11 +625,13 @@ int qat_alg_aead_session_create_content_desc_auth(struct qat_session *cdesc,
                                ICP_QAT_FW_LA_NO_RET_AUTH_RES);
                ICP_QAT_FW_LA_CMP_AUTH_SET(header->serv_specif_flags,
                                ICP_QAT_FW_LA_CMP_AUTH_RES);
+               cdesc->auth_op = ICP_QAT_HW_AUTH_VERIFY;
        } else {
                ICP_QAT_FW_LA_RET_AUTH_SET(header->serv_specif_flags,
                                           ICP_QAT_FW_LA_RET_AUTH_RES);
                ICP_QAT_FW_LA_CMP_AUTH_SET(header->serv_specif_flags,
                                           ICP_QAT_FW_LA_NO_CMP_AUTH_RES);
+               cdesc->auth_op = ICP_QAT_HW_AUTH_GENERATE;
        }
 
        /*
@@ -727,13 +738,13 @@ int qat_alg_aead_session_create_content_desc_auth(struct qat_session *cdesc,
 
                cipherconfig = (struct icp_qat_hw_cipher_algo_blk *)
                                (cdesc->cd_cur_ptr + state1_size + state2_size);
-               cipherconfig->aes.cipher_config.val =
+               cipherconfig->cipher_config.val =
                ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_ECB_MODE,
                        ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2,
                        ICP_QAT_HW_CIPHER_KEY_CONVERT,
                        ICP_QAT_HW_CIPHER_ENCRYPT);
-               memcpy(cipherconfig->aes.key, authkey, authkeylen);
-               memset(cipherconfig->aes.key + authkeylen,
+               memcpy(cipherconfig->key, authkey, authkeylen);
+               memset(cipherconfig->key + authkeylen,
                                0, ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ);
                cdesc->cd_cur_ptr += sizeof(struct icp_qat_hw_cipher_config) +
                                authkeylen + ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ;
@@ -803,56 +814,6 @@ int qat_alg_aead_session_create_content_desc_auth(struct qat_session *cdesc,
        return 0;
 }
 
-static void qat_alg_ablkcipher_init_com(struct icp_qat_fw_la_bulk_req *req,
-                                       struct icp_qat_hw_cipher_algo_blk *cd,
-                                       const uint8_t *key, unsigned int keylen)
-{
-       struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars;
-       struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr;
-       struct icp_qat_fw_cipher_cd_ctrl_hdr *cd_ctrl = (void *)&req->cd_ctrl;
-
-       PMD_INIT_FUNC_TRACE();
-       rte_memcpy(cd->aes.key, key, keylen);
-       qat_alg_init_common_hdr(header, ICP_QAT_FW_LA_NO_PROTO);
-       header->service_cmd_id = ICP_QAT_FW_LA_CMD_CIPHER;
-       cd_pars->u.s.content_desc_params_sz =
-                               sizeof(struct icp_qat_hw_cipher_algo_blk) >> 3;
-       /* Cipher CD config setup */
-       cd_ctrl->cipher_key_sz = keylen >> 3;
-       cd_ctrl->cipher_state_sz = ICP_QAT_HW_AES_BLK_SZ >> 3;
-       cd_ctrl->cipher_cfg_offset = 0;
-       ICP_QAT_FW_COMN_CURR_ID_SET(cd_ctrl, ICP_QAT_FW_SLICE_CIPHER);
-       ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl, ICP_QAT_FW_SLICE_DRAM_WR);
-}
-
-void qat_alg_ablkcipher_init_enc(struct qat_alg_ablkcipher_cd *cdesc,
-                                       int alg, const uint8_t *key,
-                                       unsigned int keylen)
-{
-       struct icp_qat_hw_cipher_algo_blk *enc_cd = cdesc->cd;
-       struct icp_qat_fw_la_bulk_req *req = &cdesc->fw_req;
-       struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars;
-
-       PMD_INIT_FUNC_TRACE();
-       qat_alg_ablkcipher_init_com(req, enc_cd, key, keylen);
-       cd_pars->u.s.content_desc_addr = cdesc->cd_paddr;
-       enc_cd->aes.cipher_config.val = QAT_AES_HW_CONFIG_CBC_ENC(alg);
-}
-
-void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_cd *cdesc,
-                                       int alg, const uint8_t *key,
-                                       unsigned int keylen)
-{
-       struct icp_qat_hw_cipher_algo_blk *dec_cd = cdesc->cd;
-       struct icp_qat_fw_la_bulk_req *req = &cdesc->fw_req;
-       struct icp_qat_fw_comn_req_hdr_cd_pars *cd_pars = &req->cd_pars;
-
-       PMD_INIT_FUNC_TRACE();
-       qat_alg_ablkcipher_init_com(req, dec_cd, key, keylen);
-       cd_pars->u.s.content_desc_addr = cdesc->cd_paddr;
-       dec_cd->aes.cipher_config.val = QAT_AES_HW_CONFIG_CBC_DEC(alg);
-}
-
 int qat_alg_validate_aes_key(int key_len, enum icp_qat_hw_cipher_algo *alg)
 {
        switch (key_len) {
@@ -894,3 +855,16 @@ int qat_alg_validate_kasumi_key(int key_len, enum icp_qat_hw_cipher_algo *alg)
        }
        return 0;
 }
+
+int qat_alg_validate_3des_key(int key_len, enum icp_qat_hw_cipher_algo *alg)
+{
+       switch (key_len) {
+       case QAT_3DES_KEY_SZ_OPT1:
+       case QAT_3DES_KEY_SZ_OPT2:
+               *alg = ICP_QAT_HW_CIPHER_ALGO_3DES;
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}