crypto/octeontx2: support control ops
[dpdk.git] / drivers / crypto / octeontx2 / otx2_cryptodev_ops.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2019 Marvell International Ltd.
3  */
4
5 #include <rte_cryptodev_pmd.h>
6
7 #include "otx2_cryptodev.h"
8 #include "otx2_cryptodev_hw_access.h"
9 #include "otx2_cryptodev_mbox.h"
10 #include "otx2_cryptodev_ops.h"
11 #include "otx2_mbox.h"
12
13 #include "cpt_hw_types.h"
14 #include "cpt_pmd_logs.h"
15
16 /* PMD ops */
17
18 static int
19 otx2_cpt_dev_config(struct rte_cryptodev *dev,
20                     struct rte_cryptodev_config *conf)
21 {
22         struct otx2_cpt_vf *vf = dev->data->dev_private;
23         int ret;
24
25         if (conf->nb_queue_pairs > vf->max_queues) {
26                 CPT_LOG_ERR("Invalid number of queue pairs requested");
27                 return -EINVAL;
28         }
29
30         dev->feature_flags &= ~conf->ff_disable;
31
32         /* Unregister error interrupts */
33         if (vf->err_intr_registered)
34                 otx2_cpt_err_intr_unregister(dev);
35
36         /* Detach queues */
37         if (vf->nb_queues) {
38                 ret = otx2_cpt_queues_detach(dev);
39                 if (ret) {
40                         CPT_LOG_ERR("Could not detach CPT queues");
41                         return ret;
42                 }
43         }
44
45         /* Attach queues */
46         ret = otx2_cpt_queues_attach(dev, conf->nb_queue_pairs);
47         if (ret) {
48                 CPT_LOG_ERR("Could not attach CPT queues");
49                 return -ENODEV;
50         }
51
52         ret = otx2_cpt_msix_offsets_get(dev);
53         if (ret) {
54                 CPT_LOG_ERR("Could not get MSI-X offsets");
55                 goto queues_detach;
56         }
57
58         /* Register error interrupts */
59         ret = otx2_cpt_err_intr_register(dev);
60         if (ret) {
61                 CPT_LOG_ERR("Could not register error interrupts");
62                 goto queues_detach;
63         }
64
65         rte_mb();
66         return 0;
67
68 queues_detach:
69         otx2_cpt_queues_detach(dev);
70         return ret;
71 }
72
73 static int
74 otx2_cpt_dev_start(struct rte_cryptodev *dev)
75 {
76         RTE_SET_USED(dev);
77
78         CPT_PMD_INIT_FUNC_TRACE();
79
80         return 0;
81 }
82
83 static void
84 otx2_cpt_dev_stop(struct rte_cryptodev *dev)
85 {
86         RTE_SET_USED(dev);
87
88         CPT_PMD_INIT_FUNC_TRACE();
89 }
90
91 static int
92 otx2_cpt_dev_close(struct rte_cryptodev *dev)
93 {
94         struct otx2_cpt_vf *vf = dev->data->dev_private;
95         int ret = 0;
96
97         /* Unregister error interrupts */
98         if (vf->err_intr_registered)
99                 otx2_cpt_err_intr_unregister(dev);
100
101         /* Detach queues */
102         if (vf->nb_queues) {
103                 ret = otx2_cpt_queues_detach(dev);
104                 if (ret)
105                         CPT_LOG_ERR("Could not detach CPT queues");
106         }
107
108         return ret;
109 }
110
111 static void
112 otx2_cpt_dev_info_get(struct rte_cryptodev *dev,
113                       struct rte_cryptodev_info *info)
114 {
115         struct otx2_cpt_vf *vf = dev->data->dev_private;
116
117         if (info != NULL) {
118                 info->max_nb_queue_pairs = vf->max_queues;
119                 info->feature_flags = dev->feature_flags;
120                 info->capabilities = NULL;
121                 info->sym.max_nb_sessions = 0;
122                 info->driver_id = otx2_cryptodev_driver_id;
123                 info->min_mbuf_headroom_req = OTX2_CPT_MIN_HEADROOM_REQ;
124                 info->min_mbuf_tailroom_req = OTX2_CPT_MIN_TAILROOM_REQ;
125         }
126 }
127
128 struct rte_cryptodev_ops otx2_cpt_ops = {
129         /* Device control ops */
130         .dev_configure = otx2_cpt_dev_config,
131         .dev_start = otx2_cpt_dev_start,
132         .dev_stop = otx2_cpt_dev_stop,
133         .dev_close = otx2_cpt_dev_close,
134         .dev_infos_get = otx2_cpt_dev_info_get,
135
136         .stats_get = NULL,
137         .stats_reset = NULL,
138         .queue_pair_setup = NULL,
139         .queue_pair_release = NULL,
140         .queue_pair_count = NULL,
141
142         /* Symmetric crypto ops */
143         .sym_session_get_size = NULL,
144         .sym_session_configure = NULL,
145         .sym_session_clear = NULL,
146 };