net/cxgbe: support updating RSS hash configuration and key
[dpdk.git] / drivers / crypto / qat / rte_qat_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2017 Intel Corporation
3  */
4
5 #include <rte_bus_pci.h>
6 #include <rte_common.h>
7 #include <rte_dev.h>
8 #include <rte_malloc.h>
9 #include <rte_pci.h>
10 #include <rte_cryptodev_pmd.h>
11
12 #include "qat_crypto.h"
13 #include "qat_logs.h"
14
15 uint8_t cryptodev_qat_driver_id;
16
17 static const struct rte_cryptodev_capabilities qat_gen1_capabilities[] = {
18         QAT_BASE_GEN1_SYM_CAPABILITIES,
19         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
20 };
21
22 static const struct rte_cryptodev_capabilities qat_gen2_capabilities[] = {
23         QAT_BASE_GEN1_SYM_CAPABILITIES,
24         QAT_EXTRA_GEN2_SYM_CAPABILITIES,
25         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
26 };
27
28 static struct rte_cryptodev_ops crypto_qat_ops = {
29
30                 /* Device related operations */
31                 .dev_configure          = qat_dev_config,
32                 .dev_start              = qat_dev_start,
33                 .dev_stop               = qat_dev_stop,
34                 .dev_close              = qat_dev_close,
35                 .dev_infos_get          = qat_dev_info_get,
36
37                 .stats_get              = qat_crypto_sym_stats_get,
38                 .stats_reset            = qat_crypto_sym_stats_reset,
39                 .queue_pair_setup       = qat_crypto_sym_qp_setup,
40                 .queue_pair_release     = qat_crypto_sym_qp_release,
41                 .queue_pair_start       = NULL,
42                 .queue_pair_stop        = NULL,
43                 .queue_pair_count       = NULL,
44
45                 /* Crypto related operations */
46                 .session_get_size       = qat_crypto_sym_get_session_private_size,
47                 .session_configure      = qat_crypto_sym_configure_session,
48                 .session_clear          = qat_crypto_sym_clear_session
49 };
50
51 /*
52  * The set of PCI devices this driver supports
53  */
54
55 static const struct rte_pci_id pci_id_qat_map[] = {
56                 {
57                         RTE_PCI_DEVICE(0x8086, 0x0443),
58                 },
59                 {
60                         RTE_PCI_DEVICE(0x8086, 0x37c9),
61                 },
62                 {
63                         RTE_PCI_DEVICE(0x8086, 0x19e3),
64                 },
65                 {
66                         RTE_PCI_DEVICE(0x8086, 0x6f55),
67                 },
68                 {.device_id = 0},
69 };
70
71 static int
72 crypto_qat_create(const char *name, struct rte_pci_device *pci_dev,
73                 struct rte_cryptodev_pmd_init_params *init_params)
74 {
75         struct rte_cryptodev *cryptodev;
76         struct qat_pmd_private *internals;
77
78         PMD_INIT_FUNC_TRACE();
79
80         cryptodev = rte_cryptodev_pmd_create(name, &pci_dev->device,
81                         init_params);
82         if (cryptodev == NULL)
83                 return -ENODEV;
84
85         cryptodev->driver_id = cryptodev_qat_driver_id;
86         cryptodev->dev_ops = &crypto_qat_ops;
87
88         cryptodev->enqueue_burst = qat_pmd_enqueue_op_burst;
89         cryptodev->dequeue_burst = qat_pmd_dequeue_op_burst;
90
91         cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
92                         RTE_CRYPTODEV_FF_HW_ACCELERATED |
93                         RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
94                         RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
95
96         internals = cryptodev->data->dev_private;
97         internals->max_nb_sessions = init_params->max_nb_sessions;
98         switch (pci_dev->id.device_id) {
99         case 0x0443:
100                 internals->qat_dev_gen = QAT_GEN1;
101                 internals->qat_dev_capabilities = qat_gen1_capabilities;
102                 break;
103         case 0x37c9:
104         case 0x19e3:
105         case 0x6f55:
106                 internals->qat_dev_gen = QAT_GEN2;
107                 internals->qat_dev_capabilities = qat_gen2_capabilities;
108                 break;
109         default:
110                 PMD_DRV_LOG(ERR,
111                         "Invalid dev_id, can't determine capabilities");
112                 break;
113         }
114
115         /*
116          * For secondary processes, we don't initialise any further as primary
117          * has already done this work. Only check we don't need a different
118          * RX function
119          */
120         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
121                 PMD_DRV_LOG(DEBUG, "Device already initialised by primary process");
122                 return 0;
123         }
124
125         return 0;
126 }
127
128 static int crypto_qat_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
129                 struct rte_pci_device *pci_dev)
130 {
131         struct rte_cryptodev_pmd_init_params init_params = {
132                 .name = "",
133                 .socket_id = rte_socket_id(),
134                 .private_data_size = sizeof(struct qat_pmd_private),
135                 .max_nb_sessions = RTE_QAT_PMD_MAX_NB_SESSIONS
136         };
137         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
138
139         PMD_DRV_LOG(DEBUG, "Found QAT device at %02x:%02x.%x",
140                         pci_dev->addr.bus,
141                         pci_dev->addr.devid,
142                         pci_dev->addr.function);
143
144         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
145
146         return crypto_qat_create(name, pci_dev, &init_params);
147 }
148
149 static int crypto_qat_pci_remove(struct rte_pci_device *pci_dev)
150 {
151         struct rte_cryptodev *cryptodev;
152         char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
153
154         if (pci_dev == NULL)
155                 return -EINVAL;
156
157         rte_pci_device_name(&pci_dev->addr, cryptodev_name,
158                         sizeof(cryptodev_name));
159
160         cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
161         if (cryptodev == NULL)
162                 return -ENODEV;
163
164         /* free crypto device */
165         return rte_cryptodev_pmd_destroy(cryptodev);
166 }
167
168 static struct rte_pci_driver rte_qat_pmd = {
169         .id_table = pci_id_qat_map,
170         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
171         .probe = crypto_qat_pci_probe,
172         .remove = crypto_qat_pci_remove
173 };
174
175 static struct cryptodev_driver qat_crypto_drv;
176
177 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_QAT_SYM_PMD, rte_qat_pmd);
178 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_QAT_SYM_PMD, pci_id_qat_map);
179 RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv, rte_qat_pmd,
180                 cryptodev_qat_driver_id);