source: rtems-libbsd/linux/drivers/soc/fsl/qbman/bman_test_api.c @ cd089b9

55-freebsd-126-freebsd-12
Last change on this file since cd089b9 was cd089b9, checked in by Sebastian Huber <sebastian.huber@…>, on 05/05/17 at 06:47:39

Linux update to 4.11-rc5

Linux baseline a71c9a1c779f2499fb2afc0553e543f18aff6edf (4.11-rc5).

  • Property mode set to 100644
File size: 4.3 KB
Line 
1#include <machine/rtems-bsd-kernel-space.h>
2
3#include <rtems/bsd/local/opt_dpaa.h>
4
5/* Copyright 2008 - 2016 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 "bman_test.h"
36
37#define NUM_BUFS        93
38#define LOOPS           3
39#define BMAN_TOKEN_MASK 0x00FFFFFFFFFFLLU
40
41static struct bman_pool *pool;
42static struct bm_buffer bufs_in[NUM_BUFS] ____cacheline_aligned;
43static struct bm_buffer bufs_out[NUM_BUFS] ____cacheline_aligned;
44static int bufs_received;
45
46static void bufs_init(void)
47{
48        int i;
49
50        for (i = 0; i < NUM_BUFS; i++)
51                bm_buffer_set64(&bufs_in[i], 0xfedc01234567LLU * i);
52        bufs_received = 0;
53}
54
55static inline int bufs_cmp(const struct bm_buffer *a, const struct bm_buffer *b)
56{
57        if (bman_ip_rev == BMAN_REV20 || bman_ip_rev == BMAN_REV21) {
58
59                /*
60                 * On SoCs with BMan revison 2.0, BMan only respects the 40
61                 * LS-bits of buffer addresses, masking off the upper 8-bits on
62                 * release commands. The API provides for 48-bit addresses
63                 * because some SoCs support all 48-bits. When generating
64                 * garbage addresses for testing, we either need to zero the
65                 * upper 8-bits when releasing to BMan (otherwise we'll be
66                 * disappointed when the buffers we acquire back from BMan
67                 * don't match), or we need to mask the upper 8-bits off when
68                 * comparing. We do the latter.
69                 */
70                if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) <
71                    (bm_buffer_get64(b) & BMAN_TOKEN_MASK))
72                        return -1;
73                if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) >
74                    (bm_buffer_get64(b) & BMAN_TOKEN_MASK))
75                        return 1;
76        } else {
77                if (bm_buffer_get64(a) < bm_buffer_get64(b))
78                        return -1;
79                if (bm_buffer_get64(a) > bm_buffer_get64(b))
80                        return 1;
81        }
82
83        return 0;
84}
85
86static void bufs_confirm(void)
87{
88        int i, j;
89
90        for (i = 0; i < NUM_BUFS; i++) {
91                int matches = 0;
92
93                for (j = 0; j < NUM_BUFS; j++)
94                        if (!bufs_cmp(&bufs_in[i], &bufs_out[j]))
95                                matches++;
96                WARN_ON(matches != 1);
97        }
98}
99
100/* test */
101void bman_test_api(void)
102{
103        int i, loops = LOOPS;
104
105        bufs_init();
106
107        pr_info("%s(): Starting\n", __func__);
108
109        pool = bman_new_pool();
110        if (!pool) {
111                pr_crit("bman_new_pool() failed\n");
112                goto failed;
113        }
114
115        /* Release buffers */
116do_loop:
117        i = 0;
118        while (i < NUM_BUFS) {
119                int num = 8;
120
121                if (i + num > NUM_BUFS)
122                        num = NUM_BUFS - i;
123                if (bman_release(pool, bufs_in + i, num)) {
124                        pr_crit("bman_release() failed\n");
125                        goto failed;
126                }
127                i += num;
128        }
129
130        /* Acquire buffers */
131        while (i > 0) {
132                int tmp, num = 8;
133
134                if (num > i)
135                        num = i;
136                tmp = bman_acquire(pool, bufs_out + i - num, num);
137                WARN_ON(tmp != num);
138                i -= num;
139        }
140        i = bman_acquire(pool, NULL, 1);
141        WARN_ON(i > 0);
142
143        bufs_confirm();
144
145        if (--loops)
146                goto do_loop;
147
148        /* Clean up */
149        bman_free_pool(pool);
150        pr_info("%s(): Finished\n", __func__);
151        return;
152
153failed:
154        WARN_ON(1);
155}
Note: See TracBrowser for help on using the repository browser.