1bfe2ae49SAnoob Joseph /* SPDX-License-Identifier: BSD-3-Clause 2bfe2ae49SAnoob Joseph * Copyright(c) 2018 Cavium, Inc 3bfe2ae49SAnoob Joseph */ 4bfe2ae49SAnoob Joseph 50dc1cffaSAnkur Dwivedi #include <rte_alarm.h> 60dc1cffaSAnkur Dwivedi #include <rte_bus_pci.h> 7bfe2ae49SAnoob Joseph #include <rte_cryptodev.h> 8af668035SAkhil Goyal #include <cryptodev_pmd.h> 944a2cebbSShijith Thotton #include <rte_eventdev.h> 1044a2cebbSShijith Thotton #include <rte_event_crypto_adapter.h> 11ec54bc9dSAnoob Joseph #include <rte_errno.h> 120dc1cffaSAnkur Dwivedi #include <rte_malloc.h> 13ec54bc9dSAnoob Joseph #include <rte_mempool.h> 140dc1cffaSAnkur Dwivedi 15bfe2ae49SAnoob Joseph #include "otx_cryptodev.h" 160906b99fSMurthy NSSR #include "otx_cryptodev_capabilities.h" 170dc1cffaSAnkur Dwivedi #include "otx_cryptodev_hw_access.h" 1813d711f3SKanaka Durga Kotamarthy #include "otx_cryptodev_mbox.h" 19bfe2ae49SAnoob Joseph #include "otx_cryptodev_ops.h" 20bfe2ae49SAnoob Joseph 2198c7b9c9SAnoob Joseph #include "cpt_pmd_logs.h" 22aa2cbd32SSunila Sahu #include "cpt_pmd_ops_helper.h" 2398c7b9c9SAnoob Joseph #include "cpt_ucode.h" 2433bcaae5SKanaka Durga Kotamarthy #include "cpt_ucode_asym.h" 2598c7b9c9SAnoob Joseph 2644a2cebbSShijith Thotton #include "ssovf_worker.h" 2744a2cebbSShijith Thotton 28aa2cbd32SSunila Sahu static uint64_t otx_fpm_iova[CPT_EC_ID_PMAX]; 29aa2cbd32SSunila Sahu 300961348fSMurthy NSSR /* Forward declarations */ 310961348fSMurthy NSSR 320961348fSMurthy NSSR static int 330961348fSMurthy NSSR otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id); 340961348fSMurthy NSSR 350dc1cffaSAnkur Dwivedi /* Alarm routines */ 360dc1cffaSAnkur Dwivedi 370dc1cffaSAnkur Dwivedi static void 380dc1cffaSAnkur Dwivedi otx_cpt_alarm_cb(void *arg) 390dc1cffaSAnkur Dwivedi { 400dc1cffaSAnkur Dwivedi struct cpt_vf *cptvf = arg; 410dc1cffaSAnkur Dwivedi otx_cpt_poll_misc(cptvf); 420dc1cffaSAnkur Dwivedi rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000, 430dc1cffaSAnkur Dwivedi otx_cpt_alarm_cb, cptvf); 440dc1cffaSAnkur Dwivedi } 450dc1cffaSAnkur Dwivedi 460dc1cffaSAnkur Dwivedi static int 470dc1cffaSAnkur Dwivedi otx_cpt_periodic_alarm_start(void *arg) 480dc1cffaSAnkur Dwivedi { 490dc1cffaSAnkur Dwivedi return rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000, 500dc1cffaSAnkur Dwivedi otx_cpt_alarm_cb, arg); 510dc1cffaSAnkur Dwivedi } 520dc1cffaSAnkur Dwivedi 53273487f7SAnoob Joseph static int 54273487f7SAnoob Joseph otx_cpt_periodic_alarm_stop(void *arg) 55273487f7SAnoob Joseph { 56273487f7SAnoob Joseph return rte_eal_alarm_cancel(otx_cpt_alarm_cb, arg); 57273487f7SAnoob Joseph } 58273487f7SAnoob Joseph 590906b99fSMurthy NSSR /* PMD ops */ 600906b99fSMurthy NSSR 610906b99fSMurthy NSSR static int 62aa2cbd32SSunila Sahu otx_cpt_dev_config(struct rte_cryptodev *dev, 630906b99fSMurthy NSSR struct rte_cryptodev_config *config __rte_unused) 640906b99fSMurthy NSSR { 65aa2cbd32SSunila Sahu int ret = 0; 66aa2cbd32SSunila Sahu 670906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 68aa2cbd32SSunila Sahu 69aa2cbd32SSunila Sahu if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) 70aa2cbd32SSunila Sahu /* Initialize shared FPM table */ 71aa2cbd32SSunila Sahu ret = cpt_fpm_init(otx_fpm_iova); 72aa2cbd32SSunila Sahu 73aa2cbd32SSunila Sahu return ret; 740906b99fSMurthy NSSR } 750906b99fSMurthy NSSR 760906b99fSMurthy NSSR static int 770906b99fSMurthy NSSR otx_cpt_dev_start(struct rte_cryptodev *c_dev) 780906b99fSMurthy NSSR { 790906b99fSMurthy NSSR void *cptvf = c_dev->data->dev_private; 800906b99fSMurthy NSSR 810906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 820906b99fSMurthy NSSR 830906b99fSMurthy NSSR return otx_cpt_start_device(cptvf); 840906b99fSMurthy NSSR } 850906b99fSMurthy NSSR 860906b99fSMurthy NSSR static void 870906b99fSMurthy NSSR otx_cpt_dev_stop(struct rte_cryptodev *c_dev) 880906b99fSMurthy NSSR { 890906b99fSMurthy NSSR void *cptvf = c_dev->data->dev_private; 900906b99fSMurthy NSSR 910906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 920906b99fSMurthy NSSR 93aa2cbd32SSunila Sahu if (c_dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) 94aa2cbd32SSunila Sahu cpt_fpm_clear(); 95aa2cbd32SSunila Sahu 960906b99fSMurthy NSSR otx_cpt_stop_device(cptvf); 970906b99fSMurthy NSSR } 980906b99fSMurthy NSSR 990906b99fSMurthy NSSR static int 1000906b99fSMurthy NSSR otx_cpt_dev_close(struct rte_cryptodev *c_dev) 1010906b99fSMurthy NSSR { 1020906b99fSMurthy NSSR void *cptvf = c_dev->data->dev_private; 1030961348fSMurthy NSSR int i, ret; 1040906b99fSMurthy NSSR 1050906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1060906b99fSMurthy NSSR 1070961348fSMurthy NSSR for (i = 0; i < c_dev->data->nb_queue_pairs; i++) { 1080961348fSMurthy NSSR ret = otx_cpt_que_pair_release(c_dev, i); 1090961348fSMurthy NSSR if (ret) 1100961348fSMurthy NSSR return ret; 1110961348fSMurthy NSSR } 1120961348fSMurthy NSSR 1130906b99fSMurthy NSSR otx_cpt_periodic_alarm_stop(cptvf); 1140906b99fSMurthy NSSR otx_cpt_deinit_device(cptvf); 1150906b99fSMurthy NSSR 1160906b99fSMurthy NSSR return 0; 1170906b99fSMurthy NSSR } 1180906b99fSMurthy NSSR 1190906b99fSMurthy NSSR static void 1200906b99fSMurthy NSSR otx_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info) 1210906b99fSMurthy NSSR { 1220906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1230906b99fSMurthy NSSR if (info != NULL) { 1240906b99fSMurthy NSSR info->max_nb_queue_pairs = CPT_NUM_QS_PER_VF; 1250906b99fSMurthy NSSR info->feature_flags = dev->feature_flags; 12633bcaae5SKanaka Durga Kotamarthy info->capabilities = otx_get_capabilities(info->feature_flags); 1270906b99fSMurthy NSSR info->sym.max_nb_sessions = 0; 1280906b99fSMurthy NSSR info->driver_id = otx_cryptodev_driver_id; 1290906b99fSMurthy NSSR info->min_mbuf_headroom_req = OTX_CPT_MIN_HEADROOM_REQ; 1300906b99fSMurthy NSSR info->min_mbuf_tailroom_req = OTX_CPT_MIN_TAILROOM_REQ; 1310906b99fSMurthy NSSR } 1320906b99fSMurthy NSSR } 1330906b99fSMurthy NSSR 1340961348fSMurthy NSSR static int 1350961348fSMurthy NSSR otx_cpt_que_pair_setup(struct rte_cryptodev *dev, 1360961348fSMurthy NSSR uint16_t que_pair_id, 1370961348fSMurthy NSSR const struct rte_cryptodev_qp_conf *qp_conf, 138725d2a7fSFan Zhang int socket_id __rte_unused) 1390961348fSMurthy NSSR { 1400961348fSMurthy NSSR struct cpt_instance *instance = NULL; 1410961348fSMurthy NSSR struct rte_pci_device *pci_dev; 1420961348fSMurthy NSSR int ret = -1; 1430961348fSMurthy NSSR 1440961348fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1450961348fSMurthy NSSR 1460961348fSMurthy NSSR if (dev->data->queue_pairs[que_pair_id] != NULL) { 1470961348fSMurthy NSSR ret = otx_cpt_que_pair_release(dev, que_pair_id); 1480961348fSMurthy NSSR if (ret) 1490961348fSMurthy NSSR return ret; 1500961348fSMurthy NSSR } 1510961348fSMurthy NSSR 1520961348fSMurthy NSSR if (qp_conf->nb_descriptors > DEFAULT_CMD_QLEN) { 1530961348fSMurthy NSSR CPT_LOG_INFO("Number of descriptors too big %d, using default " 1540961348fSMurthy NSSR "queue length of %d", qp_conf->nb_descriptors, 1550961348fSMurthy NSSR DEFAULT_CMD_QLEN); 1560961348fSMurthy NSSR } 1570961348fSMurthy NSSR 1580961348fSMurthy NSSR pci_dev = RTE_DEV_TO_PCI(dev->device); 1590961348fSMurthy NSSR 1600961348fSMurthy NSSR if (pci_dev->mem_resource[0].addr == NULL) { 1610961348fSMurthy NSSR CPT_LOG_ERR("PCI mem address null"); 1620961348fSMurthy NSSR return -EIO; 1630961348fSMurthy NSSR } 1640961348fSMurthy NSSR 165ec54bc9dSAnoob Joseph ret = otx_cpt_get_resource(dev, 0, &instance, que_pair_id); 166accf8ca7SAnoob Joseph if (ret != 0 || instance == NULL) { 1670961348fSMurthy NSSR CPT_LOG_ERR("Error getting instance handle from device %s : " 1680961348fSMurthy NSSR "ret = %d", dev->data->name, ret); 1690961348fSMurthy NSSR return ret; 1700961348fSMurthy NSSR } 1710961348fSMurthy NSSR 1720961348fSMurthy NSSR instance->queue_id = que_pair_id; 173f194f198SAnoob Joseph instance->sess_mp = qp_conf->mp_session; 174f194f198SAnoob Joseph instance->sess_mp_priv = qp_conf->mp_session_private; 1750961348fSMurthy NSSR dev->data->queue_pairs[que_pair_id] = instance; 1760961348fSMurthy NSSR 1770961348fSMurthy NSSR return 0; 1780961348fSMurthy NSSR } 1790961348fSMurthy NSSR 1800961348fSMurthy NSSR static int 1810961348fSMurthy NSSR otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id) 1820961348fSMurthy NSSR { 1830961348fSMurthy NSSR struct cpt_instance *instance = dev->data->queue_pairs[que_pair_id]; 1840961348fSMurthy NSSR int ret; 1850961348fSMurthy NSSR 1860961348fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1870961348fSMurthy NSSR 1880961348fSMurthy NSSR ret = otx_cpt_put_resource(instance); 1890961348fSMurthy NSSR if (ret != 0) { 1900961348fSMurthy NSSR CPT_LOG_ERR("Error putting instance handle of device %s : " 1910961348fSMurthy NSSR "ret = %d", dev->data->name, ret); 1920961348fSMurthy NSSR return ret; 1930961348fSMurthy NSSR } 1940961348fSMurthy NSSR 1950961348fSMurthy NSSR dev->data->queue_pairs[que_pair_id] = NULL; 1960961348fSMurthy NSSR 1970961348fSMurthy NSSR return 0; 1980961348fSMurthy NSSR } 1990961348fSMurthy NSSR 20043d01767SNithin Dabilpuram static unsigned int 20143d01767SNithin Dabilpuram otx_cpt_get_session_size(struct rte_cryptodev *dev __rte_unused) 20243d01767SNithin Dabilpuram { 20343d01767SNithin Dabilpuram return cpt_get_session_size(); 20443d01767SNithin Dabilpuram } 20543d01767SNithin Dabilpuram 206caeba506SAnoob Joseph static int 207caeba506SAnoob Joseph sym_xform_verify(struct rte_crypto_sym_xform *xform) 20843d01767SNithin Dabilpuram { 209caeba506SAnoob Joseph if (xform->next) { 210caeba506SAnoob Joseph if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && 211caeba506SAnoob Joseph xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER && 212de5eb0a6STejasree Kondoj xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT && 213de5eb0a6STejasree Kondoj (xform->auth.algo != RTE_CRYPTO_AUTH_SHA1_HMAC || 214de5eb0a6STejasree Kondoj xform->next->cipher.algo != RTE_CRYPTO_CIPHER_AES_CBC)) 215caeba506SAnoob Joseph return -ENOTSUP; 21643d01767SNithin Dabilpuram 217caeba506SAnoob Joseph if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && 218caeba506SAnoob Joseph xform->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT && 219de5eb0a6STejasree Kondoj xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH && 220de5eb0a6STejasree Kondoj (xform->cipher.algo != RTE_CRYPTO_CIPHER_AES_CBC || 221de5eb0a6STejasree Kondoj xform->next->auth.algo != RTE_CRYPTO_AUTH_SHA1_HMAC)) 222caeba506SAnoob Joseph return -ENOTSUP; 223caeba506SAnoob Joseph 224caeba506SAnoob Joseph if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && 225caeba506SAnoob Joseph xform->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC && 226caeba506SAnoob Joseph xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH && 227caeba506SAnoob Joseph xform->next->auth.algo == RTE_CRYPTO_AUTH_SHA1) 228caeba506SAnoob Joseph return -ENOTSUP; 229caeba506SAnoob Joseph 230caeba506SAnoob Joseph if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && 231caeba506SAnoob Joseph xform->auth.algo == RTE_CRYPTO_AUTH_SHA1 && 232caeba506SAnoob Joseph xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER && 233caeba506SAnoob Joseph xform->next->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC) 234caeba506SAnoob Joseph return -ENOTSUP; 235caeba506SAnoob Joseph 236caeba506SAnoob Joseph } else { 237caeba506SAnoob Joseph if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH && 238caeba506SAnoob Joseph xform->auth.algo == RTE_CRYPTO_AUTH_NULL && 239caeba506SAnoob Joseph xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) 240caeba506SAnoob Joseph return -ENOTSUP; 241caeba506SAnoob Joseph } 242caeba506SAnoob Joseph return 0; 243caeba506SAnoob Joseph } 244caeba506SAnoob Joseph 245caeba506SAnoob Joseph static int 246caeba506SAnoob Joseph sym_session_configure(int driver_id, struct rte_crypto_sym_xform *xform, 247caeba506SAnoob Joseph struct rte_cryptodev_sym_session *sess, 248caeba506SAnoob Joseph struct rte_mempool *pool) 249caeba506SAnoob Joseph { 2507293bae1SArchana Muniganti struct rte_crypto_sym_xform *temp_xform = xform; 251caeba506SAnoob Joseph struct cpt_sess_misc *misc; 2526045c06aSArchana Muniganti vq_cmd_word3_t vq_cmd_w3; 253caeba506SAnoob Joseph void *priv; 254caeba506SAnoob Joseph int ret; 255caeba506SAnoob Joseph 256caeba506SAnoob Joseph ret = sym_xform_verify(xform); 257caeba506SAnoob Joseph if (unlikely(ret)) 258caeba506SAnoob Joseph return ret; 259caeba506SAnoob Joseph 260caeba506SAnoob Joseph if (unlikely(rte_mempool_get(pool, &priv))) { 261caeba506SAnoob Joseph CPT_LOG_ERR("Could not allocate session private data"); 262caeba506SAnoob Joseph return -ENOMEM; 263caeba506SAnoob Joseph } 264caeba506SAnoob Joseph 2650b345f41SAnkur Dwivedi memset(priv, 0, sizeof(struct cpt_sess_misc) + 2666045c06aSArchana Muniganti offsetof(struct cpt_ctx, mc_ctx)); 2670b345f41SAnkur Dwivedi 268caeba506SAnoob Joseph misc = priv; 269caeba506SAnoob Joseph 270caeba506SAnoob Joseph for ( ; xform != NULL; xform = xform->next) { 271caeba506SAnoob Joseph switch (xform->type) { 272caeba506SAnoob Joseph case RTE_CRYPTO_SYM_XFORM_AEAD: 273caeba506SAnoob Joseph ret = fill_sess_aead(xform, misc); 274caeba506SAnoob Joseph break; 275caeba506SAnoob Joseph case RTE_CRYPTO_SYM_XFORM_CIPHER: 276caeba506SAnoob Joseph ret = fill_sess_cipher(xform, misc); 277caeba506SAnoob Joseph break; 278caeba506SAnoob Joseph case RTE_CRYPTO_SYM_XFORM_AUTH: 279caeba506SAnoob Joseph if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) 280caeba506SAnoob Joseph ret = fill_sess_gmac(xform, misc); 281caeba506SAnoob Joseph else 282caeba506SAnoob Joseph ret = fill_sess_auth(xform, misc); 283caeba506SAnoob Joseph break; 284caeba506SAnoob Joseph default: 285caeba506SAnoob Joseph ret = -1; 286caeba506SAnoob Joseph } 287caeba506SAnoob Joseph 288caeba506SAnoob Joseph if (ret) 289caeba506SAnoob Joseph goto priv_put; 290caeba506SAnoob Joseph } 291caeba506SAnoob Joseph 2927293bae1SArchana Muniganti if ((GET_SESS_FC_TYPE(misc) == HASH_HMAC) && 2937293bae1SArchana Muniganti cpt_mac_len_verify(&temp_xform->auth)) { 2947293bae1SArchana Muniganti CPT_LOG_ERR("MAC length is not supported"); 295db06451bSAnoob Joseph struct cpt_ctx *ctx = SESS_PRIV(misc); 296db06451bSAnoob Joseph if (ctx->auth_key != NULL) { 297db06451bSAnoob Joseph rte_free(ctx->auth_key); 298db06451bSAnoob Joseph ctx->auth_key = NULL; 299db06451bSAnoob Joseph } 3007293bae1SArchana Muniganti ret = -ENOTSUP; 3017293bae1SArchana Muniganti goto priv_put; 3027293bae1SArchana Muniganti } 3037293bae1SArchana Muniganti 304caeba506SAnoob Joseph set_sym_session_private_data(sess, driver_id, priv); 305caeba506SAnoob Joseph 306caeba506SAnoob Joseph misc->ctx_dma_addr = rte_mempool_virt2iova(misc) + 30743d01767SNithin Dabilpuram sizeof(struct cpt_sess_misc); 308caeba506SAnoob Joseph 3096045c06aSArchana Muniganti vq_cmd_w3.u64 = 0; 3106045c06aSArchana Muniganti vq_cmd_w3.s.grp = 0; 3116045c06aSArchana Muniganti vq_cmd_w3.s.cptr = misc->ctx_dma_addr + offsetof(struct cpt_ctx, 3126045c06aSArchana Muniganti mc_ctx); 3136045c06aSArchana Muniganti 3146045c06aSArchana Muniganti misc->cpt_inst_w7 = vq_cmd_w3.u64; 3156045c06aSArchana Muniganti 316caeba506SAnoob Joseph return 0; 317caeba506SAnoob Joseph 318caeba506SAnoob Joseph priv_put: 319caeba506SAnoob Joseph if (priv) 320caeba506SAnoob Joseph rte_mempool_put(pool, priv); 321caeba506SAnoob Joseph return -ENOTSUP; 322caeba506SAnoob Joseph } 323caeba506SAnoob Joseph 324caeba506SAnoob Joseph static void 325caeba506SAnoob Joseph sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess) 326caeba506SAnoob Joseph { 327caeba506SAnoob Joseph void *priv = get_sym_session_private_data(sess, driver_id); 328db06451bSAnoob Joseph struct cpt_sess_misc *misc; 329caeba506SAnoob Joseph struct rte_mempool *pool; 330db06451bSAnoob Joseph struct cpt_ctx *ctx; 331caeba506SAnoob Joseph 332caeba506SAnoob Joseph if (priv == NULL) 333caeba506SAnoob Joseph return; 334caeba506SAnoob Joseph 335db06451bSAnoob Joseph misc = priv; 336db06451bSAnoob Joseph ctx = SESS_PRIV(misc); 337db06451bSAnoob Joseph 338db06451bSAnoob Joseph rte_free(ctx->auth_key); 339db06451bSAnoob Joseph 340caeba506SAnoob Joseph memset(priv, 0, cpt_get_session_size()); 341caeba506SAnoob Joseph 342caeba506SAnoob Joseph pool = rte_mempool_from_obj(priv); 343caeba506SAnoob Joseph 344caeba506SAnoob Joseph set_sym_session_private_data(sess, driver_id, NULL); 345caeba506SAnoob Joseph 346caeba506SAnoob Joseph rte_mempool_put(pool, priv); 34743d01767SNithin Dabilpuram } 34843d01767SNithin Dabilpuram 34943d01767SNithin Dabilpuram static int 35043d01767SNithin Dabilpuram otx_cpt_session_cfg(struct rte_cryptodev *dev, 35143d01767SNithin Dabilpuram struct rte_crypto_sym_xform *xform, 35243d01767SNithin Dabilpuram struct rte_cryptodev_sym_session *sess, 353caeba506SAnoob Joseph struct rte_mempool *pool) 35443d01767SNithin Dabilpuram { 35543d01767SNithin Dabilpuram CPT_PMD_INIT_FUNC_TRACE(); 35643d01767SNithin Dabilpuram 357caeba506SAnoob Joseph return sym_session_configure(dev->driver_id, xform, sess, pool); 35843d01767SNithin Dabilpuram } 35943d01767SNithin Dabilpuram 36043d01767SNithin Dabilpuram 36143d01767SNithin Dabilpuram static void 36243d01767SNithin Dabilpuram otx_cpt_session_clear(struct rte_cryptodev *dev, 36343d01767SNithin Dabilpuram struct rte_cryptodev_sym_session *sess) 36443d01767SNithin Dabilpuram { 36543d01767SNithin Dabilpuram CPT_PMD_INIT_FUNC_TRACE(); 366caeba506SAnoob Joseph 367caeba506SAnoob Joseph return sym_session_clear(dev->driver_id, sess); 36843d01767SNithin Dabilpuram } 36943d01767SNithin Dabilpuram 37033bcaae5SKanaka Durga Kotamarthy static unsigned int 37133bcaae5SKanaka Durga Kotamarthy otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused) 37233bcaae5SKanaka Durga Kotamarthy { 37333bcaae5SKanaka Durga Kotamarthy return sizeof(struct cpt_asym_sess_misc); 37433bcaae5SKanaka Durga Kotamarthy } 37533bcaae5SKanaka Durga Kotamarthy 37633bcaae5SKanaka Durga Kotamarthy static int 3771f1e4b7cSCiara Power otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused, 37833bcaae5SKanaka Durga Kotamarthy struct rte_crypto_asym_xform *xform __rte_unused, 3791f1e4b7cSCiara Power struct rte_cryptodev_asym_session *sess) 38033bcaae5SKanaka Durga Kotamarthy { 3811f1e4b7cSCiara Power struct cpt_asym_sess_misc *priv = (struct cpt_asym_sess_misc *) 3821f1e4b7cSCiara Power sess->sess_private_data; 38333bcaae5SKanaka Durga Kotamarthy int ret; 38433bcaae5SKanaka Durga Kotamarthy 38533bcaae5SKanaka Durga Kotamarthy CPT_PMD_INIT_FUNC_TRACE(); 38633bcaae5SKanaka Durga Kotamarthy 38733bcaae5SKanaka Durga Kotamarthy ret = cpt_fill_asym_session_parameters(priv, xform); 38833bcaae5SKanaka Durga Kotamarthy if (ret) { 38933bcaae5SKanaka Durga Kotamarthy CPT_LOG_ERR("Could not configure session parameters"); 39033bcaae5SKanaka Durga Kotamarthy return ret; 39133bcaae5SKanaka Durga Kotamarthy } 39233bcaae5SKanaka Durga Kotamarthy 3936045c06aSArchana Muniganti priv->cpt_inst_w7 = 0; 3946045c06aSArchana Muniganti 39533bcaae5SKanaka Durga Kotamarthy return 0; 39633bcaae5SKanaka Durga Kotamarthy } 39733bcaae5SKanaka Durga Kotamarthy 39833bcaae5SKanaka Durga Kotamarthy static void 39933bcaae5SKanaka Durga Kotamarthy otx_cpt_asym_session_clear(struct rte_cryptodev *dev, 40033bcaae5SKanaka Durga Kotamarthy struct rte_cryptodev_asym_session *sess) 40133bcaae5SKanaka Durga Kotamarthy { 40233bcaae5SKanaka Durga Kotamarthy struct cpt_asym_sess_misc *priv; 40333bcaae5SKanaka Durga Kotamarthy 40433bcaae5SKanaka Durga Kotamarthy CPT_PMD_INIT_FUNC_TRACE(); 40533bcaae5SKanaka Durga Kotamarthy 4061f1e4b7cSCiara Power priv = (struct cpt_asym_sess_misc *) sess->sess_private_data; 40733bcaae5SKanaka Durga Kotamarthy 40833bcaae5SKanaka Durga Kotamarthy if (priv == NULL) 40933bcaae5SKanaka Durga Kotamarthy return; 41033bcaae5SKanaka Durga Kotamarthy 41133bcaae5SKanaka Durga Kotamarthy /* Free resources allocated during session configure */ 41233bcaae5SKanaka Durga Kotamarthy cpt_free_asym_session_parameters(priv); 41333bcaae5SKanaka Durga Kotamarthy memset(priv, 0, otx_cpt_asym_session_size_get(dev)); 41433bcaae5SKanaka Durga Kotamarthy } 41533bcaae5SKanaka Durga Kotamarthy 41644a2cebbSShijith Thotton static __rte_always_inline void * __rte_hot 417f194f198SAnoob Joseph otx_cpt_request_enqueue(struct cpt_instance *instance, 4186045c06aSArchana Muniganti void *req, uint64_t cpt_inst_w7) 419f194f198SAnoob Joseph { 420f194f198SAnoob Joseph struct cpt_request_info *user_req = (struct cpt_request_info *)req; 421f194f198SAnoob Joseph 4226045c06aSArchana Muniganti fill_cpt_inst(instance, req, cpt_inst_w7); 423f194f198SAnoob Joseph 424f194f198SAnoob Joseph CPT_LOG_DP_DEBUG("req: %p op: %p ", req, user_req->op); 425f194f198SAnoob Joseph 426f194f198SAnoob Joseph /* Fill time_out cycles */ 427f194f198SAnoob Joseph user_req->time_out = rte_get_timer_cycles() + 428f194f198SAnoob Joseph DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz(); 429f194f198SAnoob Joseph user_req->extra_time = 0; 430f194f198SAnoob Joseph 431f194f198SAnoob Joseph /* Default mode of software queue */ 432f194f198SAnoob Joseph mark_cpt_inst(instance); 433f194f198SAnoob Joseph 434f194f198SAnoob Joseph CPT_LOG_DP_DEBUG("Submitted NB cmd with request: %p " 435f194f198SAnoob Joseph "op: %p", user_req, user_req->op); 43644a2cebbSShijith Thotton return req; 437f194f198SAnoob Joseph } 438f194f198SAnoob Joseph 43944a2cebbSShijith Thotton static __rte_always_inline void * __rte_hot 440e9a356e2SSunila Sahu otx_cpt_enq_single_asym(struct cpt_instance *instance, 441c9902a15SDavid George struct rte_crypto_op *op) 442e9a356e2SSunila Sahu { 443e9a356e2SSunila Sahu struct cpt_qp_meta_info *minfo = &instance->meta_info; 444e9a356e2SSunila Sahu struct rte_crypto_asym_op *asym_op = op->asym; 445e9a356e2SSunila Sahu struct asym_op_params params = {0}; 446e9a356e2SSunila Sahu struct cpt_asym_sess_misc *sess; 447e9a356e2SSunila Sahu uintptr_t *cop; 448e9a356e2SSunila Sahu void *mdata; 44944a2cebbSShijith Thotton void *req; 450e9a356e2SSunila Sahu int ret; 451e9a356e2SSunila Sahu 452e9a356e2SSunila Sahu if (unlikely(rte_mempool_get(minfo->pool, &mdata) < 0)) { 453e9a356e2SSunila Sahu CPT_LOG_DP_ERR("Could not allocate meta buffer for request"); 45444a2cebbSShijith Thotton rte_errno = ENOMEM; 45544a2cebbSShijith Thotton return NULL; 456e9a356e2SSunila Sahu } 457e9a356e2SSunila Sahu 4581f1e4b7cSCiara Power sess = (struct cpt_asym_sess_misc *) 4591f1e4b7cSCiara Power asym_op->session->sess_private_data; 460e9a356e2SSunila Sahu 461e9a356e2SSunila Sahu /* Store phys_addr of the mdata to meta_buf */ 462e9a356e2SSunila Sahu params.meta_buf = rte_mempool_virt2iova(mdata); 463e9a356e2SSunila Sahu 464e9a356e2SSunila Sahu cop = mdata; 465e9a356e2SSunila Sahu cop[0] = (uintptr_t)mdata; 466e9a356e2SSunila Sahu cop[1] = (uintptr_t)op; 467e9a356e2SSunila Sahu cop[2] = cop[3] = 0ULL; 468e9a356e2SSunila Sahu 469e9a356e2SSunila Sahu params.req = RTE_PTR_ADD(cop, 4 * sizeof(uintptr_t)); 470e9a356e2SSunila Sahu params.req->op = cop; 471e9a356e2SSunila Sahu 472e9a356e2SSunila Sahu /* Adjust meta_buf by crypto_op data and request_info struct */ 473e9a356e2SSunila Sahu params.meta_buf += (4 * sizeof(uintptr_t)) + 474e9a356e2SSunila Sahu sizeof(struct cpt_request_info); 475e9a356e2SSunila Sahu 476e9a356e2SSunila Sahu switch (sess->xfrm_type) { 477e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_MODEX: 478e9a356e2SSunila Sahu ret = cpt_modex_prep(¶ms, &sess->mod_ctx); 479e9a356e2SSunila Sahu if (unlikely(ret)) 480e9a356e2SSunila Sahu goto req_fail; 481e9a356e2SSunila Sahu break; 482e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_RSA: 483e9a356e2SSunila Sahu ret = cpt_enqueue_rsa_op(op, ¶ms, sess); 484e9a356e2SSunila Sahu if (unlikely(ret)) 485e9a356e2SSunila Sahu goto req_fail; 486e9a356e2SSunila Sahu break; 487aa2cbd32SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_ECDSA: 488aa2cbd32SSunila Sahu ret = cpt_enqueue_ecdsa_op(op, ¶ms, sess, otx_fpm_iova); 489aa2cbd32SSunila Sahu if (unlikely(ret)) 490aa2cbd32SSunila Sahu goto req_fail; 491aa2cbd32SSunila Sahu break; 49299faef83SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_ECPM: 49399faef83SSunila Sahu ret = cpt_ecpm_prep(&asym_op->ecpm, ¶ms, 49499faef83SSunila Sahu sess->ec_ctx.curveid); 49599faef83SSunila Sahu if (unlikely(ret)) 49699faef83SSunila Sahu goto req_fail; 49799faef83SSunila Sahu break; 49899faef83SSunila Sahu 499e9a356e2SSunila Sahu default: 500e9a356e2SSunila Sahu op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; 50144a2cebbSShijith Thotton rte_errno = EINVAL; 502e9a356e2SSunila Sahu goto req_fail; 503e9a356e2SSunila Sahu } 504e9a356e2SSunila Sahu 505c9902a15SDavid George req = otx_cpt_request_enqueue(instance, params.req, sess->cpt_inst_w7); 50644a2cebbSShijith Thotton if (unlikely(req == NULL)) { 507e9a356e2SSunila Sahu CPT_LOG_DP_ERR("Could not enqueue crypto req"); 508e9a356e2SSunila Sahu goto req_fail; 509e9a356e2SSunila Sahu } 510e9a356e2SSunila Sahu 51144a2cebbSShijith Thotton return req; 512e9a356e2SSunila Sahu 513e9a356e2SSunila Sahu req_fail: 514e9a356e2SSunila Sahu free_op_meta(mdata, minfo->pool); 515e9a356e2SSunila Sahu 51644a2cebbSShijith Thotton return NULL; 517e9a356e2SSunila Sahu } 518e9a356e2SSunila Sahu 51944a2cebbSShijith Thotton static __rte_always_inline void * __rte_hot 520f194f198SAnoob Joseph otx_cpt_enq_single_sym(struct cpt_instance *instance, 521c9902a15SDavid George struct rte_crypto_op *op) 522f194f198SAnoob Joseph { 523f194f198SAnoob Joseph struct cpt_sess_misc *sess; 524f194f198SAnoob Joseph struct rte_crypto_sym_op *sym_op = op->sym; 5256045c06aSArchana Muniganti struct cpt_request_info *prep_req; 5266045c06aSArchana Muniganti void *mdata = NULL; 527f194f198SAnoob Joseph int ret = 0; 52844a2cebbSShijith Thotton void *req; 529f194f198SAnoob Joseph uint64_t cpt_op; 530f194f198SAnoob Joseph 531f194f198SAnoob Joseph sess = (struct cpt_sess_misc *) 532f194f198SAnoob Joseph get_sym_session_private_data(sym_op->session, 533f194f198SAnoob Joseph otx_cryptodev_driver_id); 534f194f198SAnoob Joseph 535f194f198SAnoob Joseph cpt_op = sess->cpt_op; 536f194f198SAnoob Joseph 537f194f198SAnoob Joseph if (likely(cpt_op & CPT_OP_CIPHER_MASK)) 538ec54bc9dSAnoob Joseph ret = fill_fc_params(op, sess, &instance->meta_info, &mdata, 5396045c06aSArchana Muniganti (void **)&prep_req); 540f194f198SAnoob Joseph else 541ec54bc9dSAnoob Joseph ret = fill_digest_params(op, sess, &instance->meta_info, 5426045c06aSArchana Muniganti &mdata, (void **)&prep_req); 543f194f198SAnoob Joseph 544f194f198SAnoob Joseph if (unlikely(ret)) { 5457be78d02SJosh Soref CPT_LOG_DP_ERR("prep crypto req : op %p, cpt_op 0x%x " 546f194f198SAnoob Joseph "ret 0x%x", op, (unsigned int)cpt_op, ret); 54744a2cebbSShijith Thotton return NULL; 548f194f198SAnoob Joseph } 549f194f198SAnoob Joseph 550f194f198SAnoob Joseph /* Enqueue prepared instruction to h/w */ 551c9902a15SDavid George req = otx_cpt_request_enqueue(instance, prep_req, sess->cpt_inst_w7); 55244a2cebbSShijith Thotton if (unlikely(req == NULL)) 553f194f198SAnoob Joseph /* Buffer allocated for request preparation need to be freed */ 554ec54bc9dSAnoob Joseph free_op_meta(mdata, instance->meta_info.pool); 55544a2cebbSShijith Thotton 55644a2cebbSShijith Thotton return req; 557f194f198SAnoob Joseph } 558f194f198SAnoob Joseph 55944a2cebbSShijith Thotton static __rte_always_inline void * __rte_hot 560f194f198SAnoob Joseph otx_cpt_enq_single_sym_sessless(struct cpt_instance *instance, 561c9902a15SDavid George struct rte_crypto_op *op) 562f194f198SAnoob Joseph { 563caeba506SAnoob Joseph const int driver_id = otx_cryptodev_driver_id; 564f194f198SAnoob Joseph struct rte_crypto_sym_op *sym_op = op->sym; 565caeba506SAnoob Joseph struct rte_cryptodev_sym_session *sess; 56644a2cebbSShijith Thotton void *req; 567f194f198SAnoob Joseph int ret; 568f194f198SAnoob Joseph 569caeba506SAnoob Joseph /* Create temporary session */ 5708e177f14SAnkur Dwivedi sess = rte_cryptodev_sym_session_create(instance->sess_mp); 57144a2cebbSShijith Thotton if (sess == NULL) { 57244a2cebbSShijith Thotton rte_errno = ENOMEM; 57344a2cebbSShijith Thotton return NULL; 57444a2cebbSShijith Thotton } 575f194f198SAnoob Joseph 576caeba506SAnoob Joseph ret = sym_session_configure(driver_id, sym_op->xform, sess, 577caeba506SAnoob Joseph instance->sess_mp_priv); 578caeba506SAnoob Joseph if (ret) 579caeba506SAnoob Joseph goto sess_put; 580f194f198SAnoob Joseph 581caeba506SAnoob Joseph sym_op->session = sess; 582f194f198SAnoob Joseph 583c9902a15SDavid George /* Enqueue op with the tmp session set */ 584c9902a15SDavid George req = otx_cpt_enq_single_sym(instance, op); 58544a2cebbSShijith Thotton if (unlikely(req == NULL)) 586caeba506SAnoob Joseph goto priv_put; 587f194f198SAnoob Joseph 58844a2cebbSShijith Thotton return req; 589f194f198SAnoob Joseph 590caeba506SAnoob Joseph priv_put: 591caeba506SAnoob Joseph sym_session_clear(driver_id, sess); 592caeba506SAnoob Joseph sess_put: 593caeba506SAnoob Joseph rte_mempool_put(instance->sess_mp, sess); 59444a2cebbSShijith Thotton return NULL; 595f194f198SAnoob Joseph } 596f194f198SAnoob Joseph 597e9a356e2SSunila Sahu #define OP_TYPE_SYM 0 598e9a356e2SSunila Sahu #define OP_TYPE_ASYM 1 599e9a356e2SSunila Sahu 60044a2cebbSShijith Thotton static __rte_always_inline void *__rte_hot 601f194f198SAnoob Joseph otx_cpt_enq_single(struct cpt_instance *inst, 602f194f198SAnoob Joseph struct rte_crypto_op *op, 603e9a356e2SSunila Sahu const uint8_t op_type) 604f194f198SAnoob Joseph { 605f194f198SAnoob Joseph /* Check for the type */ 606f194f198SAnoob Joseph 607e9a356e2SSunila Sahu if (op_type == OP_TYPE_SYM) { 608f194f198SAnoob Joseph if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) 609c9902a15SDavid George return otx_cpt_enq_single_sym(inst, op); 610e9a356e2SSunila Sahu else 611c9902a15SDavid George return otx_cpt_enq_single_sym_sessless(inst, op); 612f194f198SAnoob Joseph } 613f194f198SAnoob Joseph 614e9a356e2SSunila Sahu if (op_type == OP_TYPE_ASYM) { 615e9a356e2SSunila Sahu if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) 616c9902a15SDavid George return otx_cpt_enq_single_asym(inst, op); 617e9a356e2SSunila Sahu } 618e9a356e2SSunila Sahu 619e9a356e2SSunila Sahu /* Should not reach here */ 62044a2cebbSShijith Thotton rte_errno = ENOTSUP; 62144a2cebbSShijith Thotton return NULL; 622e9a356e2SSunila Sahu } 623e9a356e2SSunila Sahu 624e3866e73SThomas Monjalon static __rte_always_inline uint16_t __rte_hot 625e9a356e2SSunila Sahu otx_cpt_pkt_enqueue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops, 626e9a356e2SSunila Sahu const uint8_t op_type) 627ac4d88afSTejasree Kondoj { 628ac4d88afSTejasree Kondoj struct cpt_instance *instance = (struct cpt_instance *)qptr; 629c9902a15SDavid George uint16_t count, free_slots; 63044a2cebbSShijith Thotton void *req; 631ac4d88afSTejasree Kondoj struct cpt_vf *cptvf = (struct cpt_vf *)instance; 632ac4d88afSTejasree Kondoj struct pending_queue *pqueue = &cptvf->pqueue; 633ac4d88afSTejasree Kondoj 634c9902a15SDavid George free_slots = pending_queue_free_slots(pqueue, DEFAULT_CMD_QLEN, 635c9902a15SDavid George DEFAULT_CMD_QRSVD_SLOTS); 636c9902a15SDavid George if (nb_ops > free_slots) 637c9902a15SDavid George nb_ops = free_slots; 638ac4d88afSTejasree Kondoj 639ac4d88afSTejasree Kondoj count = 0; 640ac4d88afSTejasree Kondoj while (likely(count < nb_ops)) { 641f194f198SAnoob Joseph 642f194f198SAnoob Joseph /* Enqueue single op */ 643c9902a15SDavid George req = otx_cpt_enq_single(instance, ops[count], op_type); 644f194f198SAnoob Joseph 64544a2cebbSShijith Thotton if (unlikely(req == NULL)) 646ac4d88afSTejasree Kondoj break; 64744a2cebbSShijith Thotton 648c9902a15SDavid George pending_queue_push(pqueue, req, count, DEFAULT_CMD_QLEN); 649ac4d88afSTejasree Kondoj count++; 650ac4d88afSTejasree Kondoj } 651c9902a15SDavid George 652c9902a15SDavid George if (likely(count)) { 653c9902a15SDavid George pending_queue_commit(pqueue, count, DEFAULT_CMD_QLEN); 654ac4d88afSTejasree Kondoj otx_cpt_ring_dbell(instance, count); 655c9902a15SDavid George } 656ac4d88afSTejasree Kondoj return count; 657ac4d88afSTejasree Kondoj } 658ac4d88afSTejasree Kondoj 659e9a356e2SSunila Sahu static uint16_t 660e9a356e2SSunila Sahu otx_cpt_enqueue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops) 661e9a356e2SSunila Sahu { 662e9a356e2SSunila Sahu return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_ASYM); 663e9a356e2SSunila Sahu } 664e9a356e2SSunila Sahu 665e9a356e2SSunila Sahu static uint16_t 666e9a356e2SSunila Sahu otx_cpt_enqueue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops) 667e9a356e2SSunila Sahu { 668e9a356e2SSunila Sahu return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_SYM); 669e9a356e2SSunila Sahu } 670e9a356e2SSunila Sahu 67144a2cebbSShijith Thotton static __rte_always_inline void 67244a2cebbSShijith Thotton submit_request_to_sso(struct ssows *ws, uintptr_t req, 67344a2cebbSShijith Thotton struct rte_event *rsp_info) 67444a2cebbSShijith Thotton { 67544a2cebbSShijith Thotton uint64_t add_work; 67644a2cebbSShijith Thotton 67744a2cebbSShijith Thotton add_work = rsp_info->flow_id | (RTE_EVENT_TYPE_CRYPTODEV << 28) | 678*a662baa7SAnoob Joseph (rsp_info->sub_event_type << 20) | 67944a2cebbSShijith Thotton ((uint64_t)(rsp_info->sched_type) << 32); 68044a2cebbSShijith Thotton 68144a2cebbSShijith Thotton if (!rsp_info->sched_type) 68244a2cebbSShijith Thotton ssows_head_wait(ws); 68344a2cebbSShijith Thotton 68444a2cebbSShijith Thotton rte_atomic_thread_fence(__ATOMIC_RELEASE); 68544a2cebbSShijith Thotton ssovf_store_pair(add_work, req, ws->grps[rsp_info->queue_id]); 68644a2cebbSShijith Thotton } 68744a2cebbSShijith Thotton 68844a2cebbSShijith Thotton uint16_t __rte_hot 68944a2cebbSShijith Thotton otx_crypto_adapter_enqueue(void *port, struct rte_crypto_op *op) 69044a2cebbSShijith Thotton { 69144a2cebbSShijith Thotton union rte_event_crypto_metadata *ec_mdata; 69244a2cebbSShijith Thotton struct cpt_instance *instance; 69344a2cebbSShijith Thotton struct cpt_request_info *req; 69444a2cebbSShijith Thotton struct rte_event *rsp_info; 69544a2cebbSShijith Thotton uint8_t op_type, cdev_id; 69644a2cebbSShijith Thotton uint16_t qp_id; 69744a2cebbSShijith Thotton 698a974f7cbSAkhil Goyal ec_mdata = rte_cryptodev_session_event_mdata_get(op); 69944a2cebbSShijith Thotton if (unlikely(ec_mdata == NULL)) { 70044a2cebbSShijith Thotton rte_errno = EINVAL; 70144a2cebbSShijith Thotton return 0; 70244a2cebbSShijith Thotton } 70344a2cebbSShijith Thotton 70444a2cebbSShijith Thotton cdev_id = ec_mdata->request_info.cdev_id; 70544a2cebbSShijith Thotton qp_id = ec_mdata->request_info.queue_pair_id; 70644a2cebbSShijith Thotton rsp_info = &ec_mdata->response_info; 70744a2cebbSShijith Thotton instance = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id]; 70844a2cebbSShijith Thotton 70944a2cebbSShijith Thotton if (unlikely(!instance->ca_enabled)) { 71044a2cebbSShijith Thotton rte_errno = EINVAL; 71144a2cebbSShijith Thotton return 0; 71244a2cebbSShijith Thotton } 71344a2cebbSShijith Thotton 71444a2cebbSShijith Thotton op_type = op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC ? OP_TYPE_SYM : 71544a2cebbSShijith Thotton OP_TYPE_ASYM; 716c9902a15SDavid George req = otx_cpt_enq_single(instance, op, op_type); 71744a2cebbSShijith Thotton if (unlikely(req == NULL)) 71844a2cebbSShijith Thotton return 0; 71944a2cebbSShijith Thotton 72044a2cebbSShijith Thotton otx_cpt_ring_dbell(instance, 1); 72144a2cebbSShijith Thotton req->qp = instance; 72244a2cebbSShijith Thotton submit_request_to_sso(port, (uintptr_t)req, rsp_info); 72344a2cebbSShijith Thotton 72444a2cebbSShijith Thotton return 1; 72544a2cebbSShijith Thotton } 72644a2cebbSShijith Thotton 727e9a356e2SSunila Sahu static inline void 728e9a356e2SSunila Sahu otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req, 729e9a356e2SSunila Sahu struct rte_crypto_rsa_xform *rsa_ctx) 730e9a356e2SSunila Sahu 731e9a356e2SSunila Sahu { 732e9a356e2SSunila Sahu struct rte_crypto_rsa_op_param *rsa = &cop->asym->rsa; 733e9a356e2SSunila Sahu 734e9a356e2SSunila Sahu switch (rsa->op_type) { 735e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_OP_ENCRYPT: 736e9a356e2SSunila Sahu rsa->cipher.length = rsa_ctx->n.length; 737e9a356e2SSunila Sahu memcpy(rsa->cipher.data, req->rptr, rsa->cipher.length); 738e9a356e2SSunila Sahu break; 739e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_OP_DECRYPT: 740db8d2a2cSArek Kusztal if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) 741e9a356e2SSunila Sahu rsa->message.length = rsa_ctx->n.length; 742e9a356e2SSunila Sahu else { 743e9a356e2SSunila Sahu /* Get length of decrypted output */ 744e9a356e2SSunila Sahu rsa->message.length = rte_cpu_to_be_16 745e9a356e2SSunila Sahu (*((uint16_t *)req->rptr)); 746e9a356e2SSunila Sahu 747e9a356e2SSunila Sahu /* Offset data pointer by length fields */ 748e9a356e2SSunila Sahu req->rptr += 2; 749e9a356e2SSunila Sahu } 750e9a356e2SSunila Sahu memcpy(rsa->message.data, req->rptr, rsa->message.length); 751e9a356e2SSunila Sahu break; 752e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_OP_SIGN: 753e9a356e2SSunila Sahu rsa->sign.length = rsa_ctx->n.length; 754e9a356e2SSunila Sahu memcpy(rsa->sign.data, req->rptr, rsa->sign.length); 755e9a356e2SSunila Sahu break; 756e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_OP_VERIFY: 757db8d2a2cSArek Kusztal if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) 758e9a356e2SSunila Sahu rsa->sign.length = rsa_ctx->n.length; 759e9a356e2SSunila Sahu else { 760e9a356e2SSunila Sahu /* Get length of decrypted output */ 761e9a356e2SSunila Sahu rsa->sign.length = rte_cpu_to_be_16 762e9a356e2SSunila Sahu (*((uint16_t *)req->rptr)); 763e9a356e2SSunila Sahu 764e9a356e2SSunila Sahu /* Offset data pointer by length fields */ 765e9a356e2SSunila Sahu req->rptr += 2; 766e9a356e2SSunila Sahu } 767e9a356e2SSunila Sahu memcpy(rsa->sign.data, req->rptr, rsa->sign.length); 768e9a356e2SSunila Sahu 769e9a356e2SSunila Sahu if (memcmp(rsa->sign.data, rsa->message.data, 770e9a356e2SSunila Sahu rsa->message.length)) { 771e9a356e2SSunila Sahu CPT_LOG_DP_ERR("RSA verification failed"); 772e9a356e2SSunila Sahu cop->status = RTE_CRYPTO_OP_STATUS_ERROR; 773e9a356e2SSunila Sahu } 774e9a356e2SSunila Sahu break; 775e9a356e2SSunila Sahu default: 776e9a356e2SSunila Sahu CPT_LOG_DP_DEBUG("Invalid RSA operation type"); 777e9a356e2SSunila Sahu cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; 778e9a356e2SSunila Sahu break; 779e9a356e2SSunila Sahu } 780e9a356e2SSunila Sahu } 781e9a356e2SSunila Sahu 782aa2cbd32SSunila Sahu static __rte_always_inline void 783aa2cbd32SSunila Sahu otx_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa, 784aa2cbd32SSunila Sahu struct cpt_request_info *req, 785aa2cbd32SSunila Sahu struct cpt_asym_ec_ctx *ec) 786aa2cbd32SSunila Sahu 787aa2cbd32SSunila Sahu { 788aa2cbd32SSunila Sahu int prime_len = ec_grp[ec->curveid].prime.length; 789aa2cbd32SSunila Sahu 790aa2cbd32SSunila Sahu if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY) 791aa2cbd32SSunila Sahu return; 792aa2cbd32SSunila Sahu 793aa2cbd32SSunila Sahu /* Separate out sign r and s components */ 794aa2cbd32SSunila Sahu memcpy(ecdsa->r.data, req->rptr, prime_len); 795ecd070acSArchana Muniganti memcpy(ecdsa->s.data, req->rptr + RTE_ALIGN_CEIL(prime_len, 8), 796ecd070acSArchana Muniganti prime_len); 797aa2cbd32SSunila Sahu ecdsa->r.length = prime_len; 798aa2cbd32SSunila Sahu ecdsa->s.length = prime_len; 799aa2cbd32SSunila Sahu } 800aa2cbd32SSunila Sahu 80199faef83SSunila Sahu static __rte_always_inline void 80299faef83SSunila Sahu otx_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm, 80399faef83SSunila Sahu struct cpt_request_info *req, 80499faef83SSunila Sahu struct cpt_asym_ec_ctx *ec) 80599faef83SSunila Sahu { 80699faef83SSunila Sahu int prime_len = ec_grp[ec->curveid].prime.length; 80799faef83SSunila Sahu 80899faef83SSunila Sahu memcpy(ecpm->r.x.data, req->rptr, prime_len); 809ecd070acSArchana Muniganti memcpy(ecpm->r.y.data, req->rptr + RTE_ALIGN_CEIL(prime_len, 8), 810ecd070acSArchana Muniganti prime_len); 81199faef83SSunila Sahu ecpm->r.x.length = prime_len; 81299faef83SSunila Sahu ecpm->r.y.length = prime_len; 81399faef83SSunila Sahu } 81499faef83SSunila Sahu 815e3866e73SThomas Monjalon static __rte_always_inline void __rte_hot 816e9a356e2SSunila Sahu otx_cpt_asym_post_process(struct rte_crypto_op *cop, 817e9a356e2SSunila Sahu struct cpt_request_info *req) 818e9a356e2SSunila Sahu { 819e9a356e2SSunila Sahu struct rte_crypto_asym_op *op = cop->asym; 820e9a356e2SSunila Sahu struct cpt_asym_sess_misc *sess; 821e9a356e2SSunila Sahu 8221f1e4b7cSCiara Power sess = (struct cpt_asym_sess_misc *) op->session->sess_private_data; 823e9a356e2SSunila Sahu 824e9a356e2SSunila Sahu switch (sess->xfrm_type) { 825e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_RSA: 826e9a356e2SSunila Sahu otx_cpt_asym_rsa_op(cop, req, &sess->rsa_ctx); 827e9a356e2SSunila Sahu break; 828e9a356e2SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_MODEX: 829e9a356e2SSunila Sahu op->modex.result.length = sess->mod_ctx.modulus.length; 830e9a356e2SSunila Sahu memcpy(op->modex.result.data, req->rptr, 831e9a356e2SSunila Sahu op->modex.result.length); 832e9a356e2SSunila Sahu break; 833aa2cbd32SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_ECDSA: 834aa2cbd32SSunila Sahu otx_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx); 835aa2cbd32SSunila Sahu break; 83699faef83SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_ECPM: 83799faef83SSunila Sahu otx_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx); 83899faef83SSunila Sahu break; 839e9a356e2SSunila Sahu default: 840e9a356e2SSunila Sahu CPT_LOG_DP_DEBUG("Invalid crypto xform type"); 841e9a356e2SSunila Sahu cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; 842e9a356e2SSunila Sahu break; 843e9a356e2SSunila Sahu } 844e9a356e2SSunila Sahu } 845e9a356e2SSunila Sahu 846e3866e73SThomas Monjalon static __rte_always_inline void __rte_hot 847e9a356e2SSunila Sahu otx_cpt_dequeue_post_process(struct rte_crypto_op *cop, uintptr_t *rsp, 848e9a356e2SSunila Sahu const uint8_t op_type) 849f194f198SAnoob Joseph { 850f194f198SAnoob Joseph /* H/w has returned success */ 851f194f198SAnoob Joseph cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS; 852f194f198SAnoob Joseph 853f194f198SAnoob Joseph /* Perform further post processing */ 854f194f198SAnoob Joseph 855e9a356e2SSunila Sahu if ((op_type == OP_TYPE_SYM) && 856e9a356e2SSunila Sahu (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC)) { 857f194f198SAnoob Joseph /* Check if auth verify need to be completed */ 858f194f198SAnoob Joseph if (unlikely(rsp[2])) 859f194f198SAnoob Joseph compl_auth_verify(cop, (uint8_t *)rsp[2], rsp[3]); 860f194f198SAnoob Joseph return; 861f194f198SAnoob Joseph } 862e9a356e2SSunila Sahu 863e9a356e2SSunila Sahu if ((op_type == OP_TYPE_ASYM) && 864e9a356e2SSunila Sahu (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC)) { 865e9a356e2SSunila Sahu rsp = RTE_PTR_ADD(rsp, 4 * sizeof(uintptr_t)); 866e9a356e2SSunila Sahu otx_cpt_asym_post_process(cop, (struct cpt_request_info *)rsp); 867f194f198SAnoob Joseph } 868f194f198SAnoob Joseph 869e9a356e2SSunila Sahu return; 870e9a356e2SSunila Sahu } 871e9a356e2SSunila Sahu 87244a2cebbSShijith Thotton static inline void 87344a2cebbSShijith Thotton free_sym_session_data(const struct cpt_instance *instance, 87444a2cebbSShijith Thotton struct rte_crypto_op *cop) 87544a2cebbSShijith Thotton { 87644a2cebbSShijith Thotton void *sess_private_data_t = get_sym_session_private_data( 87744a2cebbSShijith Thotton cop->sym->session, otx_cryptodev_driver_id); 87844a2cebbSShijith Thotton memset(sess_private_data_t, 0, cpt_get_session_size()); 87944a2cebbSShijith Thotton memset(cop->sym->session, 0, 88044a2cebbSShijith Thotton rte_cryptodev_sym_get_existing_header_session_size( 88144a2cebbSShijith Thotton cop->sym->session)); 88244a2cebbSShijith Thotton rte_mempool_put(instance->sess_mp_priv, sess_private_data_t); 88344a2cebbSShijith Thotton rte_mempool_put(instance->sess_mp, cop->sym->session); 88444a2cebbSShijith Thotton cop->sym->session = NULL; 88544a2cebbSShijith Thotton } 88644a2cebbSShijith Thotton 88744a2cebbSShijith Thotton static __rte_always_inline struct rte_crypto_op * 88844a2cebbSShijith Thotton otx_cpt_process_response(const struct cpt_instance *instance, uintptr_t *rsp, 88944a2cebbSShijith Thotton uint8_t cc, const uint8_t op_type) 89044a2cebbSShijith Thotton { 89144a2cebbSShijith Thotton struct rte_crypto_op *cop; 89244a2cebbSShijith Thotton void *metabuf; 89344a2cebbSShijith Thotton 89444a2cebbSShijith Thotton metabuf = (void *)rsp[0]; 89544a2cebbSShijith Thotton cop = (void *)rsp[1]; 89644a2cebbSShijith Thotton 89744a2cebbSShijith Thotton /* Check completion code */ 89844a2cebbSShijith Thotton if (likely(cc == 0)) { 89944a2cebbSShijith Thotton /* H/w success pkt. Post process */ 90044a2cebbSShijith Thotton otx_cpt_dequeue_post_process(cop, rsp, op_type); 90144a2cebbSShijith Thotton } else if (cc == ERR_GC_ICV_MISCOMPARE) { 90244a2cebbSShijith Thotton /* auth data mismatch */ 90344a2cebbSShijith Thotton cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED; 90444a2cebbSShijith Thotton } else { 90544a2cebbSShijith Thotton /* Error */ 90644a2cebbSShijith Thotton cop->status = RTE_CRYPTO_OP_STATUS_ERROR; 90744a2cebbSShijith Thotton } 90844a2cebbSShijith Thotton 90944a2cebbSShijith Thotton if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) 91044a2cebbSShijith Thotton free_sym_session_data(instance, cop); 91144a2cebbSShijith Thotton free_op_meta(metabuf, instance->meta_info.pool); 91244a2cebbSShijith Thotton 91344a2cebbSShijith Thotton return cop; 91444a2cebbSShijith Thotton } 91544a2cebbSShijith Thotton 916e3866e73SThomas Monjalon static __rte_always_inline uint16_t __rte_hot 917e9a356e2SSunila Sahu otx_cpt_pkt_dequeue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops, 918e9a356e2SSunila Sahu const uint8_t op_type) 91989f1a8d6STejasree Kondoj { 92089f1a8d6STejasree Kondoj struct cpt_instance *instance = (struct cpt_instance *)qptr; 921f194f198SAnoob Joseph struct cpt_request_info *user_req; 92289f1a8d6STejasree Kondoj struct cpt_vf *cptvf = (struct cpt_vf *)instance; 923f194f198SAnoob Joseph uint8_t cc[nb_ops]; 924f194f198SAnoob Joseph int i, count, pcount; 925f194f198SAnoob Joseph uint8_t ret; 926f194f198SAnoob Joseph int nb_completed; 92789f1a8d6STejasree Kondoj struct pending_queue *pqueue = &cptvf->pqueue; 928f194f198SAnoob Joseph 929c9902a15SDavid George pcount = pending_queue_level(pqueue, DEFAULT_CMD_QLEN); 930c9902a15SDavid George 931c9902a15SDavid George /* Ensure pcount isn't read before data lands */ 932c9902a15SDavid George rte_atomic_thread_fence(__ATOMIC_ACQUIRE); 933c9902a15SDavid George 934f194f198SAnoob Joseph count = (nb_ops > pcount) ? pcount : nb_ops; 935f194f198SAnoob Joseph 936f194f198SAnoob Joseph for (i = 0; i < count; i++) { 937c9902a15SDavid George pending_queue_peek(pqueue, (void **) &user_req, 938c9902a15SDavid George DEFAULT_CMD_QLEN, i + 1 < count); 939f194f198SAnoob Joseph 940f194f198SAnoob Joseph ret = check_nb_command_id(user_req, instance); 941f194f198SAnoob Joseph 942f194f198SAnoob Joseph if (unlikely(ret == ERR_REQ_PENDING)) { 943f194f198SAnoob Joseph /* Stop checking for completions */ 944f194f198SAnoob Joseph break; 945f194f198SAnoob Joseph } 946f194f198SAnoob Joseph 947f194f198SAnoob Joseph /* Return completion code and op handle */ 948f194f198SAnoob Joseph cc[i] = ret; 949f194f198SAnoob Joseph ops[i] = user_req->op; 950f194f198SAnoob Joseph 951f194f198SAnoob Joseph CPT_LOG_DP_DEBUG("Request %p Op %p completed with code %d", 952f194f198SAnoob Joseph user_req, user_req->op, ret); 953f194f198SAnoob Joseph 954c9902a15SDavid George pending_queue_pop(pqueue, DEFAULT_CMD_QLEN); 955f194f198SAnoob Joseph } 956f194f198SAnoob Joseph 957f194f198SAnoob Joseph nb_completed = i; 958f194f198SAnoob Joseph 959f194f198SAnoob Joseph for (i = 0; i < nb_completed; i++) { 96089f1a8d6STejasree Kondoj if (likely((i + 1) < nb_completed)) 96189f1a8d6STejasree Kondoj rte_prefetch0(ops[i+1]); 962f194f198SAnoob Joseph 96344a2cebbSShijith Thotton ops[i] = otx_cpt_process_response(instance, (void *)ops[i], 96444a2cebbSShijith Thotton cc[i], op_type); 965f194f198SAnoob Joseph } 966f194f198SAnoob Joseph 96789f1a8d6STejasree Kondoj return nb_completed; 96889f1a8d6STejasree Kondoj } 96989f1a8d6STejasree Kondoj 970e9a356e2SSunila Sahu static uint16_t 971e9a356e2SSunila Sahu otx_cpt_dequeue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops) 972e9a356e2SSunila Sahu { 973e9a356e2SSunila Sahu return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_ASYM); 974e9a356e2SSunila Sahu } 975e9a356e2SSunila Sahu 976e9a356e2SSunila Sahu static uint16_t 977e9a356e2SSunila Sahu otx_cpt_dequeue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops) 978e9a356e2SSunila Sahu { 979e9a356e2SSunila Sahu return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_SYM); 980e9a356e2SSunila Sahu } 981e9a356e2SSunila Sahu 98244a2cebbSShijith Thotton uintptr_t __rte_hot 98344a2cebbSShijith Thotton otx_crypto_adapter_dequeue(uintptr_t get_work1) 98444a2cebbSShijith Thotton { 98544a2cebbSShijith Thotton const struct cpt_instance *instance; 98644a2cebbSShijith Thotton struct cpt_request_info *req; 98744a2cebbSShijith Thotton struct rte_crypto_op *cop; 98844a2cebbSShijith Thotton uint8_t cc, op_type; 98944a2cebbSShijith Thotton uintptr_t *rsp; 99044a2cebbSShijith Thotton 99144a2cebbSShijith Thotton req = (struct cpt_request_info *)get_work1; 99244a2cebbSShijith Thotton instance = req->qp; 99344a2cebbSShijith Thotton rsp = req->op; 99444a2cebbSShijith Thotton cop = (void *)rsp[1]; 99544a2cebbSShijith Thotton op_type = cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC ? OP_TYPE_SYM : 99644a2cebbSShijith Thotton OP_TYPE_ASYM; 99744a2cebbSShijith Thotton 99844a2cebbSShijith Thotton do { 99944a2cebbSShijith Thotton cc = check_nb_command_id( 100044a2cebbSShijith Thotton req, (struct cpt_instance *)(uintptr_t)instance); 100144a2cebbSShijith Thotton } while (cc == ERR_REQ_PENDING); 100244a2cebbSShijith Thotton 100344a2cebbSShijith Thotton cop = otx_cpt_process_response(instance, (void *)req->op, cc, op_type); 100444a2cebbSShijith Thotton 100544a2cebbSShijith Thotton return (uintptr_t)(cop); 100644a2cebbSShijith Thotton } 100744a2cebbSShijith Thotton 10080906b99fSMurthy NSSR static struct rte_cryptodev_ops cptvf_ops = { 10090906b99fSMurthy NSSR /* Device related operations */ 10100906b99fSMurthy NSSR .dev_configure = otx_cpt_dev_config, 10110906b99fSMurthy NSSR .dev_start = otx_cpt_dev_start, 10120906b99fSMurthy NSSR .dev_stop = otx_cpt_dev_stop, 10130906b99fSMurthy NSSR .dev_close = otx_cpt_dev_close, 10140906b99fSMurthy NSSR .dev_infos_get = otx_cpt_dev_info_get, 10150906b99fSMurthy NSSR 1016966b43fdSAnkur Dwivedi .stats_get = NULL, 1017966b43fdSAnkur Dwivedi .stats_reset = NULL, 10180961348fSMurthy NSSR .queue_pair_setup = otx_cpt_que_pair_setup, 10190961348fSMurthy NSSR .queue_pair_release = otx_cpt_que_pair_release, 10200906b99fSMurthy NSSR 10210906b99fSMurthy NSSR /* Crypto related operations */ 102243d01767SNithin Dabilpuram .sym_session_get_size = otx_cpt_get_session_size, 102343d01767SNithin Dabilpuram .sym_session_configure = otx_cpt_session_cfg, 102433bcaae5SKanaka Durga Kotamarthy .sym_session_clear = otx_cpt_session_clear, 102533bcaae5SKanaka Durga Kotamarthy 102633bcaae5SKanaka Durga Kotamarthy .asym_session_get_size = otx_cpt_asym_session_size_get, 102733bcaae5SKanaka Durga Kotamarthy .asym_session_configure = otx_cpt_asym_session_cfg, 102833bcaae5SKanaka Durga Kotamarthy .asym_session_clear = otx_cpt_asym_session_clear, 10290906b99fSMurthy NSSR }; 10300906b99fSMurthy NSSR 1031bfe2ae49SAnoob Joseph int 1032bfe2ae49SAnoob Joseph otx_cpt_dev_create(struct rte_cryptodev *c_dev) 1033bfe2ae49SAnoob Joseph { 10340dc1cffaSAnkur Dwivedi struct rte_pci_device *pdev = RTE_DEV_TO_PCI(c_dev->device); 10350dc1cffaSAnkur Dwivedi struct cpt_vf *cptvf = NULL; 10360dc1cffaSAnkur Dwivedi void *reg_base; 10370dc1cffaSAnkur Dwivedi char dev_name[32]; 10380dc1cffaSAnkur Dwivedi int ret; 10390dc1cffaSAnkur Dwivedi 10400dc1cffaSAnkur Dwivedi if (pdev->mem_resource[0].phys_addr == 0ULL) 10410dc1cffaSAnkur Dwivedi return -EIO; 10420dc1cffaSAnkur Dwivedi 10430dc1cffaSAnkur Dwivedi /* for secondary processes, we don't initialise any further as primary 10440dc1cffaSAnkur Dwivedi * has already done this work. 10450dc1cffaSAnkur Dwivedi */ 10460dc1cffaSAnkur Dwivedi if (rte_eal_process_type() != RTE_PROC_PRIMARY) 1047bfe2ae49SAnoob Joseph return 0; 10480dc1cffaSAnkur Dwivedi 10490dc1cffaSAnkur Dwivedi cptvf = rte_zmalloc_socket("otx_cryptodev_private_mem", 10500dc1cffaSAnkur Dwivedi sizeof(struct cpt_vf), RTE_CACHE_LINE_SIZE, 10510dc1cffaSAnkur Dwivedi rte_socket_id()); 10520dc1cffaSAnkur Dwivedi 10530dc1cffaSAnkur Dwivedi if (cptvf == NULL) { 10540dc1cffaSAnkur Dwivedi CPT_LOG_ERR("Cannot allocate memory for device private data"); 10550dc1cffaSAnkur Dwivedi return -ENOMEM; 10560dc1cffaSAnkur Dwivedi } 10570dc1cffaSAnkur Dwivedi 10580dc1cffaSAnkur Dwivedi snprintf(dev_name, 32, "%02x:%02x.%x", 10590dc1cffaSAnkur Dwivedi pdev->addr.bus, pdev->addr.devid, pdev->addr.function); 10600dc1cffaSAnkur Dwivedi 10610dc1cffaSAnkur Dwivedi reg_base = pdev->mem_resource[0].addr; 10620dc1cffaSAnkur Dwivedi if (!reg_base) { 10630dc1cffaSAnkur Dwivedi CPT_LOG_ERR("Failed to map BAR0 of %s", dev_name); 10640dc1cffaSAnkur Dwivedi ret = -ENODEV; 10650dc1cffaSAnkur Dwivedi goto fail; 10660dc1cffaSAnkur Dwivedi } 10670dc1cffaSAnkur Dwivedi 10680dc1cffaSAnkur Dwivedi ret = otx_cpt_hw_init(cptvf, pdev, reg_base, dev_name); 10690dc1cffaSAnkur Dwivedi if (ret) { 10700dc1cffaSAnkur Dwivedi CPT_LOG_ERR("Failed to init cptvf %s", dev_name); 10710dc1cffaSAnkur Dwivedi ret = -EIO; 10720dc1cffaSAnkur Dwivedi goto fail; 10730dc1cffaSAnkur Dwivedi } 10740dc1cffaSAnkur Dwivedi 107513d711f3SKanaka Durga Kotamarthy switch (cptvf->vftype) { 107613d711f3SKanaka Durga Kotamarthy case OTX_CPT_VF_TYPE_AE: 107713d711f3SKanaka Durga Kotamarthy /* Set asymmetric cpt feature flags */ 107813d711f3SKanaka Durga Kotamarthy c_dev->feature_flags = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO | 107933bcaae5SKanaka Durga Kotamarthy RTE_CRYPTODEV_FF_HW_ACCELERATED | 108033bcaae5SKanaka Durga Kotamarthy RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT; 108113d711f3SKanaka Durga Kotamarthy break; 108213d711f3SKanaka Durga Kotamarthy case OTX_CPT_VF_TYPE_SE: 108313d711f3SKanaka Durga Kotamarthy /* Set symmetric cpt feature flags */ 108413d711f3SKanaka Durga Kotamarthy c_dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO | 108513d711f3SKanaka Durga Kotamarthy RTE_CRYPTODEV_FF_HW_ACCELERATED | 108613d711f3SKanaka Durga Kotamarthy RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING | 108713d711f3SKanaka Durga Kotamarthy RTE_CRYPTODEV_FF_IN_PLACE_SGL | 108816c01147SDidier Pallard RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT | 108913d711f3SKanaka Durga Kotamarthy RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT | 1090b3aaf24dSPablo de Lara RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT | 1091de5eb0a6STejasree Kondoj RTE_CRYPTODEV_FF_SYM_SESSIONLESS | 1092de5eb0a6STejasree Kondoj RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED; 109313d711f3SKanaka Durga Kotamarthy break; 109413d711f3SKanaka Durga Kotamarthy default: 109513d711f3SKanaka Durga Kotamarthy /* Feature not supported. Abort */ 109613d711f3SKanaka Durga Kotamarthy CPT_LOG_ERR("VF type not supported by %s", dev_name); 109713d711f3SKanaka Durga Kotamarthy ret = -EIO; 109813d711f3SKanaka Durga Kotamarthy goto deinit_dev; 109913d711f3SKanaka Durga Kotamarthy } 110013d711f3SKanaka Durga Kotamarthy 11010dc1cffaSAnkur Dwivedi /* Start off timer for mailbox interrupts */ 11020dc1cffaSAnkur Dwivedi otx_cpt_periodic_alarm_start(cptvf); 11030dc1cffaSAnkur Dwivedi 11040906b99fSMurthy NSSR c_dev->dev_ops = &cptvf_ops; 11050dc1cffaSAnkur Dwivedi 1106e9a356e2SSunila Sahu if (c_dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) { 1107e9a356e2SSunila Sahu c_dev->enqueue_burst = otx_cpt_enqueue_sym; 1108e9a356e2SSunila Sahu c_dev->dequeue_burst = otx_cpt_dequeue_sym; 1109e9a356e2SSunila Sahu } else { 1110e9a356e2SSunila Sahu c_dev->enqueue_burst = otx_cpt_enqueue_asym; 1111e9a356e2SSunila Sahu c_dev->dequeue_burst = otx_cpt_dequeue_asym; 1112e9a356e2SSunila Sahu } 11130dc1cffaSAnkur Dwivedi 11140dc1cffaSAnkur Dwivedi /* Save dev private data */ 11150dc1cffaSAnkur Dwivedi c_dev->data->dev_private = cptvf; 11160dc1cffaSAnkur Dwivedi 11170dc1cffaSAnkur Dwivedi return 0; 11180dc1cffaSAnkur Dwivedi 111913d711f3SKanaka Durga Kotamarthy deinit_dev: 112013d711f3SKanaka Durga Kotamarthy otx_cpt_deinit_device(cptvf); 112113d711f3SKanaka Durga Kotamarthy 11220dc1cffaSAnkur Dwivedi fail: 11230dc1cffaSAnkur Dwivedi if (cptvf) { 11240dc1cffaSAnkur Dwivedi /* Free private data allocated */ 11250dc1cffaSAnkur Dwivedi rte_free(cptvf); 11260dc1cffaSAnkur Dwivedi } 11270dc1cffaSAnkur Dwivedi 11280dc1cffaSAnkur Dwivedi return ret; 1129bfe2ae49SAnoob Joseph } 1130