xref: /OK3568_Linux_fs/kernel/drivers/soc/fsl/qbman/bman_test_api.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
4*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions are met:
5*4882a593Smuzhiyun  *     * Redistributions of source code must retain the above copyright
6*4882a593Smuzhiyun  *	 notice, this list of conditions and the following disclaimer.
7*4882a593Smuzhiyun  *     * Redistributions in binary form must reproduce the above copyright
8*4882a593Smuzhiyun  *	 notice, this list of conditions and the following disclaimer in the
9*4882a593Smuzhiyun  *	 documentation and/or other materials provided with the distribution.
10*4882a593Smuzhiyun  *     * Neither the name of Freescale Semiconductor nor the
11*4882a593Smuzhiyun  *	 names of its contributors may be used to endorse or promote products
12*4882a593Smuzhiyun  *	 derived from this software without specific prior written permission.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * ALTERNATIVELY, this software may be distributed under the terms of the
15*4882a593Smuzhiyun  * GNU General Public License ("GPL") as published by the Free Software
16*4882a593Smuzhiyun  * Foundation, either version 2 of that License or (at your option) any
17*4882a593Smuzhiyun  * later version.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
20*4882a593Smuzhiyun  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21*4882a593Smuzhiyun  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22*4882a593Smuzhiyun  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
23*4882a593Smuzhiyun  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24*4882a593Smuzhiyun  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*4882a593Smuzhiyun  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26*4882a593Smuzhiyun  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28*4882a593Smuzhiyun  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #include "bman_test.h"
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define NUM_BUFS	93
34*4882a593Smuzhiyun #define LOOPS		3
35*4882a593Smuzhiyun #define BMAN_TOKEN_MASK 0x00FFFFFFFFFFLLU
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun static struct bman_pool *pool;
38*4882a593Smuzhiyun static struct bm_buffer bufs_in[NUM_BUFS] ____cacheline_aligned;
39*4882a593Smuzhiyun static struct bm_buffer bufs_out[NUM_BUFS] ____cacheline_aligned;
40*4882a593Smuzhiyun static int bufs_received;
41*4882a593Smuzhiyun 
bufs_init(void)42*4882a593Smuzhiyun static void bufs_init(void)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun 	int i;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	for (i = 0; i < NUM_BUFS; i++)
47*4882a593Smuzhiyun 		bm_buffer_set64(&bufs_in[i], 0xfedc01234567LLU * i);
48*4882a593Smuzhiyun 	bufs_received = 0;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun 
bufs_cmp(const struct bm_buffer * a,const struct bm_buffer * b)51*4882a593Smuzhiyun static inline int bufs_cmp(const struct bm_buffer *a, const struct bm_buffer *b)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun 	if (bman_ip_rev == BMAN_REV20 || bman_ip_rev == BMAN_REV21) {
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 		/*
56*4882a593Smuzhiyun 		 * On SoCs with BMan revison 2.0, BMan only respects the 40
57*4882a593Smuzhiyun 		 * LS-bits of buffer addresses, masking off the upper 8-bits on
58*4882a593Smuzhiyun 		 * release commands. The API provides for 48-bit addresses
59*4882a593Smuzhiyun 		 * because some SoCs support all 48-bits. When generating
60*4882a593Smuzhiyun 		 * garbage addresses for testing, we either need to zero the
61*4882a593Smuzhiyun 		 * upper 8-bits when releasing to BMan (otherwise we'll be
62*4882a593Smuzhiyun 		 * disappointed when the buffers we acquire back from BMan
63*4882a593Smuzhiyun 		 * don't match), or we need to mask the upper 8-bits off when
64*4882a593Smuzhiyun 		 * comparing. We do the latter.
65*4882a593Smuzhiyun 		 */
66*4882a593Smuzhiyun 		if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) <
67*4882a593Smuzhiyun 		    (bm_buffer_get64(b) & BMAN_TOKEN_MASK))
68*4882a593Smuzhiyun 			return -1;
69*4882a593Smuzhiyun 		if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) >
70*4882a593Smuzhiyun 		    (bm_buffer_get64(b) & BMAN_TOKEN_MASK))
71*4882a593Smuzhiyun 			return 1;
72*4882a593Smuzhiyun 	} else {
73*4882a593Smuzhiyun 		if (bm_buffer_get64(a) < bm_buffer_get64(b))
74*4882a593Smuzhiyun 			return -1;
75*4882a593Smuzhiyun 		if (bm_buffer_get64(a) > bm_buffer_get64(b))
76*4882a593Smuzhiyun 			return 1;
77*4882a593Smuzhiyun 	}
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	return 0;
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun 
bufs_confirm(void)82*4882a593Smuzhiyun static void bufs_confirm(void)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	int i, j;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	for (i = 0; i < NUM_BUFS; i++) {
87*4882a593Smuzhiyun 		int matches = 0;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 		for (j = 0; j < NUM_BUFS; j++)
90*4882a593Smuzhiyun 			if (!bufs_cmp(&bufs_in[i], &bufs_out[j]))
91*4882a593Smuzhiyun 				matches++;
92*4882a593Smuzhiyun 		WARN_ON(matches != 1);
93*4882a593Smuzhiyun 	}
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /* test */
bman_test_api(void)97*4882a593Smuzhiyun void bman_test_api(void)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun 	int i, loops = LOOPS;
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	bufs_init();
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	pr_info("%s(): Starting\n", __func__);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	pool = bman_new_pool();
106*4882a593Smuzhiyun 	if (!pool) {
107*4882a593Smuzhiyun 		pr_crit("bman_new_pool() failed\n");
108*4882a593Smuzhiyun 		goto failed;
109*4882a593Smuzhiyun 	}
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	/* Release buffers */
112*4882a593Smuzhiyun do_loop:
113*4882a593Smuzhiyun 	i = 0;
114*4882a593Smuzhiyun 	while (i < NUM_BUFS) {
115*4882a593Smuzhiyun 		int num = 8;
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun 		if (i + num > NUM_BUFS)
118*4882a593Smuzhiyun 			num = NUM_BUFS - i;
119*4882a593Smuzhiyun 		if (bman_release(pool, bufs_in + i, num)) {
120*4882a593Smuzhiyun 			pr_crit("bman_release() failed\n");
121*4882a593Smuzhiyun 			goto failed;
122*4882a593Smuzhiyun 		}
123*4882a593Smuzhiyun 		i += num;
124*4882a593Smuzhiyun 	}
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	/* Acquire buffers */
127*4882a593Smuzhiyun 	while (i > 0) {
128*4882a593Smuzhiyun 		int tmp, num = 8;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 		if (num > i)
131*4882a593Smuzhiyun 			num = i;
132*4882a593Smuzhiyun 		tmp = bman_acquire(pool, bufs_out + i - num, num);
133*4882a593Smuzhiyun 		WARN_ON(tmp != num);
134*4882a593Smuzhiyun 		i -= num;
135*4882a593Smuzhiyun 	}
136*4882a593Smuzhiyun 	i = bman_acquire(pool, NULL, 1);
137*4882a593Smuzhiyun 	WARN_ON(i > 0);
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	bufs_confirm();
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	if (--loops)
142*4882a593Smuzhiyun 		goto do_loop;
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	/* Clean up */
145*4882a593Smuzhiyun 	bman_free_pool(pool);
146*4882a593Smuzhiyun 	pr_info("%s(): Finished\n", __func__);
147*4882a593Smuzhiyun 	return;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun failed:
150*4882a593Smuzhiyun 	WARN_ON(1);
151*4882a593Smuzhiyun }
152