spi-test.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/drivers/spi/spi-test.h
  4. *
  5. * (c) Martin Sperl <kernel@martin.sperl.org>
  6. *
  7. * spi_test definitions
  8. */
  9. #include <linux/spi/spi.h>
  10. #define SPI_TEST_MAX_TRANSFERS 4
  11. #define SPI_TEST_MAX_SIZE (32 * PAGE_SIZE)
  12. #define SPI_TEST_MAX_ITERATE 32
  13. /* the "dummy" start addresses used in spi_test
  14. * these addresses get translated at a later stage
  15. */
  16. #define RX_START BIT(30)
  17. #define TX_START BIT(31)
  18. #define RX(off) ((void *)(RX_START + off))
  19. #define TX(off) ((void *)(TX_START + off))
  20. /* some special defines for offsets */
  21. #define SPI_TEST_MAX_SIZE_HALF BIT(29)
  22. /* detection pattern for unfinished reads...
  23. * - 0x00 or 0xff could be valid levels for tx_buf = NULL,
  24. * so we do not use either of them
  25. */
  26. #define SPI_TEST_PATTERN_UNWRITTEN 0xAA
  27. #define SPI_TEST_PATTERN_DO_NOT_WRITE 0x55
  28. #define SPI_TEST_CHECK_DO_NOT_WRITE 64
  29. /**
  30. * struct spi_test - describes a specific (set of) tests to execute
  31. *
  32. * @description: description of the test
  33. *
  34. * @msg: a template @spi_message usedfor the default settings
  35. * @transfers: array of @spi_transfers that are part of the
  36. * resulting spi_message.
  37. * @transfer_count: number of transfers
  38. *
  39. * @run_test: run a specific spi_test - this allows to override
  40. * the default implementation of @spi_test_run_transfer
  41. * either to add some custom filters for a specific test
  42. * or to effectively run some very custom tests...
  43. * @execute_msg: run the spi_message for real - this allows to override
  44. * @spi_test_execute_msg to apply final modifications
  45. * on the spi_message
  46. * @expected_return: the expected return code - in some cases we want to
  47. * test also for error conditions
  48. *
  49. * @iterate_len: list of length to iterate on
  50. * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf
  51. * for all values in the below range if set.
  52. * the ranges are:
  53. * [0 : @spi_master.dma_alignment[ if set
  54. * [0 : iterate_tx_align[ if unset
  55. * @iterate_rx_align: change the alignment of @spi_transfer.rx_buf
  56. * see @iterate_tx_align for details
  57. * @iterate_transfer_mask: the bitmask of transfers to which the iterations
  58. * apply - if 0, then it applies to all transfer
  59. *
  60. * @fill_option: define the way how tx_buf is filled
  61. * @fill_pattern: fill pattern to apply to the tx_buf
  62. * (used in some of the @fill_options)
  63. * @elapsed_time: elapsed time in nanoseconds
  64. */
  65. struct spi_test {
  66. char description[64];
  67. struct spi_message msg;
  68. struct spi_transfer transfers[SPI_TEST_MAX_TRANSFERS];
  69. unsigned int transfer_count;
  70. int (*run_test)(struct spi_device *spi, struct spi_test *test,
  71. void *tx, void *rx);
  72. int (*execute_msg)(struct spi_device *spi, struct spi_test *test,
  73. void *tx, void *rx);
  74. int expected_return;
  75. /* iterate over all values, terminated by a -1 */
  76. int iterate_len[SPI_TEST_MAX_ITERATE];
  77. int iterate_tx_align;
  78. int iterate_rx_align;
  79. u32 iterate_transfer_mask;
  80. /* the tx-fill operation */
  81. u32 fill_option;
  82. #define FILL_MEMSET_8 0 /* just memset with 8 bit */
  83. #define FILL_MEMSET_16 1 /* just memset with 16 bit */
  84. #define FILL_MEMSET_24 2 /* just memset with 24 bit */
  85. #define FILL_MEMSET_32 3 /* just memset with 32 bit */
  86. #define FILL_COUNT_8 4 /* fill with a 8 byte counter */
  87. #define FILL_COUNT_16 5 /* fill with a 16 bit counter */
  88. #define FILL_COUNT_24 6 /* fill with a 24 bit counter */
  89. #define FILL_COUNT_32 7 /* fill with a 32 bit counter */
  90. #define FILL_TRANSFER_BYTE_8 8 /* fill with the transfer byte - 8 bit */
  91. #define FILL_TRANSFER_BYTE_16 9 /* fill with the transfer byte - 16 bit */
  92. #define FILL_TRANSFER_BYTE_24 10 /* fill with the transfer byte - 24 bit */
  93. #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */
  94. #define FILL_TRANSFER_NUM 16 /* fill with the transfer number */
  95. u32 fill_pattern;
  96. unsigned long long elapsed_time;
  97. };
  98. /* default implementation for @spi_test.run_test */
  99. int spi_test_run_test(struct spi_device *spi,
  100. const struct spi_test *test,
  101. void *tx, void *rx);
  102. /* default implementation for @spi_test.execute_msg */
  103. int spi_test_execute_msg(struct spi_device *spi,
  104. struct spi_test *test,
  105. void *tx, void *rx);
  106. /* function to execute a set of tests */
  107. int spi_test_run_tests(struct spi_device *spi,
  108. struct spi_test *tests);
  109. #define ITERATE_LEN_LIST 0, 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
  110. 1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
  111. /* some of the default @spi_transfer.len to test, terminated by a -1 */
  112. #define ITERATE_LEN ITERATE_LEN_LIST, -1
  113. #define ITERATE_MAX_LEN ITERATE_LEN_LIST, (SPI_TEST_MAX_SIZE - 1), \
  114. SPI_TEST_MAX_SIZE, -1
  115. /* the default alignment to test */
  116. #define ITERATE_ALIGN sizeof(int)