52c487956e005c99e67bcc99f8e0e44a89e59ef0
[dpdk.git] / drivers / crypto / bcmfs / bcmfs_qp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _BCMFS_QP_H_
7 #define _BCMFS_QP_H_
8
9 #include <rte_memzone.h>
10
11 /* Maximum number of h/w queues supported by device */
12 #define BCMFS_MAX_HW_QUEUES             32
13
14 /* H/W queue IO address space len */
15 #define BCMFS_HW_QUEUE_IO_ADDR_LEN      (64 * 1024)
16
17 /* Maximum size of device ops name */
18 #define BCMFS_HW_OPS_NAMESIZE           32
19
20 enum bcmfs_queue_type {
21         /* TX or submission queue */
22         BCMFS_RM_TXQ,
23          /* Completion or receive queue */
24         BCMFS_RM_CPLQ
25 };
26
27 struct bcmfs_qp_stats {
28         /* Count of all operations enqueued */
29         uint64_t enqueued_count;
30         /* Count of all operations dequeued */
31         uint64_t dequeued_count;
32         /* Total error count on operations enqueued */
33         uint64_t enqueue_err_count;
34         /* Total error count on operations dequeued */
35         uint64_t dequeue_err_count;
36 };
37
38 struct bcmfs_qp_config {
39         /* Socket to allocate memory on */
40         int socket_id;
41         /* Mapped iobase for qp */
42         void *iobase;
43         /* nb_descriptors or requests a h/w queue can accommodate */
44         uint16_t nb_descriptors;
45         /* Maximum number of h/w descriptors needed by a request */
46         uint16_t max_descs_req;
47 };
48
49 struct bcmfs_queue {
50         /* Base virt address */
51         void *base_addr;
52         /* Base iova */
53         rte_iova_t base_phys_addr;
54         /* Queue type */
55         enum bcmfs_queue_type q_type;
56         /* Queue size based on nb_descriptors and max_descs_reqs */
57         uint32_t queue_size;
58         union {
59                 /* s/w pointer for tx h/w queue*/
60                 uint32_t tx_write_ptr;
61                 /* s/w pointer for completion h/w queue*/
62                 uint32_t cmpl_read_ptr;
63         };
64         /* Memzone name */
65         char memz_name[RTE_MEMZONE_NAMESIZE];
66 };
67
68 struct bcmfs_qp {
69         /* Queue-pair ID */
70         uint16_t qpair_id;
71         /* Mapped IO address */
72         void *ioreg;
73         /* A TX queue */
74         struct bcmfs_queue tx_q;
75         /* A Completion queue */
76         struct bcmfs_queue cmpl_q;
77         /* Number of requests queue can accommodate */
78         uint32_t nb_descriptors;
79         /* Number of pending requests and enqueued to h/w queue */
80         uint16_t nb_pending_requests;
81         /* A pool which act as a hash for <request-ID and virt address> pair */
82         unsigned long *ctx_pool;
83         /* virt address for mem allocated for bitmap */
84         void *ctx_bmp_mem;
85         /* Bitmap */
86         struct rte_bitmap *ctx_bmp;
87         /* Associated stats */
88         struct bcmfs_qp_stats stats;
89         /* h/w ops associated with qp */
90         struct bcmfs_hw_queue_pair_ops *ops;
91
92 } __rte_cache_aligned;
93
94 /* Structure defining h/w queue pair operations */
95 struct bcmfs_hw_queue_pair_ops {
96         /* ops name */
97         char name[BCMFS_HW_OPS_NAMESIZE];
98         /* Enqueue an object */
99         int (*enq_one_req)(struct bcmfs_qp *qp, void *obj);
100         /* Ring doorbell */
101         void (*ring_db)(struct bcmfs_qp *qp);
102         /* Dequeue objects */
103         uint16_t (*dequeue)(struct bcmfs_qp *qp, void **obj,
104                             uint16_t nb_ops);
105         /* Start the h/w queue */
106         int (*startq)(struct bcmfs_qp *qp);
107         /* Stop the h/w queue */
108         void (*stopq)(struct bcmfs_qp *qp);
109 };
110
111 uint16_t
112 bcmfs_enqueue_op_burst(void *qp, void **ops, uint16_t nb_ops);
113 uint16_t
114 bcmfs_dequeue_op_burst(void *qp, void **ops, uint16_t nb_ops);
115 int
116 bcmfs_qp_release(struct bcmfs_qp **qp_addr);
117 int
118 bcmfs_qp_setup(struct bcmfs_qp **qp_addr,
119                uint16_t queue_pair_id,
120                struct bcmfs_qp_config *bcmfs_conf);
121
122 #endif /* _BCMFS_QP_H_ */