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#include "qman_test.h"
32
33#define CGR_ID 27
34#define POOL_ID 2
35#define FQ_FLAGS QMAN_FQ_FLAG_DYNAMIC_FQID
36#define NUM_ENQUEUES 10
37#define NUM_PARTIAL 4
38#define PORTAL_SDQCR (QM_SDQCR_SOURCE_CHANNELS | \
39 QM_SDQCR_TYPE_PRIO_QOS | \
40 QM_SDQCR_TOKEN_SET(0x98) | \
41 QM_SDQCR_CHANNELS_DEDICATED | \
42 QM_SDQCR_CHANNELS_POOL(POOL_ID))
43#define PORTAL_OPAQUE ((void *)0xf00dbeef)
44#define VDQCR_FLAGS (QMAN_VOLATILE_FLAG_WAIT | QMAN_VOLATILE_FLAG_FINISH)
45
46static enum qman_cb_dqrr_result cb_dqrr(struct qman_portal *,
47 struct qman_fq *,
48 const struct qm_dqrr_entry *,
49 bool sched_napi);
50static void cb_ern(struct qman_portal *, struct qman_fq *,
51 const union qm_mr_entry *);
52static void cb_fqs(struct qman_portal *, struct qman_fq *,
53 const union qm_mr_entry *);
54
55static struct qm_fd fd, fd_dq;
56static struct qman_fq fq_base = {
57 .cb.dqrr = cb_dqrr,
58 .cb.ern = cb_ern,
59 .cb.fqs = cb_fqs
60};
61static DECLARE_WAIT_QUEUE_HEAD(waitqueue);
62static int retire_complete, sdqcr_complete;
63
64
65static void fd_init(struct qm_fd *fd)
66{
67 qm_fd_addr_set64(fd, 0xabdeadbeefLLU);
68 qm_fd_set_contig_big(fd, 0x0000ffff);
69 fd->cmd = cpu_to_be32(0xfeedf00d);
70}
71
72static void fd_inc(struct qm_fd *fd)
73{
74 u64 t = qm_fd_addr_get64(fd);
75 int z = t >> 40;
76 unsigned int len, off;
77 enum qm_fd_format fmt;
78
79 t <<= 1;
80 if (z)
81 t |= 1;
82 qm_fd_addr_set64(fd, t);
83
84 fmt = qm_fd_get_format(fd);
85 off = qm_fd_get_offset(fd);
86 len = qm_fd_get_length(fd);
87 len--;
88 qm_fd_set_param(fd, fmt, off, len);
89
90 be32_add_cpu(&fd->cmd, 1);
91}
92
93
94static bool fd_neq(const struct qm_fd *a, const struct qm_fd *b)
95{
96 bool neq = qm_fd_addr_get64(a) != qm_fd_addr_get64(b);
97
98 neq |= qm_fd_get_format(a) != qm_fd_get_format(b);
99 neq |= a->cfg != b->cfg;
100 neq |= a->cmd != b->cmd;
101
102 return neq;
103}
104
105
106static int do_enqueues(struct qman_fq *fq)
107{
108 unsigned int loop;
109 int err = 0;
110
111 for (loop = 0; loop < NUM_ENQUEUES; loop++) {
112 if (qman_enqueue(fq, &fd)) {
113 pr_crit("qman_enqueue() failed\n");
114 err = -EIO;
115 }
116 fd_inc(&fd);
117 }
118
119 return err;
120}
121
122int qman_test_api(void)
123{
124 unsigned int flags, frmcnt;
125 int err;
126 struct qman_fq *fq = &fq_base;
127
128 pr_info("%s(): Starting\n", __func__);
129 fd_init(&fd);
130 fd_init(&fd_dq);
131
132
133 err = qman_create_fq(0, FQ_FLAGS, fq);
134 if (err) {
135 pr_crit("qman_create_fq() failed\n");
136 goto failed;
137 }
138 err = qman_init_fq(fq, QMAN_INITFQ_FLAG_LOCAL, NULL);
139 if (err) {
140 pr_crit("qman_init_fq() failed\n");
141 goto failed;
142 }
143
144 err = do_enqueues(fq);
145 if (err)
146 goto failed;
147 pr_info("VDQCR (till-empty);\n");
148 frmcnt = QM_VDQCR_NUMFRAMES_TILLEMPTY;
149 err = qman_volatile_dequeue(fq, VDQCR_FLAGS, frmcnt);
150 if (err) {
151 pr_crit("qman_volatile_dequeue() failed\n");
152 goto failed;
153 }
154 err = do_enqueues(fq);
155 if (err)
156 goto failed;
157 pr_info("VDQCR (%d of %d);\n", NUM_PARTIAL, NUM_ENQUEUES);
158 frmcnt = QM_VDQCR_NUMFRAMES_SET(NUM_PARTIAL);
159 err = qman_volatile_dequeue(fq, VDQCR_FLAGS, frmcnt);
160 if (err) {
161 pr_crit("qman_volatile_dequeue() failed\n");
162 goto failed;
163 }
164 pr_info("VDQCR (%d of %d);\n", NUM_ENQUEUES - NUM_PARTIAL,
165 NUM_ENQUEUES);
166 frmcnt = QM_VDQCR_NUMFRAMES_SET(NUM_ENQUEUES - NUM_PARTIAL);
167 err = qman_volatile_dequeue(fq, VDQCR_FLAGS, frmcnt);
168 if (err) {
169 pr_err("qman_volatile_dequeue() failed\n");
170 goto failed;
171 }
172
173 err = do_enqueues(fq);
174 if (err)
175 goto failed;
176 pr_info("scheduled dequeue (till-empty)\n");
177 err = qman_schedule_fq(fq);
178 if (err) {
179 pr_crit("qman_schedule_fq() failed\n");
180 goto failed;
181 }
182 wait_event(waitqueue, sdqcr_complete);
183
184
185 err = qman_retire_fq(fq, &flags);
186 if (err < 0) {
187 pr_crit("qman_retire_fq() failed\n");
188 goto failed;
189 }
190 wait_event(waitqueue, retire_complete);
191 if (flags & QMAN_FQ_STATE_BLOCKOOS) {
192 err = -EIO;
193 pr_crit("leaking frames\n");
194 goto failed;
195 }
196 err = qman_oos_fq(fq);
197 if (err) {
198 pr_crit("qman_oos_fq() failed\n");
199 goto failed;
200 }
201 qman_destroy_fq(fq);
202 pr_info("%s(): Finished\n", __func__);
203 return 0;
204
205failed:
206 WARN_ON(1);
207 return err;
208}
209
210static enum qman_cb_dqrr_result cb_dqrr(struct qman_portal *p,
211 struct qman_fq *fq,
212 const struct qm_dqrr_entry *dq,
213 bool sched_napi)
214{
215 if (WARN_ON(fd_neq(&fd_dq, &dq->fd))) {
216 pr_err("BADNESS: dequeued frame doesn't match;\n");
217 return qman_cb_dqrr_consume;
218 }
219 fd_inc(&fd_dq);
220 if (!(dq->stat & QM_DQRR_STAT_UNSCHEDULED) && !fd_neq(&fd_dq, &fd)) {
221 sdqcr_complete = 1;
222 wake_up(&waitqueue);
223 }
224 return qman_cb_dqrr_consume;
225}
226
227static void cb_ern(struct qman_portal *p, struct qman_fq *fq,
228 const union qm_mr_entry *msg)
229{
230 pr_crit("cb_ern() unimplemented");
231 WARN_ON(1);
232}
233
234static void cb_fqs(struct qman_portal *p, struct qman_fq *fq,
235 const union qm_mr_entry *msg)
236{
237 u8 verb = (msg->verb & QM_MR_VERB_TYPE_MASK);
238
239 if ((verb != QM_MR_VERB_FQRN) && (verb != QM_MR_VERB_FQRNI)) {
240 pr_crit("unexpected FQS message");
241 WARN_ON(1);
242 return;
243 }
244 pr_info("Retirement message received\n");
245 retire_complete = 1;
246 wake_up(&waitqueue);
247}
248