f808e16a51f51f1fe6c423910b9d29ca935f83dd
[dpdk.git] / qat_qp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4 #ifndef _QAT_QP_H_
5 #define _QAT_QP_H_
6
7 #include "qat_common.h"
8 #include <rte_cryptodev_pmd.h>
9 #include "adf_transport_access_macros.h"
10
11 #define QAT_CSR_HEAD_WRITE_THRESH 32U
12 /* number of requests to accumulate before writing head CSR */
13 #define QAT_CSR_TAIL_WRITE_THRESH 32U
14 /* number of requests to accumulate before writing tail CSR */
15 #define QAT_CSR_TAIL_FORCE_WRITE_THRESH 256U
16 /* number of inflights below which no tail write coalescing should occur */
17
18 typedef int (*build_request_t)(void *op,
19                 uint8_t *req, void *op_cookie,
20                 enum qat_device_gen qat_dev_gen);
21 /**< Build a request from an op. */
22
23 typedef int (*process_response_t)(void **ops,
24                 uint8_t *resp, void *op_cookie,
25                 enum qat_device_gen qat_dev_gen);
26 /**< Process a response descriptor and return the associated op. */
27
28 /**
29  * Structure with data needed for creation of queue pair.
30  */
31 struct qat_qp_hw_data {
32         enum qat_service_type service_type;
33         uint8_t hw_bundle_num;
34         uint8_t tx_ring_num;
35         uint8_t rx_ring_num;
36         uint16_t tx_msg_size;
37         uint16_t rx_msg_size;
38 };
39 /**
40  * Structure with data needed for creation of queue pair.
41  */
42 struct qat_qp_config {
43         const struct qat_qp_hw_data *hw;
44         uint32_t nb_descriptors;
45         uint32_t cookie_size;
46         int socket_id;
47         build_request_t build_request;
48         process_response_t process_response;
49         const char *service_str;
50 };
51
52 /**
53  * Structure associated with each queue.
54  */
55 struct qat_queue {
56         char            memz_name[RTE_MEMZONE_NAMESIZE];
57         void            *base_addr;             /* Base address */
58         rte_iova_t      base_phys_addr;         /* Queue physical address */
59         uint32_t        head;                   /* Shadow copy of the head */
60         uint32_t        tail;                   /* Shadow copy of the tail */
61         uint32_t        modulo;
62         uint32_t        msg_size;
63         uint16_t        max_inflights;
64         uint32_t        queue_size;
65         uint8_t         hw_bundle_number;
66         uint8_t         hw_queue_number;
67         /* HW queue aka ring offset on bundle */
68         uint32_t        csr_head;               /* last written head value */
69         uint32_t        csr_tail;               /* last written tail value */
70         uint16_t        nb_processed_responses;
71         /* number of responses processed since last CSR head write */
72         uint16_t        nb_pending_requests;
73         /* number of requests pending since last CSR tail write */
74 };
75
76 struct qat_qp {
77         void                    *mmap_bar_addr;
78         uint16_t                inflights16;
79         struct  qat_queue       tx_q;
80         struct  qat_queue       rx_q;
81         struct  rte_cryptodev_stats stats;
82         struct rte_mempool *op_cookie_pool;
83         void **op_cookies;
84         uint32_t nb_descriptors;
85         enum qat_device_gen qat_dev_gen;
86         build_request_t build_request;
87         process_response_t process_response;
88         struct qat_pmd_private *qat_dev;
89         /**< qat device this qp is on */
90 } __rte_cache_aligned;
91
92 extern const struct qat_qp_hw_data qat_gen1_qps[][ADF_MAX_QPS_PER_BUNDLE];
93
94 uint16_t
95 qat_enqueue_op_burst(void *qp, void **ops, uint16_t nb_ops);
96
97 uint16_t
98 qat_dequeue_op_burst(void *qp, void **ops, uint16_t nb_ops);
99
100 int
101 qat_qp_release(struct qat_qp **qp_addr);
102
103 int
104 qat_qp_setup(struct qat_pmd_private *qat_dev,
105                 struct qat_qp **qp_addr, uint16_t queue_pair_id,
106                 struct qat_qp_config *qat_qp_conf);
107
108 int
109 qat_qps_per_service(const struct qat_qp_hw_data *qp_hw_data,
110                         enum qat_service_type service);
111 #endif /* _QAT_QP_H_ */