1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
5 #include <rte_bus_pci.h>
6 #include <rte_common.h>
7 #include <rte_cryptodev.h>
8 #include <rte_cryptodev_pmd.h>
12 /* CPT common headers */
13 #include "cpt_pmd_logs.h"
15 #include "otx_cryptodev.h"
16 #include "otx_cryptodev_ops.h"
18 static int otx_cryptodev_logtype;
20 static struct rte_pci_id pci_id_cpt_table[] = {
22 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, CPT_81XX_PCI_VF_DEVICE_ID),
31 otx_cpt_logtype_init(void)
33 cpt_logtype = otx_cryptodev_logtype;
37 otx_cpt_pci_probe(struct rte_pci_driver *pci_drv,
38 struct rte_pci_device *pci_dev)
40 struct rte_cryptodev *cryptodev;
41 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
47 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
49 cryptodev = rte_cryptodev_pmd_allocate(name, rte_socket_id());
50 if (cryptodev == NULL)
53 cryptodev->device = &pci_dev->device;
54 cryptodev->device->driver = &pci_drv->driver;
55 cryptodev->driver_id = otx_cryptodev_driver_id;
57 /* init user callbacks */
58 TAILQ_INIT(&(cryptodev->link_intr_cbs));
60 /* init logtype used in common */
61 otx_cpt_logtype_init();
63 /* Invoke PMD device initialization function */
64 retval = otx_cpt_dev_create(cryptodev);
68 CPT_LOG_ERR("[DRV %s]: Failed to create device "
69 "(vendor_id: 0x%x device_id: 0x%x",
71 (unsigned int) pci_dev->id.vendor_id,
72 (unsigned int) pci_dev->id.device_id);
74 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
80 otx_cpt_pci_remove(struct rte_pci_device *pci_dev)
82 struct rte_cryptodev *cryptodev;
83 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
88 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
90 cryptodev = rte_cryptodev_pmd_get_named_dev(name);
91 if (cryptodev == NULL)
94 if (pci_dev->driver == NULL)
97 /* free crypto device */
98 rte_cryptodev_pmd_release_device(cryptodev);
100 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
101 rte_free(cryptodev->data->dev_private);
103 cryptodev->device->driver = NULL;
104 cryptodev->device = NULL;
105 cryptodev->data = NULL;
110 static struct rte_pci_driver otx_cryptodev_pmd = {
111 .id_table = pci_id_cpt_table,
112 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
113 .probe = otx_cpt_pci_probe,
114 .remove = otx_cpt_pci_remove,
117 static struct cryptodev_driver otx_cryptodev_drv;
119 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_OCTEONTX_PMD, otx_cryptodev_pmd);
120 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_OCTEONTX_PMD, pci_id_cpt_table);
121 RTE_PMD_REGISTER_CRYPTO_DRIVER(otx_cryptodev_drv, otx_cryptodev_pmd.driver,
122 otx_cryptodev_driver_id);
124 RTE_INIT(otx_cpt_init_log)
127 otx_cryptodev_logtype = rte_log_register("pmd.crypto.octeontx");
128 if (otx_cryptodev_logtype >= 0)
129 rte_log_set_level(otx_cryptodev_logtype, RTE_LOG_NOTICE);