2 * linux/drivers/spi/spi-loopback-test.c
4 * (c) Martin Sperl <kernel@martin.sperl.org>
6 * Loopback test driver to test several typical spi_message conditions
7 * that a spi_master driver may encounter
8 * this can also get used for regression testing
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/delay.h>
22 #include <linux/kernel.h>
23 #include <linux/ktime.h>
24 #include <linux/list.h>
25 #include <linux/list_sort.h>
26 #include <linux/module.h>
27 #include <linux/of_device.h>
28 #include <linux/printk.h>
29 #include <linux/spi/spi.h>
33 /* flag to only simulate transfers */
35 module_param(simulate_only
, int, 0);
36 MODULE_PARM_DESC(simulate_only
, "if not 0 do not execute the spi message");
38 /* dump spi messages */
40 module_param(dump_messages
, int, 0);
41 MODULE_PARM_DESC(dump_messages
,
42 "=1 dump the basic spi_message_structure, " \
43 "=2 dump the spi_message_structure including data, " \
44 "=3 dump the spi_message structure before and after execution");
45 /* the device is jumpered for loopback - enabling some rx_buf tests */
47 module_param(loopback
, int, 0);
48 MODULE_PARM_DESC(loopback
,
49 "if set enable loopback mode, where the rx_buf " \
50 "is checked to match tx_buf after the spi_message " \
53 /* run only a specific test */
54 int run_only_test
= -1;
55 module_param(run_only_test
, int, 0);
56 MODULE_PARM_DESC(run_only_test
,
57 "only run the test with this number (0-based !)");
59 /* the actual tests to execute */
60 static struct spi_test spi_tests
[] = {
62 .description
= "tx/rx-transfer - start of page",
63 .fill_option
= FILL_COUNT_8
,
64 .iterate_len
= { ITERATE_MAX_LEN
},
65 .iterate_tx_align
= ITERATE_ALIGN
,
66 .iterate_rx_align
= ITERATE_ALIGN
,
76 .description
= "tx/rx-transfer - crossing PAGE_SIZE",
77 .fill_option
= FILL_COUNT_8
,
78 .iterate_len
= { ITERATE_MAX_LEN
},
79 .iterate_tx_align
= ITERATE_ALIGN
,
80 .iterate_rx_align
= ITERATE_ALIGN
,
84 .tx_buf
= TX(PAGE_SIZE
- 4),
85 .rx_buf
= RX(PAGE_SIZE
- 4),
90 .description
= "tx-transfer - only",
91 .fill_option
= FILL_COUNT_8
,
92 .iterate_len
= { ITERATE_MAX_LEN
},
93 .iterate_tx_align
= ITERATE_ALIGN
,
102 .description
= "rx-transfer - only",
103 .fill_option
= FILL_COUNT_8
,
104 .iterate_len
= { ITERATE_MAX_LEN
},
105 .iterate_rx_align
= ITERATE_ALIGN
,
114 .description
= "two tx-transfers - alter both",
115 .fill_option
= FILL_COUNT_8
,
116 .iterate_len
= { ITERATE_LEN
},
117 .iterate_tx_align
= ITERATE_ALIGN
,
118 .iterate_transfer_mask
= BIT(0) | BIT(1),
125 /* this is why we cant use ITERATE_MAX_LEN */
126 .tx_buf
= TX(SPI_TEST_MAX_SIZE_HALF
),
131 .description
= "two tx-transfers - alter first",
132 .fill_option
= FILL_COUNT_8
,
133 .iterate_len
= { ITERATE_MAX_LEN
},
134 .iterate_tx_align
= ITERATE_ALIGN
,
135 .iterate_transfer_mask
= BIT(0),
148 .description
= "two tx-transfers - alter second",
149 .fill_option
= FILL_COUNT_8
,
150 .iterate_len
= { ITERATE_MAX_LEN
},
151 .iterate_tx_align
= ITERATE_ALIGN
,
152 .iterate_transfer_mask
= BIT(1),
165 .description
= "two transfers tx then rx - alter both",
166 .fill_option
= FILL_COUNT_8
,
167 .iterate_len
= { ITERATE_MAX_LEN
},
168 .iterate_tx_align
= ITERATE_ALIGN
,
169 .iterate_transfer_mask
= BIT(0) | BIT(1),
181 .description
= "two transfers tx then rx - alter tx",
182 .fill_option
= FILL_COUNT_8
,
183 .iterate_len
= { ITERATE_MAX_LEN
},
184 .iterate_tx_align
= ITERATE_ALIGN
,
185 .iterate_transfer_mask
= BIT(0),
198 .description
= "two transfers tx then rx - alter rx",
199 .fill_option
= FILL_COUNT_8
,
200 .iterate_len
= { ITERATE_MAX_LEN
},
201 .iterate_tx_align
= ITERATE_ALIGN
,
202 .iterate_transfer_mask
= BIT(1),
215 .description
= "two tx+rx transfers - alter both",
216 .fill_option
= FILL_COUNT_8
,
217 .iterate_len
= { ITERATE_LEN
},
218 .iterate_tx_align
= ITERATE_ALIGN
,
219 .iterate_transfer_mask
= BIT(0) | BIT(1),
227 /* making sure we align without overwrite
228 * the reason we can not use ITERATE_MAX_LEN
230 .tx_buf
= TX(SPI_TEST_MAX_SIZE_HALF
),
231 .rx_buf
= RX(SPI_TEST_MAX_SIZE_HALF
),
236 .description
= "two tx+rx transfers - alter first",
237 .fill_option
= FILL_COUNT_8
,
238 .iterate_len
= { ITERATE_MAX_LEN
},
239 .iterate_tx_align
= ITERATE_ALIGN
,
240 .iterate_transfer_mask
= BIT(0),
244 /* making sure we align without overwrite */
250 /* making sure we align without overwrite */
257 .description
= "two tx+rx transfers - alter second",
258 .fill_option
= FILL_COUNT_8
,
259 .iterate_len
= { ITERATE_MAX_LEN
},
260 .iterate_tx_align
= ITERATE_ALIGN
,
261 .iterate_transfer_mask
= BIT(1),
270 /* making sure we align without overwrite */
277 .description
= "two tx+rx transfers - delay after transfer",
278 .fill_option
= FILL_COUNT_8
,
279 .iterate_len
= { ITERATE_MAX_LEN
},
280 .iterate_transfer_mask
= BIT(0) | BIT(1),
296 { /* end of tests sequence */ }
299 static int spi_loopback_test_probe(struct spi_device
*spi
)
303 dev_info(&spi
->dev
, "Executing spi-loopback-tests\n");
305 ret
= spi_test_run_tests(spi
, spi_tests
);
307 dev_info(&spi
->dev
, "Finished spi-loopback-tests with return: %i\n",
313 /* non const match table to permit to change via a module parameter */
314 static struct of_device_id spi_loopback_test_of_match
[] = {
315 { .compatible
= "linux,spi-loopback-test", },
319 /* allow to override the compatible string via a module_parameter */
320 module_param_string(compatible
, spi_loopback_test_of_match
[0].compatible
,
321 sizeof(spi_loopback_test_of_match
[0].compatible
),
324 MODULE_DEVICE_TABLE(of
, spi_loopback_test_of_match
);
326 static struct spi_driver spi_loopback_test_driver
= {
328 .name
= "spi-loopback-test",
329 .owner
= THIS_MODULE
,
330 .of_match_table
= spi_loopback_test_of_match
,
332 .probe
= spi_loopback_test_probe
,
335 module_spi_driver(spi_loopback_test_driver
);
337 MODULE_AUTHOR("Martin Sperl <kernel@martin.sperl.org>");
338 MODULE_DESCRIPTION("test spi_driver to check core functionality");
339 MODULE_LICENSE("GPL");
341 /*-------------------------------------------------------------------------*/
343 /* spi_test implementation */
345 #define RANGE_CHECK(ptr, plen, start, slen) \
346 ((ptr >= start) && (ptr + plen <= start + slen))
348 /* we allocate one page more, to allow for offsets */
349 #define SPI_TEST_MAX_SIZE_PLUS (SPI_TEST_MAX_SIZE + PAGE_SIZE)
351 static void spi_test_print_hex_dump(char *pre
, const void *ptr
, size_t len
)
353 /* limit the hex_dump */
355 print_hex_dump(KERN_INFO
, pre
,
356 DUMP_PREFIX_OFFSET
, 16, 1,
361 print_hex_dump(KERN_INFO
, pre
,
362 DUMP_PREFIX_OFFSET
, 16, 1,
365 pr_info("%s truncated - continuing at offset %04zx\n",
367 print_hex_dump(KERN_INFO
, pre
,
368 DUMP_PREFIX_OFFSET
, 16, 1,
369 ptr
+ (len
- 512), 512, 0);
372 static void spi_test_dump_message(struct spi_device
*spi
,
373 struct spi_message
*msg
,
376 struct spi_transfer
*xfer
;
380 dev_info(&spi
->dev
, " spi_msg@%pK\n", msg
);
382 dev_info(&spi
->dev
, " status: %i\n",
384 dev_info(&spi
->dev
, " frame_length: %i\n",
386 dev_info(&spi
->dev
, " actual_length: %i\n",
389 list_for_each_entry(xfer
, &msg
->transfers
, transfer_list
) {
390 dev_info(&spi
->dev
, " spi_transfer@%pK\n", xfer
);
391 dev_info(&spi
->dev
, " len: %i\n", xfer
->len
);
392 dev_info(&spi
->dev
, " tx_buf: %pK\n", xfer
->tx_buf
);
393 if (dump_data
&& xfer
->tx_buf
)
394 spi_test_print_hex_dump(" TX: ",
398 dev_info(&spi
->dev
, " rx_buf: %pK\n", xfer
->rx_buf
);
399 if (dump_data
&& xfer
->rx_buf
)
400 spi_test_print_hex_dump(" RX: ",
403 /* check for unwritten test pattern on rx_buf */
405 for (i
= 0 ; i
< xfer
->len
; i
++) {
406 b
= ((u8
*)xfer
->rx_buf
)[xfer
->len
- 1 - i
];
407 if (b
!= SPI_TEST_PATTERN_UNWRITTEN
)
412 " rx_buf filled with %02x starts at offset: %i\n",
413 SPI_TEST_PATTERN_UNWRITTEN
,
420 struct list_head list
;
425 static int rx_ranges_cmp(void *priv
, struct list_head
*a
, struct list_head
*b
)
427 struct rx_ranges
*rx_a
= list_entry(a
, struct rx_ranges
, list
);
428 struct rx_ranges
*rx_b
= list_entry(b
, struct rx_ranges
, list
);
430 if (rx_a
->start
> rx_b
->start
)
432 if (rx_a
->start
< rx_b
->start
)
437 static int spi_check_rx_ranges(struct spi_device
*spi
,
438 struct spi_message
*msg
,
441 struct spi_transfer
*xfer
;
442 struct rx_ranges ranges
[SPI_TEST_MAX_TRANSFERS
], *r
;
444 LIST_HEAD(ranges_list
);
448 /* loop over all transfers to fill in the rx_ranges */
449 list_for_each_entry(xfer
, &msg
->transfers
, transfer_list
) {
450 /* if there is no rx, then no check is needed */
453 /* fill in the rx_range */
454 if (RANGE_CHECK(xfer
->rx_buf
, xfer
->len
,
455 rx
, SPI_TEST_MAX_SIZE_PLUS
)) {
456 ranges
[i
].start
= xfer
->rx_buf
;
457 ranges
[i
].end
= xfer
->rx_buf
+ xfer
->len
;
458 list_add(&ranges
[i
].list
, &ranges_list
);
463 /* if no ranges, then we can return and avoid the checks...*/
468 list_sort(NULL
, &ranges_list
, rx_ranges_cmp
);
470 /* and iterate over all the rx addresses */
471 for (addr
= rx
; addr
< (u8
*)rx
+ SPI_TEST_MAX_SIZE_PLUS
; addr
++) {
472 /* if we are the DO not write pattern,
473 * then continue with the loop...
475 if (*addr
== SPI_TEST_PATTERN_DO_NOT_WRITE
)
478 /* check if we are inside a range */
479 list_for_each_entry(r
, &ranges_list
, list
) {
480 /* if so then set to end... */
481 if ((addr
>= r
->start
) && (addr
< r
->end
))
484 /* second test after a (hopefull) translation */
485 if (*addr
== SPI_TEST_PATTERN_DO_NOT_WRITE
)
488 /* if still not found then something has modified too much */
489 /* we could list the "closest" transfer here... */
491 "loopback strangeness - rx changed outside of allowed range at: %pK\n",
493 /* do not return, only set ret,
494 * so that we list all addresses
502 static int spi_test_check_elapsed_time(struct spi_device
*spi
,
503 struct spi_test
*test
)
506 unsigned long long estimated_time
= 0;
507 unsigned long long delay_usecs
= 0;
509 for (i
= 0; i
< test
->transfer_count
; i
++) {
510 struct spi_transfer
*xfer
= test
->transfers
+ i
;
511 unsigned long long nbits
= (unsigned long long)BITS_PER_BYTE
*
514 delay_usecs
+= xfer
->delay_usecs
;
517 estimated_time
+= div_u64(nbits
* NSEC_PER_SEC
, xfer
->speed_hz
);
520 estimated_time
+= delay_usecs
* NSEC_PER_USEC
;
521 if (test
->elapsed_time
< estimated_time
) {
523 "elapsed time %lld ns is shorter than minimum estimated time %lld ns\n",
524 test
->elapsed_time
, estimated_time
);
532 static int spi_test_check_loopback_result(struct spi_device
*spi
,
533 struct spi_message
*msg
,
536 struct spi_transfer
*xfer
;
541 /* checks rx_buffer pattern are valid with loopback or without */
542 ret
= spi_check_rx_ranges(spi
, msg
, rx
);
546 /* if we run without loopback, then return now */
550 /* if applicable to transfer check that rx_buf is equal to tx_buf */
551 list_for_each_entry(xfer
, &msg
->transfers
, transfer_list
) {
552 /* if there is no rx, then no check is needed */
553 if (!xfer
->len
|| !xfer
->rx_buf
)
555 /* so depending on tx_buf we need to handle things */
557 for (i
= 0; i
< xfer
->len
; i
++) {
558 txb
= ((u8
*)xfer
->tx_buf
)[i
];
559 rxb
= ((u8
*)xfer
->rx_buf
)[i
];
564 /* first byte received */
565 txb
= ((u8
*)xfer
->rx_buf
)[0];
566 /* first byte may be 0 or xff */
567 if (!((txb
== 0) || (txb
== 0xff))) {
569 "loopback strangeness - we expect 0x00 or 0xff, but not 0x%02x\n",
573 /* check that all bytes are identical */
574 for (i
= 1; i
< xfer
->len
; i
++) {
575 rxb
= ((u8
*)xfer
->rx_buf
)[i
];
586 "loopback strangeness - transfer mismatch on byte %04zx - expected 0x%02x, but got 0x%02x\n",
592 static int spi_test_translate(struct spi_device
*spi
,
593 void **ptr
, size_t len
,
602 /* in the MAX_SIZE_HALF case modify the pointer */
603 if (((size_t)*ptr
) & SPI_TEST_MAX_SIZE_HALF
)
604 /* move the pointer to the correct range */
605 *ptr
+= (SPI_TEST_MAX_SIZE_PLUS
/ 2) -
606 SPI_TEST_MAX_SIZE_HALF
;
609 * - we check against MAX_SIZE_PLUS to allow for automated alignment
611 if (RANGE_CHECK(*ptr
, len
, RX(0), SPI_TEST_MAX_SIZE_PLUS
)) {
619 if (RANGE_CHECK(*ptr
, len
, TX(0), SPI_TEST_MAX_SIZE_PLUS
)) {
627 "PointerRange [%pK:%pK[ not in range [%pK:%pK[ or [%pK:%pK[\n",
629 RX(0), RX(SPI_TEST_MAX_SIZE
),
630 TX(0), TX(SPI_TEST_MAX_SIZE
));
635 static int spi_test_fill_pattern(struct spi_device
*spi
,
636 struct spi_test
*test
)
638 struct spi_transfer
*xfers
= test
->transfers
;
644 #define GET_VALUE_BYTE(value, index, bytes) \
645 (value >> (8 * (bytes - 1 - count % bytes)))
647 #define GET_VALUE_BYTE(value, index, bytes) \
648 (value >> (8 * (count % bytes)))
651 /* fill all transfers with the pattern requested */
652 for (i
= 0; i
< test
->transfer_count
; i
++) {
653 /* fill rx_buf with SPI_TEST_PATTERN_UNWRITTEN */
655 memset(xfers
[i
].rx_buf
, SPI_TEST_PATTERN_UNWRITTEN
,
657 /* if tx_buf is NULL then skip */
658 tx_buf
= (u8
*)xfers
[i
].tx_buf
;
661 /* modify all the transfers */
662 for (j
= 0; j
< xfers
[i
].len
; j
++, tx_buf
++, count
++) {
664 switch (test
->fill_option
) {
666 *tx_buf
= test
->fill_pattern
;
669 *tx_buf
= GET_VALUE_BYTE(test
->fill_pattern
,
673 *tx_buf
= GET_VALUE_BYTE(test
->fill_pattern
,
677 *tx_buf
= GET_VALUE_BYTE(test
->fill_pattern
,
684 *tx_buf
= GET_VALUE_BYTE(count
, count
, 2);
687 *tx_buf
= GET_VALUE_BYTE(count
, count
, 3);
690 *tx_buf
= GET_VALUE_BYTE(count
, count
, 4);
692 case FILL_TRANSFER_BYTE_8
:
695 case FILL_TRANSFER_BYTE_16
:
696 *tx_buf
= GET_VALUE_BYTE(j
, j
, 2);
698 case FILL_TRANSFER_BYTE_24
:
699 *tx_buf
= GET_VALUE_BYTE(j
, j
, 3);
701 case FILL_TRANSFER_BYTE_32
:
702 *tx_buf
= GET_VALUE_BYTE(j
, j
, 4);
704 case FILL_TRANSFER_NUM
:
709 "unsupported fill_option: %i\n",
719 static int _spi_test_run_iter(struct spi_device
*spi
,
720 struct spi_test
*test
,
723 struct spi_message
*msg
= &test
->msg
;
724 struct spi_transfer
*x
;
727 /* initialize message - zero-filled via static initialization */
728 spi_message_init_no_memset(msg
);
730 /* fill rx with the DO_NOT_WRITE pattern */
731 memset(rx
, SPI_TEST_PATTERN_DO_NOT_WRITE
, SPI_TEST_MAX_SIZE_PLUS
);
733 /* add the individual transfers */
734 for (i
= 0; i
< test
->transfer_count
; i
++) {
735 x
= &test
->transfers
[i
];
737 /* patch the values of tx_buf */
738 ret
= spi_test_translate(spi
, (void **)&x
->tx_buf
, x
->len
,
743 /* patch the values of rx_buf */
744 ret
= spi_test_translate(spi
, &x
->rx_buf
, x
->len
,
749 /* and add it to the list */
750 spi_message_add_tail(x
, msg
);
753 /* fill in the transfer buffers with pattern */
754 ret
= spi_test_fill_pattern(spi
, test
);
759 if (test
->execute_msg
)
760 ret
= test
->execute_msg(spi
, test
, tx
, rx
);
762 ret
= spi_test_execute_msg(spi
, test
, tx
, rx
);
765 if (ret
== test
->expected_return
)
769 "test failed - test returned %i, but we expect %i\n",
770 ret
, test
->expected_return
);
775 /* if it is 0, as we expected something else,
776 * then return something special
781 static int spi_test_run_iter(struct spi_device
*spi
,
782 const struct spi_test
*testtemplate
,
789 struct spi_test test
;
790 int i
, tx_count
, rx_count
;
792 /* copy the test template to test */
793 memcpy(&test
, testtemplate
, sizeof(test
));
795 /* if iterate_transfer_mask is not set,
796 * then set it to first transfer only
798 if (!(test
.iterate_transfer_mask
& (BIT(test
.transfer_count
) - 1)))
799 test
.iterate_transfer_mask
= 1;
801 /* count number of transfers with tx/rx_buf != NULL */
802 rx_count
= tx_count
= 0;
803 for (i
= 0; i
< test
.transfer_count
; i
++) {
804 if (test
.transfers
[i
].tx_buf
)
806 if (test
.transfers
[i
].rx_buf
)
810 /* in some iteration cases warn and exit early,
811 * as there is nothing to do, that has not been tested already...
813 if (tx_off
&& (!tx_count
)) {
814 dev_warn_once(&spi
->dev
,
815 "%s: iterate_tx_off configured with tx_buf==NULL - ignoring\n",
819 if (rx_off
&& (!rx_count
)) {
820 dev_warn_once(&spi
->dev
,
821 "%s: iterate_rx_off configured with rx_buf==NULL - ignoring\n",
827 if (!(len
|| tx_off
|| rx_off
)) {
828 dev_info(&spi
->dev
, "Running test %s\n", test
.description
);
831 " with iteration values: len = %zu, tx_off = %zu, rx_off = %zu\n",
832 len
, tx_off
, rx_off
);
835 /* update in the values from iteration values */
836 for (i
= 0; i
< test
.transfer_count
; i
++) {
837 /* only when bit in transfer mask is set */
838 if (!(test
.iterate_transfer_mask
& BIT(i
)))
840 test
.transfers
[i
].len
= len
;
841 if (test
.transfers
[i
].tx_buf
)
842 test
.transfers
[i
].tx_buf
+= tx_off
;
843 if (test
.transfers
[i
].tx_buf
)
844 test
.transfers
[i
].rx_buf
+= rx_off
;
848 return _spi_test_run_iter(spi
, &test
, tx
, rx
);
852 * spi_test_execute_msg - default implementation to run a test
854 * spi: @spi_device on which to run the @spi_message
855 * test: the test to execute, which already contains @msg
856 * tx: the tx buffer allocated for the test sequence
857 * rx: the rx buffer allocated for the test sequence
859 * Returns: error code of spi_sync as well as basic error checking
861 int spi_test_execute_msg(struct spi_device
*spi
, struct spi_test
*test
,
864 struct spi_message
*msg
= &test
->msg
;
868 /* only if we do not simulate */
869 if (!simulate_only
) {
872 /* dump the complete message before and after the transfer */
873 if (dump_messages
== 3)
874 spi_test_dump_message(spi
, msg
, true);
877 /* run spi message */
878 ret
= spi_sync(spi
, msg
);
879 test
->elapsed_time
= ktime_to_ns(ktime_sub(ktime_get(), start
));
880 if (ret
== -ETIMEDOUT
) {
882 "spi-message timed out - reruning...\n");
883 /* rerun after a few explicit schedules */
884 for (i
= 0; i
< 16; i
++)
886 ret
= spi_sync(spi
, msg
);
890 "Failed to execute spi_message: %i\n",
895 /* do some extra error checks */
896 if (msg
->frame_length
!= msg
->actual_length
) {
898 "actual length differs from expected\n");
903 /* run rx-buffer tests */
904 ret
= spi_test_check_loopback_result(spi
, msg
, tx
, rx
);
908 ret
= spi_test_check_elapsed_time(spi
, test
);
911 /* if requested or on error dump message (including data) */
913 if (dump_messages
|| ret
)
914 spi_test_dump_message(spi
, msg
,
915 (dump_messages
>= 2) || (ret
));
919 EXPORT_SYMBOL_GPL(spi_test_execute_msg
);
922 * spi_test_run_test - run an individual spi_test
923 * including all the relevant iterations on:
924 * length and buffer alignment
926 * spi: the spi_device to send the messages to
927 * test: the test which we need to execute
928 * tx: the tx buffer allocated for the test sequence
929 * rx: the rx buffer allocated for the test sequence
931 * Returns: status code of spi_sync or other failures
934 int spi_test_run_test(struct spi_device
*spi
, const struct spi_test
*test
,
939 size_t tx_align
, rx_align
;
942 /* test for transfer limits */
943 if (test
->transfer_count
>= SPI_TEST_MAX_TRANSFERS
) {
945 "%s: Exceeded max number of transfers with %i\n",
946 test
->description
, test
->transfer_count
);
950 /* setting up some values in spi_message
951 * based on some settings in spi_master
952 * some of this can also get done in the run() method
955 /* iterate over all the iterable values using macros
956 * (to make it a bit more readable...
958 #define FOR_EACH_ALIGNMENT(var) \
960 var < (test->iterate_##var ? \
961 (spi->master->dma_alignment ? \
962 spi->master->dma_alignment : \
963 test->iterate_##var) : \
967 for (idx_len
= 0; idx_len
< SPI_TEST_MAX_ITERATE
&&
968 (len
= test
->iterate_len
[idx_len
]) != -1; idx_len
++) {
969 FOR_EACH_ALIGNMENT(tx_align
) {
970 FOR_EACH_ALIGNMENT(rx_align
) {
971 /* and run the iteration */
972 ret
= spi_test_run_iter(spi
, test
,
985 EXPORT_SYMBOL_GPL(spi_test_run_test
);
988 * spi_test_run_tests - run an array of spi_messages tests
989 * @spi: the spi device on which to run the tests
990 * @tests: NULL-terminated array of @spi_test
992 * Returns: status errors as per @spi_test_run_test()
995 int spi_test_run_tests(struct spi_device
*spi
,
996 struct spi_test
*tests
)
998 char *rx
= NULL
, *tx
= NULL
;
999 int ret
= 0, count
= 0;
1000 struct spi_test
*test
;
1002 /* allocate rx/tx buffers of 128kB size without devm
1003 * in the hope that is on a page boundary
1005 rx
= kzalloc(SPI_TEST_MAX_SIZE_PLUS
, GFP_KERNEL
);
1011 tx
= kzalloc(SPI_TEST_MAX_SIZE_PLUS
, GFP_KERNEL
);
1017 /* now run the individual tests in the table */
1018 for (test
= tests
, count
= 0; test
->description
[0];
1020 /* only run test if requested */
1021 if ((run_only_test
> -1) && (count
!= run_only_test
))
1023 /* run custom implementation */
1025 ret
= test
->run_test(spi
, test
, tx
, rx
);
1027 ret
= spi_test_run_test(spi
, test
, tx
, rx
);
1030 /* add some delays so that we can easily
1031 * detect the individual tests when using a logic analyzer
1032 * we also add scheduling to avoid potential spi_timeouts...
1043 EXPORT_SYMBOL_GPL(spi_test_run_tests
);