d1615e2a7ef1caaa988754657f318626cabba159
[dpdk.git] / drivers / crypto / qat / qat_device.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4 #ifndef _QAT_DEVICE_H_
5 #define _QAT_DEVICE_H_
6
7 #include <rte_cryptodev_pmd.h>
8 #include <rte_bus_pci.h>
9 #include "qat_common.h"
10 #include "qat_logs.h"
11 #include "adf_transport_access_macros.h"
12 #include "qat_qp.h"
13
14
15 #define QAT_DETACHED  (0)
16 #define QAT_ATTACHED  (1)
17
18 #define QAT_MAX_PCI_DEVICES     48
19 #define QAT_DEV_NAME_MAX_LEN    64
20
21
22 extern uint8_t cryptodev_qat_driver_id;
23
24 extern int qat_sym_qp_release(struct rte_cryptodev *dev,
25         uint16_t queue_pair_id);
26
27 /*
28  * This struct holds all the data about a QAT pci device
29  * including data about all services it supports.
30  * It contains
31  *  - hw_data
32  *  - config data
33  *  - runtime data
34  */
35 struct qat_sym_dev_private;
36 struct qat_pci_device {
37
38         /* Data used by all services */
39         char name[QAT_DEV_NAME_MAX_LEN];
40         /**< Name of qat pci device */
41         uint8_t qat_dev_id;
42         /**< Device instance for this qat pci device */
43         struct rte_pci_device *pci_dev;
44         /**< PCI information. */
45         enum qat_device_gen qat_dev_gen;
46         /**< QAT device generation */
47         rte_spinlock_t arb_csr_lock;
48         /**< lock to protect accesses to the arbiter CSR */
49         __extension__
50         uint8_t attached : 1;
51         /**< Flag indicating the device is attached */
52
53         struct qat_qp *qps_in_use[QAT_MAX_SERVICES][ADF_MAX_QPS_PER_BUNDLE];
54         /**< links to qps set up for each service, index same as on API */
55
56         /* Data relating to symmetric crypto service */
57         struct qat_sym_dev_private *sym_dev;
58         /**< link back to cryptodev private data */
59
60         /* Data relating to compression service */
61
62         /* Data relating to asymmetric crypto service */
63
64 };
65
66 /** private data structure for a QAT device.
67  * This QAT device is a device offering only symmetric crypto service,
68  * there can be one of these on each qat_pci_device (VF),
69  * in future there may also be private data structures for other services.
70  */
71 struct qat_sym_dev_private {
72         struct qat_pci_device *qat_dev;
73         /**< The qat pci device hosting the service */
74         uint8_t sym_dev_id;
75         /**< Device instance for this rte_cryptodev */
76         const struct rte_cryptodev_capabilities *qat_dev_capabilities;
77         /* QAT device symmetric crypto capabilities */
78 };
79
80 struct qat_gen_hw_data {
81         enum qat_device_gen dev_gen;
82         const struct qat_qp_hw_data (*qp_hw_data)[ADF_MAX_QPS_PER_BUNDLE];
83 };
84
85 extern struct qat_gen_hw_data qp_gen_config[];
86
87 int qat_dev_config(struct rte_cryptodev *dev,
88                 struct rte_cryptodev_config *config);
89 int qat_dev_start(struct rte_cryptodev *dev);
90 void qat_dev_stop(struct rte_cryptodev *dev);
91 int qat_dev_close(struct rte_cryptodev *dev);
92 void qat_sym_dev_info_get(struct rte_cryptodev *dev,
93         struct rte_cryptodev_info *info);
94
95 struct qat_pci_device *
96 qat_pci_device_allocate(struct rte_pci_device *pci_dev);
97 int
98 qat_pci_device_release(struct rte_pci_device *pci_dev);
99 struct qat_pci_device *
100 qat_get_qat_dev_from_pci_dev(struct rte_pci_device *pci_dev);
101
102 #endif /* _QAT_DEVICE_H_ */