1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Broadcom
9 #include <rte_memzone.h>
11 /* Maximum number of h/w queues supported by device */
12 #define BCMFS_MAX_HW_QUEUES 32
14 /* H/W queue IO address space len */
15 #define BCMFS_HW_QUEUE_IO_ADDR_LEN (64 * 1024)
17 /* Maximum size of device ops name */
18 #define BCMFS_HW_OPS_NAMESIZE 32
20 enum bcmfs_queue_type {
21 /* TX or submission queue */
23 /* Completion or receive queue */
27 #define BCMFS_QP_IOBASE_XLATE(base, idx) \
28 ((base) + ((idx) * BCMFS_HW_QUEUE_IO_ADDR_LEN))
30 /* Max pkts for preprocessing before submitting to h/w qp */
31 #define BCMFS_MAX_REQS_BUFF 64
34 struct bcmfs_qp_stats {
35 /* Count of all operations enqueued */
36 uint64_t enqueued_count;
37 /* Count of all operations dequeued */
38 uint64_t dequeued_count;
39 /* Total error count on operations enqueued */
40 uint64_t enqueue_err_count;
41 /* Total error count on operations dequeued */
42 uint64_t dequeue_err_count;
45 struct bcmfs_qp_config {
46 /* Socket to allocate memory on */
48 /* Mapped iobase for qp */
50 /* nb_descriptors or requests a h/w queue can accommodate */
51 uint16_t nb_descriptors;
52 /* Maximum number of h/w descriptors needed by a request */
53 uint16_t max_descs_req;
54 /* h/w ops associated with qp */
55 struct bcmfs_hw_queue_pair_ops *ops;
59 /* Base virt address */
62 rte_iova_t base_phys_addr;
64 enum bcmfs_queue_type q_type;
65 /* Queue size based on nb_descriptors and max_descs_reqs */
68 /* s/w pointer for tx h/w queue*/
69 uint32_t tx_write_ptr;
70 /* s/w pointer for completion h/w queue*/
71 uint32_t cmpl_read_ptr;
73 /* number of inflight descriptor accumulated before next db ring */
74 uint16_t descs_inflight;
76 char memz_name[RTE_MEMZONE_NAMESIZE];
82 /* Mapped IO address */
85 struct bcmfs_queue tx_q;
86 /* A Completion queue */
87 struct bcmfs_queue cmpl_q;
88 /* Number of requests queue can accommodate */
89 uint32_t nb_descriptors;
90 /* Number of pending requests and enqueued to h/w queue */
91 uint16_t nb_pending_requests;
92 /* A pool which act as a hash for <request-ID and virt address> pair */
93 unsigned long *ctx_pool;
94 /* virt address for mem allocated for bitmap */
97 struct rte_bitmap *ctx_bmp;
98 /* Associated stats */
99 struct bcmfs_qp_stats stats;
100 /* h/w ops associated with qp */
101 struct bcmfs_hw_queue_pair_ops *ops;
102 /* bcmfs requests pool*/
103 struct rte_mempool *sr_mp;
104 /* a temporary buffer to keep message pointers */
105 struct bcmfs_qp_message *infl_msgs[BCMFS_MAX_REQS_BUFF];
107 } __rte_cache_aligned;
109 /* Structure defining h/w queue pair operations */
110 struct bcmfs_hw_queue_pair_ops {
112 char name[BCMFS_HW_OPS_NAMESIZE];
113 /* Enqueue an object */
114 int (*enq_one_req)(struct bcmfs_qp *qp, void *obj);
116 void (*ring_db)(struct bcmfs_qp *qp);
117 /* Dequeue objects */
118 uint16_t (*dequeue)(struct bcmfs_qp *qp, void **obj,
120 /* Start the h/w queue */
121 int (*startq)(struct bcmfs_qp *qp);
122 /* Stop the h/w queue */
123 void (*stopq)(struct bcmfs_qp *qp);
127 bcmfs_enqueue_op_burst(void *qp, void **ops, uint16_t nb_ops);
129 bcmfs_dequeue_op_burst(void *qp, void **ops, uint16_t nb_ops);
131 bcmfs_qp_release(struct bcmfs_qp **qp_addr);
133 bcmfs_qp_setup(struct bcmfs_qp **qp_addr,
134 uint16_t queue_pair_id,
135 struct bcmfs_qp_config *bcmfs_conf);
138 void bcmfs_qp_stats_get(struct bcmfs_qp **qp, int num_qp,
139 struct bcmfs_qp_stats *stats);
140 void bcmfs_qp_stats_reset(struct bcmfs_qp **qp, int num_qp);
142 #endif /* _BCMFS_QP_H_ */