net/ice: set min and max MTU
[dpdk.git] / drivers / crypto / octeontx / otx_cryptodev.c
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 /* CPT common headers */
13 #include "cpt_pmd_logs.h"
14
15 #include "otx_cryptodev.h"
16 #include "otx_cryptodev_ops.h"
17
18 static int otx_cryptodev_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 void
31 otx_cpt_logtype_init(void)
32 {
33         cpt_logtype = otx_cryptodev_logtype;
34 }
35
36 static int
37 otx_cpt_pci_probe(struct rte_pci_driver *pci_drv,
38                         struct rte_pci_device *pci_dev)
39 {
40         struct rte_cryptodev *cryptodev;
41         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
42         int retval;
43
44         if (pci_drv == NULL)
45                 return -ENODEV;
46
47         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
48
49         cryptodev = rte_cryptodev_pmd_allocate(name, rte_socket_id());
50         if (cryptodev == NULL)
51                 return -ENOMEM;
52
53         cryptodev->device = &pci_dev->device;
54         cryptodev->device->driver = &pci_drv->driver;
55         cryptodev->driver_id = otx_cryptodev_driver_id;
56
57         /* init user callbacks */
58         TAILQ_INIT(&(cryptodev->link_intr_cbs));
59
60         /* init logtype used in common */
61         otx_cpt_logtype_init();
62
63         /* Invoke PMD device initialization function */
64         retval = otx_cpt_dev_create(cryptodev);
65         if (retval == 0)
66                 return 0;
67
68         CPT_LOG_ERR("[DRV %s]: Failed to create device "
69                         "(vendor_id: 0x%x device_id: 0x%x",
70                         pci_drv->driver.name,
71                         (unsigned int) pci_dev->id.vendor_id,
72                         (unsigned int) pci_dev->id.device_id);
73
74         cryptodev->attached = RTE_CRYPTODEV_DETACHED;
75
76         return -ENXIO;
77 }
78
79 static int
80 otx_cpt_pci_remove(struct rte_pci_device *pci_dev)
81 {
82         struct rte_cryptodev *cryptodev;
83         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
84
85         if (pci_dev == NULL)
86                 return -EINVAL;
87
88         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
89
90         cryptodev = rte_cryptodev_pmd_get_named_dev(name);
91         if (cryptodev == NULL)
92                 return -ENODEV;
93
94         if (pci_dev->driver == NULL)
95                 return -ENODEV;
96
97         /* free crypto device */
98         rte_cryptodev_pmd_release_device(cryptodev);
99
100         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
101                 rte_free(cryptodev->data->dev_private);
102
103         cryptodev->device->driver = NULL;
104         cryptodev->device = NULL;
105         cryptodev->data = NULL;
106
107         return 0;
108 }
109
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,
115 };
116
117 static struct cryptodev_driver otx_cryptodev_drv;
118
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);
123
124 RTE_INIT(otx_cpt_init_log)
125 {
126         /* Bus level logs */
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);
130 }