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> 80906b99fSMurthy NSSR #include <rte_cryptodev_pmd.h> 90dc1cffaSAnkur Dwivedi #include <rte_malloc.h> 100dc1cffaSAnkur Dwivedi 110dc1cffaSAnkur Dwivedi #include "cpt_pmd_logs.h" 12273487f7SAnoob Joseph #include "cpt_pmd_ops_helper.h" 13*43d01767SNithin Dabilpuram #include "cpt_ucode.h" 14*43d01767SNithin Dabilpuram #include "cpt_request_mgr.h" 15bfe2ae49SAnoob Joseph 16bfe2ae49SAnoob Joseph #include "otx_cryptodev.h" 170906b99fSMurthy NSSR #include "otx_cryptodev_capabilities.h" 180dc1cffaSAnkur Dwivedi #include "otx_cryptodev_hw_access.h" 19bfe2ae49SAnoob Joseph #include "otx_cryptodev_ops.h" 20bfe2ae49SAnoob Joseph 21273487f7SAnoob Joseph static int otx_cryptodev_probe_count; 22273487f7SAnoob Joseph static rte_spinlock_t otx_probe_count_lock = RTE_SPINLOCK_INITIALIZER; 23273487f7SAnoob Joseph 24273487f7SAnoob Joseph static struct rte_mempool *otx_cpt_meta_pool; 25273487f7SAnoob Joseph static int otx_cpt_op_mlen; 26273487f7SAnoob Joseph static int otx_cpt_op_sb_mlen; 27273487f7SAnoob Joseph 280961348fSMurthy NSSR /* Forward declarations */ 290961348fSMurthy NSSR 300961348fSMurthy NSSR static int 310961348fSMurthy NSSR otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id); 320961348fSMurthy NSSR 33273487f7SAnoob Joseph /* 34273487f7SAnoob Joseph * Initializes global variables used by fast-path code 35273487f7SAnoob Joseph * 36273487f7SAnoob Joseph * @return 37273487f7SAnoob Joseph * - 0 on success, errcode on error 38273487f7SAnoob Joseph */ 39273487f7SAnoob Joseph static int 40273487f7SAnoob Joseph init_global_resources(void) 41273487f7SAnoob Joseph { 42273487f7SAnoob Joseph /* Get meta len for scatter gather mode */ 43273487f7SAnoob Joseph otx_cpt_op_mlen = cpt_pmd_ops_helper_get_mlen_sg_mode(); 44273487f7SAnoob Joseph 45273487f7SAnoob Joseph /* Extra 4B saved for future considerations */ 46273487f7SAnoob Joseph otx_cpt_op_mlen += 4 * sizeof(uint64_t); 47273487f7SAnoob Joseph 48273487f7SAnoob Joseph otx_cpt_meta_pool = rte_mempool_create("cpt_metabuf-pool", 4096 * 16, 49273487f7SAnoob Joseph otx_cpt_op_mlen, 512, 0, 50273487f7SAnoob Joseph NULL, NULL, NULL, NULL, 51273487f7SAnoob Joseph SOCKET_ID_ANY, 0); 52273487f7SAnoob Joseph if (!otx_cpt_meta_pool) { 53273487f7SAnoob Joseph CPT_LOG_ERR("cpt metabuf pool not created"); 54273487f7SAnoob Joseph return -ENOMEM; 55273487f7SAnoob Joseph } 56273487f7SAnoob Joseph 57273487f7SAnoob Joseph /* Get meta len for direct mode */ 58273487f7SAnoob Joseph otx_cpt_op_sb_mlen = cpt_pmd_ops_helper_get_mlen_direct_mode(); 59273487f7SAnoob Joseph 60273487f7SAnoob Joseph /* Extra 4B saved for future considerations */ 61273487f7SAnoob Joseph otx_cpt_op_sb_mlen += 4 * sizeof(uint64_t); 62273487f7SAnoob Joseph 63273487f7SAnoob Joseph return 0; 64273487f7SAnoob Joseph } 65273487f7SAnoob Joseph 66273487f7SAnoob Joseph void 67273487f7SAnoob Joseph cleanup_global_resources(void) 68273487f7SAnoob Joseph { 69273487f7SAnoob Joseph /* Take lock */ 70273487f7SAnoob Joseph rte_spinlock_lock(&otx_probe_count_lock); 71273487f7SAnoob Joseph 72273487f7SAnoob Joseph /* Decrement the cryptodev count */ 73273487f7SAnoob Joseph otx_cryptodev_probe_count--; 74273487f7SAnoob Joseph 75273487f7SAnoob Joseph /* Free buffers */ 76273487f7SAnoob Joseph if (otx_cpt_meta_pool && otx_cryptodev_probe_count == 0) 77273487f7SAnoob Joseph rte_mempool_free(otx_cpt_meta_pool); 78273487f7SAnoob Joseph 79273487f7SAnoob Joseph /* Free lock */ 80273487f7SAnoob Joseph rte_spinlock_unlock(&otx_probe_count_lock); 81273487f7SAnoob Joseph } 82273487f7SAnoob Joseph 830dc1cffaSAnkur Dwivedi /* Alarm routines */ 840dc1cffaSAnkur Dwivedi 850dc1cffaSAnkur Dwivedi static void 860dc1cffaSAnkur Dwivedi otx_cpt_alarm_cb(void *arg) 870dc1cffaSAnkur Dwivedi { 880dc1cffaSAnkur Dwivedi struct cpt_vf *cptvf = arg; 890dc1cffaSAnkur Dwivedi otx_cpt_poll_misc(cptvf); 900dc1cffaSAnkur Dwivedi rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000, 910dc1cffaSAnkur Dwivedi otx_cpt_alarm_cb, cptvf); 920dc1cffaSAnkur Dwivedi } 930dc1cffaSAnkur Dwivedi 940dc1cffaSAnkur Dwivedi static int 950dc1cffaSAnkur Dwivedi otx_cpt_periodic_alarm_start(void *arg) 960dc1cffaSAnkur Dwivedi { 970dc1cffaSAnkur Dwivedi return rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000, 980dc1cffaSAnkur Dwivedi otx_cpt_alarm_cb, arg); 990dc1cffaSAnkur Dwivedi } 1000dc1cffaSAnkur Dwivedi 101273487f7SAnoob Joseph static int 102273487f7SAnoob Joseph otx_cpt_periodic_alarm_stop(void *arg) 103273487f7SAnoob Joseph { 104273487f7SAnoob Joseph return rte_eal_alarm_cancel(otx_cpt_alarm_cb, arg); 105273487f7SAnoob Joseph } 106273487f7SAnoob Joseph 1070906b99fSMurthy NSSR /* PMD ops */ 1080906b99fSMurthy NSSR 1090906b99fSMurthy NSSR static int 1100906b99fSMurthy NSSR otx_cpt_dev_config(struct rte_cryptodev *dev __rte_unused, 1110906b99fSMurthy NSSR struct rte_cryptodev_config *config __rte_unused) 1120906b99fSMurthy NSSR { 1130906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1140906b99fSMurthy NSSR return 0; 1150906b99fSMurthy NSSR } 1160906b99fSMurthy NSSR 1170906b99fSMurthy NSSR static int 1180906b99fSMurthy NSSR otx_cpt_dev_start(struct rte_cryptodev *c_dev) 1190906b99fSMurthy NSSR { 1200906b99fSMurthy NSSR void *cptvf = c_dev->data->dev_private; 1210906b99fSMurthy NSSR 1220906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1230906b99fSMurthy NSSR 1240906b99fSMurthy NSSR return otx_cpt_start_device(cptvf); 1250906b99fSMurthy NSSR } 1260906b99fSMurthy NSSR 1270906b99fSMurthy NSSR static void 1280906b99fSMurthy NSSR otx_cpt_dev_stop(struct rte_cryptodev *c_dev) 1290906b99fSMurthy NSSR { 1300906b99fSMurthy NSSR void *cptvf = c_dev->data->dev_private; 1310906b99fSMurthy NSSR 1320906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1330906b99fSMurthy NSSR 1340906b99fSMurthy NSSR otx_cpt_stop_device(cptvf); 1350906b99fSMurthy NSSR } 1360906b99fSMurthy NSSR 1370906b99fSMurthy NSSR static int 1380906b99fSMurthy NSSR otx_cpt_dev_close(struct rte_cryptodev *c_dev) 1390906b99fSMurthy NSSR { 1400906b99fSMurthy NSSR void *cptvf = c_dev->data->dev_private; 1410961348fSMurthy NSSR int i, ret; 1420906b99fSMurthy NSSR 1430906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1440906b99fSMurthy NSSR 1450961348fSMurthy NSSR for (i = 0; i < c_dev->data->nb_queue_pairs; i++) { 1460961348fSMurthy NSSR ret = otx_cpt_que_pair_release(c_dev, i); 1470961348fSMurthy NSSR if (ret) 1480961348fSMurthy NSSR return ret; 1490961348fSMurthy NSSR } 1500961348fSMurthy NSSR 1510906b99fSMurthy NSSR otx_cpt_periodic_alarm_stop(cptvf); 1520906b99fSMurthy NSSR otx_cpt_deinit_device(cptvf); 1530906b99fSMurthy NSSR 1540906b99fSMurthy NSSR return 0; 1550906b99fSMurthy NSSR } 1560906b99fSMurthy NSSR 1570906b99fSMurthy NSSR static void 1580906b99fSMurthy NSSR otx_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info) 1590906b99fSMurthy NSSR { 1600906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1610906b99fSMurthy NSSR if (info != NULL) { 1620906b99fSMurthy NSSR info->max_nb_queue_pairs = CPT_NUM_QS_PER_VF; 1630906b99fSMurthy NSSR info->feature_flags = dev->feature_flags; 1640906b99fSMurthy NSSR info->capabilities = otx_get_capabilities(); 1650906b99fSMurthy NSSR info->sym.max_nb_sessions = 0; 1660906b99fSMurthy NSSR info->driver_id = otx_cryptodev_driver_id; 1670906b99fSMurthy NSSR info->min_mbuf_headroom_req = OTX_CPT_MIN_HEADROOM_REQ; 1680906b99fSMurthy NSSR info->min_mbuf_tailroom_req = OTX_CPT_MIN_TAILROOM_REQ; 1690906b99fSMurthy NSSR } 1700906b99fSMurthy NSSR } 1710906b99fSMurthy NSSR 1720906b99fSMurthy NSSR static void 1730906b99fSMurthy NSSR otx_cpt_stats_get(struct rte_cryptodev *dev __rte_unused, 1740906b99fSMurthy NSSR struct rte_cryptodev_stats *stats __rte_unused) 1750906b99fSMurthy NSSR { 1760906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1770906b99fSMurthy NSSR } 1780906b99fSMurthy NSSR 1790906b99fSMurthy NSSR static void 1800906b99fSMurthy NSSR otx_cpt_stats_reset(struct rte_cryptodev *dev __rte_unused) 1810906b99fSMurthy NSSR { 1820906b99fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1830906b99fSMurthy NSSR } 1840906b99fSMurthy NSSR 1850961348fSMurthy NSSR static int 1860961348fSMurthy NSSR otx_cpt_que_pair_setup(struct rte_cryptodev *dev, 1870961348fSMurthy NSSR uint16_t que_pair_id, 1880961348fSMurthy NSSR const struct rte_cryptodev_qp_conf *qp_conf, 1890961348fSMurthy NSSR int socket_id __rte_unused, 1900961348fSMurthy NSSR struct rte_mempool *session_pool __rte_unused) 1910961348fSMurthy NSSR { 1920961348fSMurthy NSSR void *cptvf = dev->data->dev_private; 1930961348fSMurthy NSSR struct cpt_instance *instance = NULL; 1940961348fSMurthy NSSR struct rte_pci_device *pci_dev; 1950961348fSMurthy NSSR int ret = -1; 1960961348fSMurthy NSSR 1970961348fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 1980961348fSMurthy NSSR 1990961348fSMurthy NSSR if (dev->data->queue_pairs[que_pair_id] != NULL) { 2000961348fSMurthy NSSR ret = otx_cpt_que_pair_release(dev, que_pair_id); 2010961348fSMurthy NSSR if (ret) 2020961348fSMurthy NSSR return ret; 2030961348fSMurthy NSSR } 2040961348fSMurthy NSSR 2050961348fSMurthy NSSR if (qp_conf->nb_descriptors > DEFAULT_CMD_QLEN) { 2060961348fSMurthy NSSR CPT_LOG_INFO("Number of descriptors too big %d, using default " 2070961348fSMurthy NSSR "queue length of %d", qp_conf->nb_descriptors, 2080961348fSMurthy NSSR DEFAULT_CMD_QLEN); 2090961348fSMurthy NSSR } 2100961348fSMurthy NSSR 2110961348fSMurthy NSSR pci_dev = RTE_DEV_TO_PCI(dev->device); 2120961348fSMurthy NSSR 2130961348fSMurthy NSSR if (pci_dev->mem_resource[0].addr == NULL) { 2140961348fSMurthy NSSR CPT_LOG_ERR("PCI mem address null"); 2150961348fSMurthy NSSR return -EIO; 2160961348fSMurthy NSSR } 2170961348fSMurthy NSSR 2180961348fSMurthy NSSR ret = otx_cpt_get_resource(cptvf, 0, &instance); 2190961348fSMurthy NSSR if (ret != 0) { 2200961348fSMurthy NSSR CPT_LOG_ERR("Error getting instance handle from device %s : " 2210961348fSMurthy NSSR "ret = %d", dev->data->name, ret); 2220961348fSMurthy NSSR return ret; 2230961348fSMurthy NSSR } 2240961348fSMurthy NSSR 2250961348fSMurthy NSSR instance->queue_id = que_pair_id; 2260961348fSMurthy NSSR dev->data->queue_pairs[que_pair_id] = instance; 2270961348fSMurthy NSSR 2280961348fSMurthy NSSR return 0; 2290961348fSMurthy NSSR } 2300961348fSMurthy NSSR 2310961348fSMurthy NSSR static int 2320961348fSMurthy NSSR otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id) 2330961348fSMurthy NSSR { 2340961348fSMurthy NSSR struct cpt_instance *instance = dev->data->queue_pairs[que_pair_id]; 2350961348fSMurthy NSSR int ret; 2360961348fSMurthy NSSR 2370961348fSMurthy NSSR CPT_PMD_INIT_FUNC_TRACE(); 2380961348fSMurthy NSSR 2390961348fSMurthy NSSR ret = otx_cpt_put_resource(instance); 2400961348fSMurthy NSSR if (ret != 0) { 2410961348fSMurthy NSSR CPT_LOG_ERR("Error putting instance handle of device %s : " 2420961348fSMurthy NSSR "ret = %d", dev->data->name, ret); 2430961348fSMurthy NSSR return ret; 2440961348fSMurthy NSSR } 2450961348fSMurthy NSSR 2460961348fSMurthy NSSR dev->data->queue_pairs[que_pair_id] = NULL; 2470961348fSMurthy NSSR 2480961348fSMurthy NSSR return 0; 2490961348fSMurthy NSSR } 2500961348fSMurthy NSSR 251*43d01767SNithin Dabilpuram static unsigned int 252*43d01767SNithin Dabilpuram otx_cpt_get_session_size(struct rte_cryptodev *dev __rte_unused) 253*43d01767SNithin Dabilpuram { 254*43d01767SNithin Dabilpuram return cpt_get_session_size(); 255*43d01767SNithin Dabilpuram } 256*43d01767SNithin Dabilpuram 257*43d01767SNithin Dabilpuram static void 258*43d01767SNithin Dabilpuram otx_cpt_session_init(void *sym_sess, uint8_t driver_id) 259*43d01767SNithin Dabilpuram { 260*43d01767SNithin Dabilpuram struct rte_cryptodev_sym_session *sess = sym_sess; 261*43d01767SNithin Dabilpuram struct cpt_sess_misc *cpt_sess = 262*43d01767SNithin Dabilpuram (struct cpt_sess_misc *) get_sym_session_private_data(sess, driver_id); 263*43d01767SNithin Dabilpuram 264*43d01767SNithin Dabilpuram CPT_PMD_INIT_FUNC_TRACE(); 265*43d01767SNithin Dabilpuram cpt_sess->ctx_dma_addr = rte_mempool_virt2iova(cpt_sess) + 266*43d01767SNithin Dabilpuram sizeof(struct cpt_sess_misc); 267*43d01767SNithin Dabilpuram } 268*43d01767SNithin Dabilpuram 269*43d01767SNithin Dabilpuram static int 270*43d01767SNithin Dabilpuram otx_cpt_session_cfg(struct rte_cryptodev *dev, 271*43d01767SNithin Dabilpuram struct rte_crypto_sym_xform *xform, 272*43d01767SNithin Dabilpuram struct rte_cryptodev_sym_session *sess, 273*43d01767SNithin Dabilpuram struct rte_mempool *mempool) 274*43d01767SNithin Dabilpuram { 275*43d01767SNithin Dabilpuram struct rte_crypto_sym_xform *chain; 276*43d01767SNithin Dabilpuram void *sess_private_data = NULL; 277*43d01767SNithin Dabilpuram 278*43d01767SNithin Dabilpuram CPT_PMD_INIT_FUNC_TRACE(); 279*43d01767SNithin Dabilpuram 280*43d01767SNithin Dabilpuram if (cpt_is_algo_supported(xform)) 281*43d01767SNithin Dabilpuram goto err; 282*43d01767SNithin Dabilpuram 283*43d01767SNithin Dabilpuram if (unlikely(sess == NULL)) { 284*43d01767SNithin Dabilpuram CPT_LOG_ERR("invalid session struct"); 285*43d01767SNithin Dabilpuram return -EINVAL; 286*43d01767SNithin Dabilpuram } 287*43d01767SNithin Dabilpuram 288*43d01767SNithin Dabilpuram if (rte_mempool_get(mempool, &sess_private_data)) { 289*43d01767SNithin Dabilpuram CPT_LOG_ERR("Could not allocate sess_private_data"); 290*43d01767SNithin Dabilpuram return -ENOMEM; 291*43d01767SNithin Dabilpuram } 292*43d01767SNithin Dabilpuram 293*43d01767SNithin Dabilpuram chain = xform; 294*43d01767SNithin Dabilpuram while (chain) { 295*43d01767SNithin Dabilpuram switch (chain->type) { 296*43d01767SNithin Dabilpuram default: 297*43d01767SNithin Dabilpuram CPT_LOG_ERR("Invalid crypto xform type"); 298*43d01767SNithin Dabilpuram break; 299*43d01767SNithin Dabilpuram } 300*43d01767SNithin Dabilpuram chain = chain->next; 301*43d01767SNithin Dabilpuram } 302*43d01767SNithin Dabilpuram set_sym_session_private_data(sess, dev->driver_id, sess_private_data); 303*43d01767SNithin Dabilpuram otx_cpt_session_init(sess, dev->driver_id); 304*43d01767SNithin Dabilpuram return 0; 305*43d01767SNithin Dabilpuram 306*43d01767SNithin Dabilpuram err: 307*43d01767SNithin Dabilpuram if (sess_private_data) 308*43d01767SNithin Dabilpuram rte_mempool_put(mempool, sess_private_data); 309*43d01767SNithin Dabilpuram return -EPERM; 310*43d01767SNithin Dabilpuram } 311*43d01767SNithin Dabilpuram 312*43d01767SNithin Dabilpuram static void 313*43d01767SNithin Dabilpuram otx_cpt_session_clear(struct rte_cryptodev *dev, 314*43d01767SNithin Dabilpuram struct rte_cryptodev_sym_session *sess) 315*43d01767SNithin Dabilpuram { 316*43d01767SNithin Dabilpuram void *sess_priv = get_sym_session_private_data(sess, dev->driver_id); 317*43d01767SNithin Dabilpuram 318*43d01767SNithin Dabilpuram CPT_PMD_INIT_FUNC_TRACE(); 319*43d01767SNithin Dabilpuram if (sess_priv) { 320*43d01767SNithin Dabilpuram memset(sess_priv, 0, otx_cpt_get_session_size(dev)); 321*43d01767SNithin Dabilpuram struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv); 322*43d01767SNithin Dabilpuram set_sym_session_private_data(sess, dev->driver_id, NULL); 323*43d01767SNithin Dabilpuram rte_mempool_put(sess_mp, sess_priv); 324*43d01767SNithin Dabilpuram } 325*43d01767SNithin Dabilpuram } 326*43d01767SNithin Dabilpuram 3270906b99fSMurthy NSSR static struct rte_cryptodev_ops cptvf_ops = { 3280906b99fSMurthy NSSR /* Device related operations */ 3290906b99fSMurthy NSSR .dev_configure = otx_cpt_dev_config, 3300906b99fSMurthy NSSR .dev_start = otx_cpt_dev_start, 3310906b99fSMurthy NSSR .dev_stop = otx_cpt_dev_stop, 3320906b99fSMurthy NSSR .dev_close = otx_cpt_dev_close, 3330906b99fSMurthy NSSR .dev_infos_get = otx_cpt_dev_info_get, 3340906b99fSMurthy NSSR 3350906b99fSMurthy NSSR .stats_get = otx_cpt_stats_get, 3360906b99fSMurthy NSSR .stats_reset = otx_cpt_stats_reset, 3370961348fSMurthy NSSR .queue_pair_setup = otx_cpt_que_pair_setup, 3380961348fSMurthy NSSR .queue_pair_release = otx_cpt_que_pair_release, 3390906b99fSMurthy NSSR .queue_pair_count = NULL, 3400906b99fSMurthy NSSR 3410906b99fSMurthy NSSR /* Crypto related operations */ 342*43d01767SNithin Dabilpuram .sym_session_get_size = otx_cpt_get_session_size, 343*43d01767SNithin Dabilpuram .sym_session_configure = otx_cpt_session_cfg, 344*43d01767SNithin Dabilpuram .sym_session_clear = otx_cpt_session_clear 3450906b99fSMurthy NSSR }; 3460906b99fSMurthy NSSR 347273487f7SAnoob Joseph static void 348273487f7SAnoob Joseph otx_cpt_common_vars_init(struct cpt_vf *cptvf) 349273487f7SAnoob Joseph { 350273487f7SAnoob Joseph cptvf->meta_info.cptvf_meta_pool = otx_cpt_meta_pool; 351273487f7SAnoob Joseph cptvf->meta_info.cptvf_op_mlen = otx_cpt_op_mlen; 352273487f7SAnoob Joseph cptvf->meta_info.cptvf_op_sb_mlen = otx_cpt_op_sb_mlen; 353273487f7SAnoob Joseph } 354273487f7SAnoob Joseph 355bfe2ae49SAnoob Joseph int 356bfe2ae49SAnoob Joseph otx_cpt_dev_create(struct rte_cryptodev *c_dev) 357bfe2ae49SAnoob Joseph { 3580dc1cffaSAnkur Dwivedi struct rte_pci_device *pdev = RTE_DEV_TO_PCI(c_dev->device); 3590dc1cffaSAnkur Dwivedi struct cpt_vf *cptvf = NULL; 3600dc1cffaSAnkur Dwivedi void *reg_base; 3610dc1cffaSAnkur Dwivedi char dev_name[32]; 3620dc1cffaSAnkur Dwivedi int ret; 3630dc1cffaSAnkur Dwivedi 3640dc1cffaSAnkur Dwivedi if (pdev->mem_resource[0].phys_addr == 0ULL) 3650dc1cffaSAnkur Dwivedi return -EIO; 3660dc1cffaSAnkur Dwivedi 3670dc1cffaSAnkur Dwivedi /* for secondary processes, we don't initialise any further as primary 3680dc1cffaSAnkur Dwivedi * has already done this work. 3690dc1cffaSAnkur Dwivedi */ 3700dc1cffaSAnkur Dwivedi if (rte_eal_process_type() != RTE_PROC_PRIMARY) 371bfe2ae49SAnoob Joseph return 0; 3720dc1cffaSAnkur Dwivedi 3730dc1cffaSAnkur Dwivedi cptvf = rte_zmalloc_socket("otx_cryptodev_private_mem", 3740dc1cffaSAnkur Dwivedi sizeof(struct cpt_vf), RTE_CACHE_LINE_SIZE, 3750dc1cffaSAnkur Dwivedi rte_socket_id()); 3760dc1cffaSAnkur Dwivedi 3770dc1cffaSAnkur Dwivedi if (cptvf == NULL) { 3780dc1cffaSAnkur Dwivedi CPT_LOG_ERR("Cannot allocate memory for device private data"); 3790dc1cffaSAnkur Dwivedi return -ENOMEM; 3800dc1cffaSAnkur Dwivedi } 3810dc1cffaSAnkur Dwivedi 3820dc1cffaSAnkur Dwivedi snprintf(dev_name, 32, "%02x:%02x.%x", 3830dc1cffaSAnkur Dwivedi pdev->addr.bus, pdev->addr.devid, pdev->addr.function); 3840dc1cffaSAnkur Dwivedi 3850dc1cffaSAnkur Dwivedi reg_base = pdev->mem_resource[0].addr; 3860dc1cffaSAnkur Dwivedi if (!reg_base) { 3870dc1cffaSAnkur Dwivedi CPT_LOG_ERR("Failed to map BAR0 of %s", dev_name); 3880dc1cffaSAnkur Dwivedi ret = -ENODEV; 3890dc1cffaSAnkur Dwivedi goto fail; 3900dc1cffaSAnkur Dwivedi } 3910dc1cffaSAnkur Dwivedi 3920dc1cffaSAnkur Dwivedi ret = otx_cpt_hw_init(cptvf, pdev, reg_base, dev_name); 3930dc1cffaSAnkur Dwivedi if (ret) { 3940dc1cffaSAnkur Dwivedi CPT_LOG_ERR("Failed to init cptvf %s", dev_name); 3950dc1cffaSAnkur Dwivedi ret = -EIO; 3960dc1cffaSAnkur Dwivedi goto fail; 3970dc1cffaSAnkur Dwivedi } 3980dc1cffaSAnkur Dwivedi 3990dc1cffaSAnkur Dwivedi /* Start off timer for mailbox interrupts */ 4000dc1cffaSAnkur Dwivedi otx_cpt_periodic_alarm_start(cptvf); 4010dc1cffaSAnkur Dwivedi 402273487f7SAnoob Joseph rte_spinlock_lock(&otx_probe_count_lock); 403273487f7SAnoob Joseph if (!otx_cryptodev_probe_count) { 404273487f7SAnoob Joseph ret = init_global_resources(); 405273487f7SAnoob Joseph if (ret) { 406273487f7SAnoob Joseph rte_spinlock_unlock(&otx_probe_count_lock); 407273487f7SAnoob Joseph goto init_fail; 408273487f7SAnoob Joseph } 409273487f7SAnoob Joseph } 410273487f7SAnoob Joseph otx_cryptodev_probe_count++; 411273487f7SAnoob Joseph rte_spinlock_unlock(&otx_probe_count_lock); 412273487f7SAnoob Joseph 413273487f7SAnoob Joseph /* Initialize data path variables used by common code */ 414273487f7SAnoob Joseph otx_cpt_common_vars_init(cptvf); 415273487f7SAnoob Joseph 4160906b99fSMurthy NSSR c_dev->dev_ops = &cptvf_ops; 4170dc1cffaSAnkur Dwivedi 4180dc1cffaSAnkur Dwivedi c_dev->enqueue_burst = NULL; 4190dc1cffaSAnkur Dwivedi c_dev->dequeue_burst = NULL; 4200dc1cffaSAnkur Dwivedi 4210dc1cffaSAnkur Dwivedi c_dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO | 4220dc1cffaSAnkur Dwivedi RTE_CRYPTODEV_FF_HW_ACCELERATED | 4230dc1cffaSAnkur Dwivedi RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING | 4240dc1cffaSAnkur Dwivedi RTE_CRYPTODEV_FF_IN_PLACE_SGL | 4250dc1cffaSAnkur Dwivedi RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT | 4260dc1cffaSAnkur Dwivedi RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT; 4270dc1cffaSAnkur Dwivedi 4280dc1cffaSAnkur Dwivedi /* Save dev private data */ 4290dc1cffaSAnkur Dwivedi c_dev->data->dev_private = cptvf; 4300dc1cffaSAnkur Dwivedi 4310dc1cffaSAnkur Dwivedi return 0; 4320dc1cffaSAnkur Dwivedi 433273487f7SAnoob Joseph init_fail: 434273487f7SAnoob Joseph otx_cpt_periodic_alarm_stop(cptvf); 435273487f7SAnoob Joseph otx_cpt_deinit_device(cptvf); 436273487f7SAnoob Joseph 4370dc1cffaSAnkur Dwivedi fail: 4380dc1cffaSAnkur Dwivedi if (cptvf) { 4390dc1cffaSAnkur Dwivedi /* Free private data allocated */ 4400dc1cffaSAnkur Dwivedi rte_free(cptvf); 4410dc1cffaSAnkur Dwivedi } 4420dc1cffaSAnkur Dwivedi 4430dc1cffaSAnkur Dwivedi return ret; 444bfe2ae49SAnoob Joseph } 445