1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef __MLX5_WQ_H__
34#define __MLX5_WQ_H__
35
36#include <linux/mlx5/mlx5_ifc.h>
37
38struct mlx5_wq_param {
39 int linear;
40 int buf_numa_node;
41 int db_numa_node;
42};
43
44struct mlx5_wq_ctrl {
45 struct mlx5_core_dev *mdev;
46 struct mlx5_buf buf;
47 struct mlx5_db db;
48};
49
50struct mlx5_frag_wq_ctrl {
51 struct mlx5_core_dev *mdev;
52 struct mlx5_frag_buf frag_buf;
53 struct mlx5_db db;
54};
55
56struct mlx5_wq_cyc {
57 void *buf;
58 __be32 *db;
59 u16 sz_m1;
60 u8 log_stride;
61};
62
63struct mlx5_cqwq {
64 struct mlx5_frag_buf frag_buf;
65 __be32 *db;
66 u32 sz_m1;
67 u32 frag_sz_m1;
68 u32 cc;
69 u8 log_sz;
70 u8 log_stride;
71 u8 log_frag_strides;
72};
73
74struct mlx5_wq_ll {
75 void *buf;
76 __be32 *db;
77 __be16 *tail_next;
78 u16 sz_m1;
79 u16 head;
80 u16 wqe_ctr;
81 u16 cur_sz;
82 u8 log_stride;
83};
84
85int mlx5_wq_cyc_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
86 void *wqc, struct mlx5_wq_cyc *wq,
87 struct mlx5_wq_ctrl *wq_ctrl);
88u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq);
89
90int mlx5_cqwq_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
91 void *cqc, struct mlx5_cqwq *wq,
92 struct mlx5_frag_wq_ctrl *wq_ctrl);
93u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq);
94
95int mlx5_wq_ll_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
96 void *wqc, struct mlx5_wq_ll *wq,
97 struct mlx5_wq_ctrl *wq_ctrl);
98u32 mlx5_wq_ll_get_size(struct mlx5_wq_ll *wq);
99
100void mlx5_wq_destroy(struct mlx5_wq_ctrl *wq_ctrl);
101void mlx5_cqwq_destroy(struct mlx5_frag_wq_ctrl *wq_ctrl);
102
103static inline u16 mlx5_wq_cyc_ctr2ix(struct mlx5_wq_cyc *wq, u16 ctr)
104{
105 return ctr & wq->sz_m1;
106}
107
108static inline void *mlx5_wq_cyc_get_wqe(struct mlx5_wq_cyc *wq, u16 ix)
109{
110 return wq->buf + (ix << wq->log_stride);
111}
112
113static inline int mlx5_wq_cyc_cc_bigger(u16 cc1, u16 cc2)
114{
115 int equal = (cc1 == cc2);
116 int smaller = 0x8000 & (cc1 - cc2);
117
118 return !equal && !smaller;
119}
120
121static inline u32 mlx5_cqwq_get_ci(struct mlx5_cqwq *wq)
122{
123 return wq->cc & wq->sz_m1;
124}
125
126static inline void *mlx5_cqwq_get_wqe(struct mlx5_cqwq *wq, u32 ix)
127{
128 unsigned int frag = (ix >> wq->log_frag_strides);
129
130 return wq->frag_buf.frags[frag].buf +
131 ((wq->frag_sz_m1 & ix) << wq->log_stride);
132}
133
134static inline u32 mlx5_cqwq_get_wrap_cnt(struct mlx5_cqwq *wq)
135{
136 return wq->cc >> wq->log_sz;
137}
138
139static inline void mlx5_cqwq_pop(struct mlx5_cqwq *wq)
140{
141 wq->cc++;
142}
143
144static inline void mlx5_cqwq_update_db_record(struct mlx5_cqwq *wq)
145{
146 *wq->db = cpu_to_be32(wq->cc & 0xffffff);
147}
148
149static inline int mlx5_wq_ll_is_full(struct mlx5_wq_ll *wq)
150{
151 return wq->cur_sz == wq->sz_m1;
152}
153
154static inline int mlx5_wq_ll_is_empty(struct mlx5_wq_ll *wq)
155{
156 return !wq->cur_sz;
157}
158
159static inline void *mlx5_wq_ll_get_wqe(struct mlx5_wq_ll *wq, u16 ix)
160{
161 return wq->buf + (ix << wq->log_stride);
162}
163
164static inline void mlx5_wq_ll_push(struct mlx5_wq_ll *wq, u16 head_next)
165{
166 wq->head = head_next;
167 wq->wqe_ctr++;
168 wq->cur_sz++;
169}
170
171static inline void mlx5_wq_ll_pop(struct mlx5_wq_ll *wq, __be16 ix,
172 __be16 *next_tail_next)
173{
174 *wq->tail_next = ix;
175 wq->tail_next = next_tail_next;
176 wq->cur_sz--;
177}
178
179static inline void mlx5_wq_ll_update_db_record(struct mlx5_wq_ll *wq)
180{
181 *wq->db = cpu_to_be32(wq->wqe_ctr);
182}
183
184#endif
185