1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Cavium, Inc 3 */ 4 5 #include <rte_bus_pci.h> 6 #include <rte_common.h> 7 #include <rte_cryptodev.h> 8 #include <rte_cryptodev_pmd.h> 9 #include <rte_log.h> 10 #include <rte_pci.h> 11 12 #include "otx_cryptodev.h" 13 #include "otx_cryptodev_ops.h" 14 15 #include "cpt_pmd_logs.h" 16 17 uint8_t otx_cryptodev_driver_id; 18 int otx_cpt_logtype; 19 20 static struct rte_pci_id pci_id_cpt_table[] = { 21 { 22 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, CPT_81XX_PCI_VF_DEVICE_ID), 23 }, 24 /* sentinel */ 25 { 26 .device_id = 0 27 }, 28 }; 29 30 static int 31 otx_cpt_pci_probe(struct rte_pci_driver *pci_drv, 32 struct rte_pci_device *pci_dev) 33 { 34 struct rte_cryptodev *cryptodev; 35 char name[RTE_CRYPTODEV_NAME_MAX_LEN]; 36 int retval; 37 38 if (pci_drv == NULL) 39 return -ENODEV; 40 41 rte_pci_device_name(&pci_dev->addr, name, sizeof(name)); 42 43 cryptodev = rte_cryptodev_pmd_allocate(name, rte_socket_id()); 44 if (cryptodev == NULL) 45 return -ENOMEM; 46 47 cryptodev->device = &pci_dev->device; 48 cryptodev->device->driver = &pci_drv->driver; 49 cryptodev->driver_id = otx_cryptodev_driver_id; 50 51 /* init user callbacks */ 52 TAILQ_INIT(&(cryptodev->link_intr_cbs)); 53 54 /* Invoke PMD device initialization function */ 55 retval = otx_cpt_dev_create(cryptodev); 56 if (retval == 0) 57 return 0; 58 59 CPT_LOG_ERR("[DRV %s]: Failed to create device " 60 "(vendor_id: 0x%x device_id: 0x%x", 61 pci_drv->driver.name, 62 (unsigned int) pci_dev->id.vendor_id, 63 (unsigned int) pci_dev->id.device_id); 64 65 cryptodev->attached = RTE_CRYPTODEV_DETACHED; 66 67 return -ENXIO; 68 } 69 70 static int 71 otx_cpt_pci_remove(struct rte_pci_device *pci_dev) 72 { 73 struct rte_cryptodev *cryptodev; 74 char name[RTE_CRYPTODEV_NAME_MAX_LEN]; 75 76 if (pci_dev == NULL) 77 return -EINVAL; 78 79 rte_pci_device_name(&pci_dev->addr, name, sizeof(name)); 80 81 cryptodev = rte_cryptodev_pmd_get_named_dev(name); 82 if (cryptodev == NULL) 83 return -ENODEV; 84 85 if (pci_dev->driver == NULL) 86 return -ENODEV; 87 88 /* free crypto device */ 89 rte_cryptodev_pmd_release_device(cryptodev); 90 91 if (rte_eal_process_type() == RTE_PROC_PRIMARY) 92 rte_free(cryptodev->data->dev_private); 93 94 cryptodev->device->driver = NULL; 95 cryptodev->device = NULL; 96 cryptodev->data = NULL; 97 98 return 0; 99 } 100 101 static struct rte_pci_driver otx_cryptodev_pmd = { 102 .id_table = pci_id_cpt_table, 103 .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 104 .probe = otx_cpt_pci_probe, 105 .remove = otx_cpt_pci_remove, 106 }; 107 108 static struct cryptodev_driver otx_cryptodev_drv; 109 110 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_OCTEONTX_PMD, otx_cryptodev_pmd); 111 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_OCTEONTX_PMD, pci_id_cpt_table); 112 RTE_PMD_REGISTER_KMOD_DEP(CRYPTODEV_NAME_OCTEONTX_PMD, "vfio-pci"); 113 RTE_PMD_REGISTER_CRYPTO_DRIVER(otx_cryptodev_drv, otx_cryptodev_pmd.driver, 114 otx_cryptodev_driver_id); 115 116 RTE_INIT(otx_cpt_init_log) 117 { 118 /* Bus level logs */ 119 otx_cpt_logtype = rte_log_register("pmd.crypto.octeontx"); 120 if (otx_cpt_logtype >= 0) 121 rte_log_set_level(otx_cpt_logtype, RTE_LOG_NOTICE); 122 } 123