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 #include "otx_cryptodev.h"
13 #include "otx_cryptodev_ops.h"
15 #include "cpt_pmd_logs.h"
17 uint8_t otx_cryptodev_driver_id;
19 static struct rte_pci_id pci_id_cpt_table[] = {
21 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, CPT_81XX_PCI_VF_DEVICE_ID),
30 otx_cpt_pci_probe(struct rte_pci_driver *pci_drv,
31 struct rte_pci_device *pci_dev)
33 struct rte_cryptodev *cryptodev;
34 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
40 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
42 cryptodev = rte_cryptodev_pmd_allocate(name, rte_socket_id());
43 if (cryptodev == NULL)
46 cryptodev->device = &pci_dev->device;
47 cryptodev->device->driver = &pci_drv->driver;
48 cryptodev->driver_id = otx_cryptodev_driver_id;
50 /* init user callbacks */
51 TAILQ_INIT(&(cryptodev->link_intr_cbs));
53 /* Invoke PMD device initialization function */
54 retval = otx_cpt_dev_create(cryptodev);
58 CPT_LOG_ERR("[DRV %s]: Failed to create device "
59 "(vendor_id: 0x%x device_id: 0x%x",
61 (unsigned int) pci_dev->id.vendor_id,
62 (unsigned int) pci_dev->id.device_id);
64 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
70 otx_cpt_pci_remove(struct rte_pci_device *pci_dev)
72 struct rte_cryptodev *cryptodev;
73 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
78 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
80 cryptodev = rte_cryptodev_pmd_get_named_dev(name);
81 if (cryptodev == NULL)
84 if (pci_dev->driver == NULL)
87 /* free crypto device */
88 rte_cryptodev_pmd_release_device(cryptodev);
90 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
91 rte_free(cryptodev->data->dev_private);
93 cryptodev->device->driver = NULL;
94 cryptodev->device = NULL;
95 cryptodev->data = NULL;
100 static struct rte_pci_driver otx_cryptodev_pmd = {
101 .id_table = pci_id_cpt_table,
102 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
103 .probe = otx_cpt_pci_probe,
104 .remove = otx_cpt_pci_remove,
107 static struct cryptodev_driver otx_cryptodev_drv;
109 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_OCTEONTX_PMD, otx_cryptodev_pmd);
110 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_OCTEONTX_PMD, pci_id_cpt_table);
111 RTE_PMD_REGISTER_KMOD_DEP(CRYPTODEV_NAME_OCTEONTX_PMD, "vfio-pci");
112 RTE_PMD_REGISTER_CRYPTO_DRIVER(otx_cryptodev_drv, otx_cryptodev_pmd.driver,
113 otx_cryptodev_driver_id);
114 RTE_LOG_REGISTER_DEFAULT(otx_cpt_logtype, NOTICE);