cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

spi-test.h (4999B)


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