bman_test_api.c 4.3 KB

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