xref: /dpdk/drivers/common/qat/qat_device.h (revision 68a03efeed657e6e05f281479b33b51102797e15)
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_bus_pci.h>
8 
9 #include "qat_common.h"
10 #include "qat_logs.h"
11 #include "adf_transport_access_macros.h"
12 #include "qat_qp.h"
13 
14 #define QAT_DETACHED  (0)
15 #define QAT_ATTACHED  (1)
16 
17 #define QAT_DEV_NAME_MAX_LEN	64
18 
19 #define SYM_ENQ_THRESHOLD_NAME "qat_sym_enq_threshold"
20 #define ASYM_ENQ_THRESHOLD_NAME "qat_asym_enq_threshold"
21 #define COMP_ENQ_THRESHOLD_NAME "qat_comp_enq_threshold"
22 #define MAX_QP_THRESHOLD_SIZE	32
23 
24 struct qat_dev_cmd_param {
25 	const char *name;
26 	uint16_t val;
27 };
28 
29 enum qat_comp_num_im_buffers {
30 	QAT_NUM_INTERM_BUFS_GEN1 = 12,
31 	QAT_NUM_INTERM_BUFS_GEN2 = 20,
32 	QAT_NUM_INTERM_BUFS_GEN3 = 20
33 };
34 
35 struct qat_device_info {
36 	const struct rte_memzone *mz;
37 	/**< mz to store the qat_pci_device so it can be
38 	 * shared across processes
39 	 */
40 	struct rte_pci_device *pci_dev;
41 	struct rte_device sym_rte_dev;
42 	/**< This represents the crypto sym subset of this pci device.
43 	 * Register with this rather than with the one in
44 	 * pci_dev so that its driver can have a crypto-specific name
45 	 */
46 
47 	struct rte_device asym_rte_dev;
48 	/**< This represents the crypto asym subset of this pci device.
49 	 * Register with this rather than with the one in
50 	 * pci_dev so that its driver can have a crypto-specific name
51 	 */
52 
53 	struct rte_device comp_rte_dev;
54 	/**< This represents the compression subset of this pci device.
55 	 * Register with this rather than with the one in
56 	 * pci_dev so that its driver can have a compression-specific name
57 	 */
58 };
59 
60 extern struct qat_device_info qat_pci_devs[];
61 
62 struct qat_sym_dev_private;
63 struct qat_asym_dev_private;
64 struct qat_comp_dev_private;
65 
66 /*
67  * This struct holds all the data about a QAT pci device
68  * including data about all services it supports.
69  * It contains
70  *  - hw_data
71  *  - config data
72  *  - runtime data
73  * Note: as this data can be shared in a multi-process scenario,
74  * any pointers in it must also point to shared memory.
75  */
76 struct qat_pci_device {
77 
78 	/* Data used by all services */
79 	char name[QAT_DEV_NAME_MAX_LEN];
80 	/**< Name of qat pci device */
81 	uint8_t qat_dev_id;
82 	/**< Id of device instance for this qat pci device */
83 	enum qat_device_gen qat_dev_gen;
84 	/**< QAT device generation */
85 	rte_spinlock_t arb_csr_lock;
86 	/**< lock to protect accesses to the arbiter CSR */
87 
88 	struct qat_qp *qps_in_use[QAT_MAX_SERVICES][ADF_MAX_QPS_ON_ANY_SERVICE];
89 	/**< links to qps set up for each service, index same as on API */
90 
91 	/* Data relating to symmetric crypto service */
92 	struct qat_sym_dev_private *sym_dev;
93 	/**< link back to cryptodev private data */
94 
95 	int qat_sym_driver_id;
96 	/**< Symmetric driver id used by this device */
97 
98 	/* Data relating to asymmetric crypto service */
99 	struct qat_asym_dev_private *asym_dev;
100 	/**< link back to cryptodev private data */
101 
102 	int qat_asym_driver_id;
103 	/**< Symmetric driver id used by this device */
104 
105 	/* Data relating to compression service */
106 	struct qat_comp_dev_private *comp_dev;
107 	/**< link back to compressdev private data */
108 };
109 
110 struct qat_gen_hw_data {
111 	enum qat_device_gen dev_gen;
112 	const struct qat_qp_hw_data (*qp_hw_data)[ADF_MAX_QPS_ON_ANY_SERVICE];
113 	enum qat_comp_num_im_buffers comp_num_im_bufs_required;
114 };
115 
116 extern struct qat_gen_hw_data qat_gen_config[];
117 
118 struct qat_pci_device *
119 qat_pci_device_allocate(struct rte_pci_device *pci_dev,
120 		struct qat_dev_cmd_param *qat_dev_cmd_param);
121 
122 struct qat_pci_device *
123 qat_get_qat_dev_from_pci_dev(struct rte_pci_device *pci_dev);
124 
125 /* declaration needed for weak functions */
126 int
127 qat_sym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused,
128 		struct qat_dev_cmd_param *qat_dev_cmd_param);
129 
130 int
131 qat_asym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused,
132 		struct qat_dev_cmd_param *qat_dev_cmd_param);
133 
134 int
135 qat_sym_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused);
136 
137 int
138 qat_asym_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused);
139 
140 int
141 qat_comp_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused,
142 		struct qat_dev_cmd_param *qat_dev_cmd_param);
143 
144 int
145 qat_comp_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused);
146 
147 #endif /* _QAT_DEVICE_H_ */
148