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