crypto/octeontx2: add PMD skeleton
[dpdk.git] / drivers / crypto / octeontx2 / otx2_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2019 Marvell International Ltd.
3  */
4
5 #include <rte_bus_pci.h>
6 #include <rte_common.h>
7 #include <rte_crypto.h>
8 #include <rte_cryptodev.h>
9 #include <rte_cryptodev_pmd.h>
10 #include <rte_dev.h>
11 #include <rte_errno.h>
12 #include <rte_mempool.h>
13 #include <rte_pci.h>
14
15 #include "otx2_common.h"
16 #include "otx2_cryptodev.h"
17 #include "otx2_cryptodev_ops.h"
18
19 /* CPT common headers */
20 #include "cpt_common.h"
21 #include "cpt_pmd_logs.h"
22
23 int otx2_cpt_logtype;
24
25 static struct rte_pci_id pci_id_cpt_table[] = {
26         {
27                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
28                                PCI_DEVID_OCTEONTX2_RVU_CPT_VF)
29         },
30         /* sentinel */
31         {
32                 .device_id = 0
33         },
34 };
35
36 static int
37 otx2_cpt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
38                    struct rte_pci_device *pci_dev)
39 {
40         struct rte_cryptodev_pmd_init_params init_params = {
41                 .name = "",
42                 .socket_id = rte_socket_id(),
43                 .private_data_size = sizeof(struct otx2_cpt_vf)
44         };
45         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
46         struct rte_cryptodev *dev;
47         int ret;
48
49         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
50
51         dev = rte_cryptodev_pmd_create(name, &pci_dev->device, &init_params);
52         if (dev == NULL) {
53                 ret = -ENODEV;
54                 goto exit;
55         }
56
57         dev->dev_ops = &otx2_cpt_ops;
58
59         dev->driver_id = otx2_cryptodev_driver_id;
60
61         dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
62                              RTE_CRYPTODEV_FF_HW_ACCELERATED;
63
64         return 0;
65
66 exit:
67         CPT_LOG_ERR("Could not create device (vendor_id: 0x%x device_id: 0x%x)",
68                     pci_dev->id.vendor_id, pci_dev->id.device_id);
69         return ret;
70 }
71
72 static int
73 otx2_cpt_pci_remove(struct rte_pci_device *pci_dev)
74 {
75         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
76         struct rte_cryptodev *dev;
77
78         if (pci_dev == NULL)
79                 return -EINVAL;
80
81         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
82
83         dev = rte_cryptodev_pmd_get_named_dev(name);
84         if (dev == NULL)
85                 return -ENODEV;
86
87         return rte_cryptodev_pmd_destroy(dev);
88 }
89
90 static struct rte_pci_driver otx2_cryptodev_pmd = {
91         .id_table = pci_id_cpt_table,
92         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
93         .probe = otx2_cpt_pci_probe,
94         .remove = otx2_cpt_pci_remove,
95 };
96
97 static struct cryptodev_driver otx2_cryptodev_drv;
98
99 RTE_INIT(otx2_cpt_init_log);
100 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_OCTEONTX2_PMD, otx2_cryptodev_pmd);
101 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_OCTEONTX2_PMD, pci_id_cpt_table);
102 RTE_PMD_REGISTER_CRYPTO_DRIVER(otx2_cryptodev_drv, otx2_cryptodev_pmd.driver,
103                 otx2_cryptodev_driver_id);
104
105 RTE_INIT(otx2_cpt_init_log)
106 {
107         /* Bus level logs */
108         otx2_cpt_logtype = rte_log_register("pmd.crypto.octeontx2");
109         if (otx2_cpt_logtype >= 0)
110                 rte_log_set_level(otx2_cpt_logtype, RTE_LOG_NOTICE);
111 }