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"
18 #define PCI_VENDOR_ID_CAVIUM 0x177d
19 #define CPT_81XX_PCI_VF_DEVICE_ID 0xa041
21 uint8_t otx_cryptodev_driver_id;
23 static struct rte_pci_id pci_id_cpt_table[] = {
25 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, CPT_81XX_PCI_VF_DEVICE_ID),
34 otx_cpt_pci_probe(struct rte_pci_driver *pci_drv,
35 struct rte_pci_device *pci_dev)
37 struct rte_cryptodev *cryptodev;
38 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
44 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
46 cryptodev = rte_cryptodev_pmd_allocate(name, rte_socket_id());
47 if (cryptodev == NULL)
50 cryptodev->device = &pci_dev->device;
51 cryptodev->device->driver = &pci_drv->driver;
52 cryptodev->driver_id = otx_cryptodev_driver_id;
54 /* init user callbacks */
55 TAILQ_INIT(&(cryptodev->link_intr_cbs));
57 /* Invoke PMD device initialization function */
58 retval = otx_cpt_dev_create(cryptodev);
62 CPT_LOG_ERR("[DRV %s]: Failed to create device "
63 "(vendor_id: 0x%x device_id: 0x%x",
65 (unsigned int) pci_dev->id.vendor_id,
66 (unsigned int) pci_dev->id.device_id);
68 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
74 otx_cpt_pci_remove(struct rte_pci_device *pci_dev)
76 struct rte_cryptodev *cryptodev;
77 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
83 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
85 cryptodev = rte_cryptodev_pmd_get_named_dev(name);
86 if (cryptodev == NULL)
89 if (pci_dev->driver == NULL)
92 dev_priv = cryptodev->data->dev_private;
94 /* free crypto device */
95 rte_cryptodev_pmd_release_device(cryptodev);
97 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
100 cryptodev->device->driver = NULL;
101 cryptodev->device = NULL;
102 cryptodev->data = NULL;
107 static struct rte_pci_driver otx_cryptodev_pmd = {
108 .id_table = pci_id_cpt_table,
109 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
110 .probe = otx_cpt_pci_probe,
111 .remove = otx_cpt_pci_remove,
114 static struct cryptodev_driver otx_cryptodev_drv;
116 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_OCTEONTX_PMD, otx_cryptodev_pmd);
117 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_OCTEONTX_PMD, pci_id_cpt_table);
118 RTE_PMD_REGISTER_KMOD_DEP(CRYPTODEV_NAME_OCTEONTX_PMD, "vfio-pci");
119 RTE_PMD_REGISTER_CRYPTO_DRIVER(otx_cryptodev_drv, otx_cryptodev_pmd.driver,
120 otx_cryptodev_driver_id);
121 RTE_LOG_REGISTER_DEFAULT(otx_cpt_logtype, NOTICE);