Back to home page

OSCL-LXR

 
 

    


0001 /* Copyright 2008 - 2016 Freescale Semiconductor, Inc.
0002  *
0003  * Redistribution and use in source and binary forms, with or without
0004  * modification, are permitted provided that the following conditions are met:
0005  *     * Redistributions of source code must retain the above copyright
0006  *   notice, this list of conditions and the following disclaimer.
0007  *     * Redistributions in binary form must reproduce the above copyright
0008  *   notice, this list of conditions and the following disclaimer in the
0009  *   documentation and/or other materials provided with the distribution.
0010  *     * Neither the name of Freescale Semiconductor nor the
0011  *   names of its contributors may be used to endorse or promote products
0012  *   derived from this software without specific prior written permission.
0013  *
0014  * ALTERNATIVELY, this software may be distributed under the terms of the
0015  * GNU General Public License ("GPL") as published by the Free Software
0016  * Foundation, either version 2 of that License or (at your option) any
0017  * later version.
0018  *
0019  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
0020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
0021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0022  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
0023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #include "bman_test.h"
0032 
0033 #define NUM_BUFS    93
0034 #define LOOPS       3
0035 #define BMAN_TOKEN_MASK 0x00FFFFFFFFFFLLU
0036 
0037 static struct bman_pool *pool;
0038 static struct bm_buffer bufs_in[NUM_BUFS] ____cacheline_aligned;
0039 static struct bm_buffer bufs_out[NUM_BUFS] ____cacheline_aligned;
0040 static int bufs_received;
0041 
0042 static void bufs_init(void)
0043 {
0044     int i;
0045 
0046     for (i = 0; i < NUM_BUFS; i++)
0047         bm_buffer_set64(&bufs_in[i], 0xfedc01234567LLU * i);
0048     bufs_received = 0;
0049 }
0050 
0051 static inline int bufs_cmp(const struct bm_buffer *a, const struct bm_buffer *b)
0052 {
0053     if (bman_ip_rev == BMAN_REV20 || bman_ip_rev == BMAN_REV21) {
0054 
0055         /*
0056          * On SoCs with BMan revison 2.0, BMan only respects the 40
0057          * LS-bits of buffer addresses, masking off the upper 8-bits on
0058          * release commands. The API provides for 48-bit addresses
0059          * because some SoCs support all 48-bits. When generating
0060          * garbage addresses for testing, we either need to zero the
0061          * upper 8-bits when releasing to BMan (otherwise we'll be
0062          * disappointed when the buffers we acquire back from BMan
0063          * don't match), or we need to mask the upper 8-bits off when
0064          * comparing. We do the latter.
0065          */
0066         if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) <
0067             (bm_buffer_get64(b) & BMAN_TOKEN_MASK))
0068             return -1;
0069         if ((bm_buffer_get64(a) & BMAN_TOKEN_MASK) >
0070             (bm_buffer_get64(b) & BMAN_TOKEN_MASK))
0071             return 1;
0072     } else {
0073         if (bm_buffer_get64(a) < bm_buffer_get64(b))
0074             return -1;
0075         if (bm_buffer_get64(a) > bm_buffer_get64(b))
0076             return 1;
0077     }
0078 
0079     return 0;
0080 }
0081 
0082 static void bufs_confirm(void)
0083 {
0084     int i, j;
0085 
0086     for (i = 0; i < NUM_BUFS; i++) {
0087         int matches = 0;
0088 
0089         for (j = 0; j < NUM_BUFS; j++)
0090             if (!bufs_cmp(&bufs_in[i], &bufs_out[j]))
0091                 matches++;
0092         WARN_ON(matches != 1);
0093     }
0094 }
0095 
0096 /* test */
0097 void bman_test_api(void)
0098 {
0099     int i, loops = LOOPS;
0100 
0101     bufs_init();
0102 
0103     pr_info("%s(): Starting\n", __func__);
0104 
0105     pool = bman_new_pool();
0106     if (!pool) {
0107         pr_crit("bman_new_pool() failed\n");
0108         goto failed;
0109     }
0110 
0111     /* Release buffers */
0112 do_loop:
0113     i = 0;
0114     while (i < NUM_BUFS) {
0115         int num = 8;
0116 
0117         if (i + num > NUM_BUFS)
0118             num = NUM_BUFS - i;
0119         if (bman_release(pool, bufs_in + i, num)) {
0120             pr_crit("bman_release() failed\n");
0121             goto failed;
0122         }
0123         i += num;
0124     }
0125 
0126     /* Acquire buffers */
0127     while (i > 0) {
0128         int tmp, num = 8;
0129 
0130         if (num > i)
0131             num = i;
0132         tmp = bman_acquire(pool, bufs_out + i - num, num);
0133         WARN_ON(tmp != num);
0134         i -= num;
0135     }
0136     i = bman_acquire(pool, NULL, 1);
0137     WARN_ON(i > 0);
0138 
0139     bufs_confirm();
0140 
0141     if (--loops)
0142         goto do_loop;
0143 
0144     /* Clean up */
0145     bman_free_pool(pool);
0146     pr_info("%s(): Finished\n", __func__);
0147     return;
0148 
0149 failed:
0150     WARN_ON(1);
0151 }