1 | #include <machine/rtems-bsd-kernel-space.h> |
---|
2 | |
---|
3 | #include <rtems/bsd/local/opt_dpaa.h> |
---|
4 | |
---|
5 | /* Copyright 2008 - 2015 Freescale Semiconductor, Inc. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions are met: |
---|
9 | * * Redistributions of source code must retain the above copyright |
---|
10 | * notice, this list of conditions and the following disclaimer. |
---|
11 | * * Redistributions in binary form must reproduce the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer in the |
---|
13 | * documentation and/or other materials provided with the distribution. |
---|
14 | * * Neither the name of Freescale Semiconductor nor the |
---|
15 | * names of its contributors may be used to endorse or promote products |
---|
16 | * derived from this software without specific prior written permission. |
---|
17 | * |
---|
18 | * ALTERNATIVELY, this software may be distributed under the terms of the |
---|
19 | * GNU General Public License ("GPL") as published by the Free Software |
---|
20 | * Foundation, either version 2 of that License or (at your option) any |
---|
21 | * later version. |
---|
22 | * |
---|
23 | * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY |
---|
24 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
26 | * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY |
---|
27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
30 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
33 | */ |
---|
34 | |
---|
35 | #include "qman_test.h" |
---|
36 | |
---|
37 | /*************/ |
---|
38 | /* constants */ |
---|
39 | /*************/ |
---|
40 | |
---|
41 | #define CGR_ID 27 |
---|
42 | #define POOL_ID 2 |
---|
43 | #define FQ_FLAGS QMAN_FQ_FLAG_DYNAMIC_FQID |
---|
44 | #define NUM_ENQUEUES 10 |
---|
45 | #define NUM_PARTIAL 4 |
---|
46 | #define PORTAL_SDQCR (QM_SDQCR_SOURCE_CHANNELS | \ |
---|
47 | QM_SDQCR_TYPE_PRIO_QOS | \ |
---|
48 | QM_SDQCR_TOKEN_SET(0x98) | \ |
---|
49 | QM_SDQCR_CHANNELS_DEDICATED | \ |
---|
50 | QM_SDQCR_CHANNELS_POOL(POOL_ID)) |
---|
51 | #define PORTAL_OPAQUE ((void *)0xf00dbeef) |
---|
52 | #define VDQCR_FLAGS (QMAN_VOLATILE_FLAG_WAIT | QMAN_VOLATILE_FLAG_FINISH) |
---|
53 | |
---|
54 | /*************************************/ |
---|
55 | /* Predeclarations (eg. for fq_base) */ |
---|
56 | /*************************************/ |
---|
57 | |
---|
58 | static enum qman_cb_dqrr_result cb_dqrr(struct qman_portal *, |
---|
59 | struct qman_fq *, |
---|
60 | const struct qm_dqrr_entry *); |
---|
61 | static void cb_ern(struct qman_portal *, struct qman_fq *, |
---|
62 | const struct qm_mr_entry *); |
---|
63 | static void cb_fqs(struct qman_portal *, struct qman_fq *, |
---|
64 | const struct qm_mr_entry *); |
---|
65 | |
---|
66 | /***************/ |
---|
67 | /* global vars */ |
---|
68 | /***************/ |
---|
69 | |
---|
70 | static struct qm_fd fd, fd_dq; |
---|
71 | static struct qman_fq fq_base = { |
---|
72 | .cb.dqrr = cb_dqrr, |
---|
73 | .cb.ern = cb_ern, |
---|
74 | .cb.fqs = cb_fqs |
---|
75 | }; |
---|
76 | static DECLARE_WAIT_QUEUE_HEAD(waitqueue); |
---|
77 | static int retire_complete, sdqcr_complete; |
---|
78 | |
---|
79 | /**********************/ |
---|
80 | /* internal functions */ |
---|
81 | /**********************/ |
---|
82 | |
---|
83 | /* Helpers for initialising and "incrementing" a frame descriptor */ |
---|
84 | static void fd_init(struct qm_fd *__fd) |
---|
85 | { |
---|
86 | qm_fd_addr_set64(__fd, 0xabdeadbeefLLU); |
---|
87 | __fd->format = qm_fd_contig_big; |
---|
88 | __fd->length29 = 0x0000ffff; |
---|
89 | __fd->cmd = 0xfeedf00d; |
---|
90 | } |
---|
91 | |
---|
92 | static void fd_inc(struct qm_fd *__fd) |
---|
93 | { |
---|
94 | u64 t = qm_fd_addr_get64(__fd); |
---|
95 | int z = t >> 40; |
---|
96 | |
---|
97 | t <<= 1; |
---|
98 | if (z) |
---|
99 | t |= 1; |
---|
100 | qm_fd_addr_set64(__fd, t); |
---|
101 | __fd->length29--; |
---|
102 | __fd->cmd++; |
---|
103 | } |
---|
104 | |
---|
105 | /* The only part of the 'fd' we can't memcmp() is the ppid */ |
---|
106 | static int fd_cmp(const struct qm_fd *a, const struct qm_fd *b) |
---|
107 | { |
---|
108 | int r = (qm_fd_addr_get64(a) == qm_fd_addr_get64(b)) ? 0 : -1; |
---|
109 | |
---|
110 | if (!r) |
---|
111 | r = a->format - b->format; |
---|
112 | if (!r) |
---|
113 | r = a->opaque - b->opaque; |
---|
114 | if (!r) |
---|
115 | r = a->cmd - b->cmd; |
---|
116 | return r; |
---|
117 | } |
---|
118 | |
---|
119 | /********/ |
---|
120 | /* test */ |
---|
121 | /********/ |
---|
122 | |
---|
123 | static void do_enqueues(struct qman_fq *fq) |
---|
124 | { |
---|
125 | unsigned int loop; |
---|
126 | |
---|
127 | for (loop = 0; loop < NUM_ENQUEUES; loop++) { |
---|
128 | if (qman_enqueue(fq, &fd, QMAN_ENQUEUE_FLAG_WAIT | |
---|
129 | (((loop + 1) == NUM_ENQUEUES) ? |
---|
130 | QMAN_ENQUEUE_FLAG_WAIT_SYNC : 0))) |
---|
131 | panic("qman_enqueue() failed\n"); |
---|
132 | fd_inc(&fd); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | void qman_test_api(void) |
---|
137 | { |
---|
138 | u32 flags; |
---|
139 | int res; |
---|
140 | struct qman_fq *fq = &fq_base; |
---|
141 | |
---|
142 | pr_info("%s(): Starting\n", __func__); |
---|
143 | fd_init(&fd); |
---|
144 | fd_init(&fd_dq); |
---|
145 | |
---|
146 | /* Initialise (parked) FQ */ |
---|
147 | if (qman_create_fq(0, FQ_FLAGS, fq)) |
---|
148 | panic("qman_create_fq() failed\n"); |
---|
149 | if (qman_init_fq(fq, QMAN_INITFQ_FLAG_LOCAL, NULL)) |
---|
150 | panic("qman_init_fq() failed\n"); |
---|
151 | |
---|
152 | /* Do enqueues + VDQCR, twice. (Parked FQ) */ |
---|
153 | do_enqueues(fq); |
---|
154 | pr_info("VDQCR (till-empty);\n"); |
---|
155 | if (qman_volatile_dequeue(fq, VDQCR_FLAGS, |
---|
156 | QM_VDQCR_NUMFRAMES_TILLEMPTY)) |
---|
157 | panic("qman_volatile_dequeue() failed\n"); |
---|
158 | do_enqueues(fq); |
---|
159 | pr_info("VDQCR (%d of %d);\n", NUM_PARTIAL, NUM_ENQUEUES); |
---|
160 | if (qman_volatile_dequeue(fq, VDQCR_FLAGS, |
---|
161 | QM_VDQCR_NUMFRAMES_SET(NUM_PARTIAL))) |
---|
162 | panic("qman_volatile_dequeue() failed\n"); |
---|
163 | pr_info("VDQCR (%d of %d);\n", NUM_ENQUEUES - NUM_PARTIAL, |
---|
164 | NUM_ENQUEUES); |
---|
165 | if (qman_volatile_dequeue(fq, VDQCR_FLAGS, |
---|
166 | QM_VDQCR_NUMFRAMES_SET(NUM_ENQUEUES - NUM_PARTIAL))) |
---|
167 | panic("qman_volatile_dequeue() failed\n"); |
---|
168 | |
---|
169 | do_enqueues(fq); |
---|
170 | pr_info("scheduled dequeue (till-empty)\n"); |
---|
171 | if (qman_schedule_fq(fq)) |
---|
172 | panic("qman_schedule_fq() failed\n"); |
---|
173 | wait_event(waitqueue, sdqcr_complete); |
---|
174 | |
---|
175 | /* Retire and OOS the FQ */ |
---|
176 | res = qman_retire_fq(fq, &flags); |
---|
177 | if (res < 0) |
---|
178 | panic("qman_retire_fq() failed\n"); |
---|
179 | wait_event(waitqueue, retire_complete); |
---|
180 | if (flags & QMAN_FQ_STATE_BLOCKOOS) |
---|
181 | panic("leaking frames\n"); |
---|
182 | if (qman_oos_fq(fq)) |
---|
183 | panic("qman_oos_fq() failed\n"); |
---|
184 | qman_destroy_fq(fq, 0); |
---|
185 | pr_info("%s(): Finished\n", __func__); |
---|
186 | } |
---|
187 | |
---|
188 | static enum qman_cb_dqrr_result cb_dqrr(struct qman_portal *p, |
---|
189 | struct qman_fq *fq, |
---|
190 | const struct qm_dqrr_entry *dq) |
---|
191 | { |
---|
192 | if (fd_cmp(&fd_dq, &dq->fd)) { |
---|
193 | pr_err("BADNESS: dequeued frame doesn't match;\n"); |
---|
194 | BUG(); |
---|
195 | } |
---|
196 | fd_inc(&fd_dq); |
---|
197 | if (!(dq->stat & QM_DQRR_STAT_UNSCHEDULED) && !fd_cmp(&fd_dq, &fd)) { |
---|
198 | sdqcr_complete = 1; |
---|
199 | wake_up(&waitqueue); |
---|
200 | } |
---|
201 | return qman_cb_dqrr_consume; |
---|
202 | } |
---|
203 | |
---|
204 | static void cb_ern(struct qman_portal *p, struct qman_fq *fq, |
---|
205 | const struct qm_mr_entry *msg) |
---|
206 | { |
---|
207 | panic("cb_ern() unimplemented"); |
---|
208 | } |
---|
209 | |
---|
210 | static void cb_fqs(struct qman_portal *p, struct qman_fq *fq, |
---|
211 | const struct qm_mr_entry *msg) |
---|
212 | { |
---|
213 | u8 verb = (msg->verb & QM_MR_VERB_TYPE_MASK); |
---|
214 | |
---|
215 | if ((verb != QM_MR_VERB_FQRN) && (verb != QM_MR_VERB_FQRNI)) |
---|
216 | panic("unexpected FQS message"); |
---|
217 | #ifndef __rtems__ |
---|
218 | pr_info("Retirement message received\n"); |
---|
219 | #endif /* __rtems__ */ |
---|
220 | retire_complete = 1; |
---|
221 | wake_up(&waitqueue); |
---|
222 | } |
---|