crypto/qat: add PCI device struct
[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_pci_device {
36
37         /* data used by all services */
38         char name[QAT_DEV_NAME_MAX_LEN];
39         /**< Name of qat pci device */
40         struct rte_pci_device *pci_dev;
41         /**< PCI information. */
42         enum qat_device_gen qat_dev_gen;
43         /**< QAT device generation */
44         rte_spinlock_t arb_csr_lock;
45         /* protects accesses to the arbiter CSR */
46         __extension__
47         uint8_t attached : 1;
48         /**< Flag indicating the device is attached */
49
50         /* data relating to symmetric crypto service */
51         struct qat_pmd_private *sym_dev;
52         /**< link back to cryptodev private data */
53         unsigned int max_nb_sym_queue_pairs;
54         /**< Max number of queue pairs supported by device */
55
56         /* data relating to compression service */
57
58         /* data relating to asymmetric crypto service */
59
60 };
61
62 /** private data structure for a QAT device.
63  * This QAT device is a device offering only symmetric crypto service,
64  * there can be one of these on each qat_pci_device (VF),
65  * in future there may also be private data structures for other services.
66  */
67 struct qat_pmd_private {
68         unsigned int max_nb_queue_pairs;
69         /**< Max number of queue pairs supported by device */
70         unsigned int max_nb_sessions;
71         /**< Max number of sessions supported by device */
72         enum qat_device_gen qat_dev_gen;
73         /**< QAT device generation */
74         const struct rte_cryptodev_capabilities *qat_dev_capabilities;
75         /* QAT device capabilities */
76         struct rte_pci_device *pci_dev;
77         /**< PCI information. */
78         uint8_t dev_id;
79         /**< Device ID for this instance */
80         struct qat_pci_device *qat_dev;
81         /**< The qat pci device hosting the service */
82 };
83
84 struct qat_gen_hw_data {
85         enum qat_device_gen dev_gen;
86         const struct qat_qp_hw_data (*qp_hw_data)[ADF_MAX_QPS_PER_BUNDLE];
87 };
88
89 extern struct qat_gen_hw_data qp_gen_config[];
90
91 int qat_dev_config(struct rte_cryptodev *dev,
92                 struct rte_cryptodev_config *config);
93 int qat_dev_start(struct rte_cryptodev *dev);
94 void qat_dev_stop(struct rte_cryptodev *dev);
95 int qat_dev_close(struct rte_cryptodev *dev);
96 void qat_dev_info_get(struct rte_cryptodev *dev,
97         struct rte_cryptodev_info *info);
98
99 struct qat_pci_device *
100 qat_pci_device_allocate(struct rte_pci_device *pci_dev);
101 int
102 qat_pci_device_release(struct rte_pci_device *pci_dev);
103 struct qat_pci_device *
104 qat_get_qat_dev_from_pci_dev(struct rte_pci_device *pci_dev);
105
106 #endif /* _QAT_DEVICE_H_ */