Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  linux/drivers/spi/spi-test.h
0004  *
0005  *  (c) Martin Sperl <kernel@martin.sperl.org>
0006  *
0007  *  spi_test definitions
0008  */
0009 
0010 #include <linux/spi/spi.h>
0011 
0012 #define SPI_TEST_MAX_TRANSFERS 4
0013 #define SPI_TEST_MAX_SIZE (32 * PAGE_SIZE)
0014 #define SPI_TEST_MAX_ITERATE 32
0015 
0016 /* the "dummy" start addresses used in spi_test
0017  * these addresses get translated at a later stage
0018  */
0019 #define RX_START    BIT(30)
0020 #define TX_START    BIT(31)
0021 #define RX(off)     ((void *)(RX_START + off))
0022 #define TX(off)     ((void *)(TX_START + off))
0023 
0024 /* some special defines for offsets */
0025 #define SPI_TEST_MAX_SIZE_HALF  BIT(29)
0026 
0027 /* detection pattern for unfinished reads...
0028  * - 0x00 or 0xff could be valid levels for tx_buf = NULL,
0029  * so we do not use either of them
0030  */
0031 #define SPI_TEST_PATTERN_UNWRITTEN 0xAA
0032 #define SPI_TEST_PATTERN_DO_NOT_WRITE 0x55
0033 #define SPI_TEST_CHECK_DO_NOT_WRITE 64
0034 
0035 /**
0036  * struct spi_test - describes a specific (set of) tests to execute
0037  *
0038  * @description:      description of the test
0039  *
0040  * @msg:              a template @spi_message usedfor the default settings
0041  * @transfers:        array of @spi_transfers that are part of the
0042  *                    resulting spi_message.
0043  * @transfer_count:   number of transfers
0044  *
0045  * @run_test:         run a specific spi_test - this allows to override
0046  *                    the default implementation of @spi_test_run_transfer
0047  *                    either to add some custom filters for a specific test
0048  *                    or to effectively run some very custom tests...
0049  * @execute_msg:      run the spi_message for real - this allows to override
0050  *                    @spi_test_execute_msg to apply final modifications
0051  *                    on the spi_message
0052  * @expected_return:  the expected return code - in some cases we want to
0053  *                    test also for error conditions
0054  *
0055  * @iterate_len:      list of length to iterate on
0056  * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf
0057  *                    for all values in the below range if set.
0058  *                    the ranges are:
0059  *                    [0 : @spi_master.dma_alignment[ if set
0060  *                    [0 : iterate_tx_align[ if unset
0061  * @iterate_rx_align: change the alignment of @spi_transfer.rx_buf
0062  *                    see @iterate_tx_align for details
0063  * @iterate_transfer_mask: the bitmask of transfers to which the iterations
0064  *                         apply - if 0, then it applies to all transfer
0065  *
0066  * @fill_option:      define the way how tx_buf is filled
0067  * @fill_pattern:     fill pattern to apply to the tx_buf
0068  *                    (used in some of the @fill_options)
0069  * @elapsed_time:     elapsed time in nanoseconds
0070  */
0071 
0072 struct spi_test {
0073     char description[64];
0074     struct spi_message msg;
0075     struct spi_transfer transfers[SPI_TEST_MAX_TRANSFERS];
0076     unsigned int transfer_count;
0077     int (*run_test)(struct spi_device *spi, struct spi_test *test,
0078             void *tx, void *rx);
0079     int (*execute_msg)(struct spi_device *spi, struct spi_test *test,
0080                void *tx, void *rx);
0081     int expected_return;
0082     /* iterate over all values, terminated by a -1 */
0083     int iterate_len[SPI_TEST_MAX_ITERATE];
0084     int iterate_tx_align;
0085     int iterate_rx_align;
0086     u32 iterate_transfer_mask;
0087     /* the tx-fill operation */
0088     u32 fill_option;
0089 #define FILL_MEMSET_8   0   /* just memset with 8 bit */
0090 #define FILL_MEMSET_16  1   /* just memset with 16 bit */
0091 #define FILL_MEMSET_24  2   /* just memset with 24 bit */
0092 #define FILL_MEMSET_32  3   /* just memset with 32 bit */
0093 #define FILL_COUNT_8    4   /* fill with a 8 byte counter */
0094 #define FILL_COUNT_16   5   /* fill with a 16 bit counter */
0095 #define FILL_COUNT_24   6   /* fill with a 24 bit counter */
0096 #define FILL_COUNT_32   7   /* fill with a 32 bit counter */
0097 #define FILL_TRANSFER_BYTE_8  8 /* fill with the transfer byte - 8 bit */
0098 #define FILL_TRANSFER_BYTE_16 9 /* fill with the transfer byte - 16 bit */
0099 #define FILL_TRANSFER_BYTE_24 10 /* fill with the transfer byte - 24 bit */
0100 #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */
0101 #define FILL_TRANSFER_NUM     16 /* fill with the transfer number */
0102     u32 fill_pattern;
0103     unsigned long long elapsed_time;
0104 };
0105 
0106 /* default implementation for @spi_test.run_test */
0107 int spi_test_run_test(struct spi_device *spi,
0108               const struct spi_test *test,
0109               void *tx, void *rx);
0110 
0111 /* default implementation for @spi_test.execute_msg */
0112 int spi_test_execute_msg(struct spi_device *spi,
0113              struct spi_test *test,
0114              void *tx, void *rx);
0115 
0116 /* function to execute a set of tests */
0117 int spi_test_run_tests(struct spi_device *spi,
0118                struct spi_test *tests);
0119 
0120 #define ITERATE_LEN_LIST 0, 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
0121         1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
0122 /* some of the default @spi_transfer.len to test, terminated by a -1 */
0123 #define ITERATE_LEN ITERATE_LEN_LIST, -1
0124 #define ITERATE_MAX_LEN ITERATE_LEN_LIST, (SPI_TEST_MAX_SIZE - 1), \
0125         SPI_TEST_MAX_SIZE, -1
0126 
0127 /* the default alignment to test */
0128 #define ITERATE_ALIGN sizeof(int)