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/vmalloc.h>
30 #include <linux/spi/spi.h>
34 /* flag to only simulate transfers */
36 module_param(simulate_only
, int, 0);
37 MODULE_PARM_DESC(simulate_only
, "if not 0 do not execute the spi message");
39 /* dump spi messages */
41 module_param(dump_messages
, int, 0);
42 MODULE_PARM_DESC(dump_messages
,
43 "=1 dump the basic spi_message_structure, " \
44 "=2 dump the spi_message_structure including data, " \
45 "=3 dump the spi_message structure before and after execution");
46 /* the device is jumpered for loopback - enabling some rx_buf tests */
48 module_param(loopback
, int, 0);
49 MODULE_PARM_DESC(loopback
,
50 "if set enable loopback mode, where the rx_buf " \
51 "is checked to match tx_buf after the spi_message " \
54 /* run only a specific test */
55 int run_only_test
= -1;
56 module_param(run_only_test
, int, 0);
57 MODULE_PARM_DESC(run_only_test
,
58 "only run the test with this number (0-based !)");
60 /* use vmalloc'ed buffers */
62 module_param(use_vmalloc
, int, 0644);
63 MODULE_PARM_DESC(use_vmalloc
,
64 "use vmalloc'ed buffers instead of kmalloc'ed");
68 module_param(check_ranges
, int, 0644);
69 MODULE_PARM_DESC(check_ranges
,
70 "checks rx_buffer pattern are valid");
72 /* the actual tests to execute */
73 static struct spi_test spi_tests
[] = {
75 .description
= "tx/rx-transfer - start of page",
76 .fill_option
= FILL_COUNT_8
,
77 .iterate_len
= { ITERATE_MAX_LEN
},
78 .iterate_tx_align
= ITERATE_ALIGN
,
79 .iterate_rx_align
= ITERATE_ALIGN
,
89 .description
= "tx/rx-transfer - crossing PAGE_SIZE",
90 .fill_option
= FILL_COUNT_8
,
91 .iterate_len
= { ITERATE_MAX_LEN
},
92 .iterate_tx_align
= ITERATE_ALIGN
,
93 .iterate_rx_align
= ITERATE_ALIGN
,
97 .tx_buf
= TX(PAGE_SIZE
- 4),
98 .rx_buf
= RX(PAGE_SIZE
- 4),
103 .description
= "tx-transfer - only",
104 .fill_option
= FILL_COUNT_8
,
105 .iterate_len
= { ITERATE_MAX_LEN
},
106 .iterate_tx_align
= ITERATE_ALIGN
,
115 .description
= "rx-transfer - only",
116 .fill_option
= FILL_COUNT_8
,
117 .iterate_len
= { ITERATE_MAX_LEN
},
118 .iterate_rx_align
= ITERATE_ALIGN
,
127 .description
= "two tx-transfers - alter both",
128 .fill_option
= FILL_COUNT_8
,
129 .iterate_len
= { ITERATE_LEN
},
130 .iterate_tx_align
= ITERATE_ALIGN
,
131 .iterate_transfer_mask
= BIT(0) | BIT(1),
138 /* this is why we cant use ITERATE_MAX_LEN */
139 .tx_buf
= TX(SPI_TEST_MAX_SIZE_HALF
),
144 .description
= "two tx-transfers - alter first",
145 .fill_option
= FILL_COUNT_8
,
146 .iterate_len
= { ITERATE_MAX_LEN
},
147 .iterate_tx_align
= ITERATE_ALIGN
,
148 .iterate_transfer_mask
= BIT(0),
161 .description
= "two tx-transfers - alter second",
162 .fill_option
= FILL_COUNT_8
,
163 .iterate_len
= { ITERATE_MAX_LEN
},
164 .iterate_tx_align
= ITERATE_ALIGN
,
165 .iterate_transfer_mask
= BIT(1),
178 .description
= "two transfers tx then rx - alter both",
179 .fill_option
= FILL_COUNT_8
,
180 .iterate_len
= { ITERATE_MAX_LEN
},
181 .iterate_tx_align
= ITERATE_ALIGN
,
182 .iterate_transfer_mask
= BIT(0) | BIT(1),
194 .description
= "two transfers tx then rx - alter tx",
195 .fill_option
= FILL_COUNT_8
,
196 .iterate_len
= { ITERATE_MAX_LEN
},
197 .iterate_tx_align
= ITERATE_ALIGN
,
198 .iterate_transfer_mask
= BIT(0),
211 .description
= "two transfers tx then rx - alter rx",
212 .fill_option
= FILL_COUNT_8
,
213 .iterate_len
= { ITERATE_MAX_LEN
},
214 .iterate_tx_align
= ITERATE_ALIGN
,
215 .iterate_transfer_mask
= BIT(1),
228 .description
= "two tx+rx transfers - alter both",
229 .fill_option
= FILL_COUNT_8
,
230 .iterate_len
= { ITERATE_LEN
},
231 .iterate_tx_align
= ITERATE_ALIGN
,
232 .iterate_transfer_mask
= BIT(0) | BIT(1),
240 /* making sure we align without overwrite
241 * the reason we can not use ITERATE_MAX_LEN
243 .tx_buf
= TX(SPI_TEST_MAX_SIZE_HALF
),
244 .rx_buf
= RX(SPI_TEST_MAX_SIZE_HALF
),
249 .description
= "two tx+rx transfers - alter first",
250 .fill_option
= FILL_COUNT_8
,
251 .iterate_len
= { ITERATE_MAX_LEN
},
252 .iterate_tx_align
= ITERATE_ALIGN
,
253 .iterate_transfer_mask
= BIT(0),
257 /* making sure we align without overwrite */
263 /* making sure we align without overwrite */
270 .description
= "two tx+rx transfers - alter second",
271 .fill_option
= FILL_COUNT_8
,
272 .iterate_len
= { ITERATE_MAX_LEN
},
273 .iterate_tx_align
= ITERATE_ALIGN
,
274 .iterate_transfer_mask
= BIT(1),
283 /* making sure we align without overwrite */
290 .description
= "two tx+rx transfers - delay after transfer",
291 .fill_option
= FILL_COUNT_8
,
292 .iterate_len
= { ITERATE_MAX_LEN
},
293 .iterate_transfer_mask
= BIT(0) | BIT(1),
309 { /* end of tests sequence */ }
312 static int spi_loopback_test_probe(struct spi_device
*spi
)
316 dev_info(&spi
->dev
, "Executing spi-loopback-tests\n");
318 ret
= spi_test_run_tests(spi
, spi_tests
);
320 dev_info(&spi
->dev
, "Finished spi-loopback-tests with return: %i\n",
326 /* non const match table to permit to change via a module parameter */
327 static struct of_device_id spi_loopback_test_of_match
[] = {
328 { .compatible
= "linux,spi-loopback-test", },
332 /* allow to override the compatible string via a module_parameter */
333 module_param_string(compatible
, spi_loopback_test_of_match
[0].compatible
,
334 sizeof(spi_loopback_test_of_match
[0].compatible
),
337 MODULE_DEVICE_TABLE(of
, spi_loopback_test_of_match
);
339 static struct spi_driver spi_loopback_test_driver
= {
341 .name
= "spi-loopback-test",
342 .owner
= THIS_MODULE
,
343 .of_match_table
= spi_loopback_test_of_match
,
345 .probe
= spi_loopback_test_probe
,
348 module_spi_driver(spi_loopback_test_driver
);
350 MODULE_AUTHOR("Martin Sperl <kernel@martin.sperl.org>");
351 MODULE_DESCRIPTION("test spi_driver to check core functionality");
352 MODULE_LICENSE("GPL");
354 /*-------------------------------------------------------------------------*/
356 /* spi_test implementation */
358 #define RANGE_CHECK(ptr, plen, start, slen) \
359 ((ptr >= start) && (ptr + plen <= start + slen))
361 /* we allocate one page more, to allow for offsets */
362 #define SPI_TEST_MAX_SIZE_PLUS (SPI_TEST_MAX_SIZE + PAGE_SIZE)
364 static void spi_test_print_hex_dump(char *pre
, const void *ptr
, size_t len
)
366 /* limit the hex_dump */
368 print_hex_dump(KERN_INFO
, pre
,
369 DUMP_PREFIX_OFFSET
, 16, 1,
374 print_hex_dump(KERN_INFO
, pre
,
375 DUMP_PREFIX_OFFSET
, 16, 1,
378 pr_info("%s truncated - continuing at offset %04zx\n",
380 print_hex_dump(KERN_INFO
, pre
,
381 DUMP_PREFIX_OFFSET
, 16, 1,
382 ptr
+ (len
- 512), 512, 0);
385 static void spi_test_dump_message(struct spi_device
*spi
,
386 struct spi_message
*msg
,
389 struct spi_transfer
*xfer
;
393 dev_info(&spi
->dev
, " spi_msg@%pK\n", msg
);
395 dev_info(&spi
->dev
, " status: %i\n",
397 dev_info(&spi
->dev
, " frame_length: %i\n",
399 dev_info(&spi
->dev
, " actual_length: %i\n",
402 list_for_each_entry(xfer
, &msg
->transfers
, transfer_list
) {
403 dev_info(&spi
->dev
, " spi_transfer@%pK\n", xfer
);
404 dev_info(&spi
->dev
, " len: %i\n", xfer
->len
);
405 dev_info(&spi
->dev
, " tx_buf: %pK\n", xfer
->tx_buf
);
406 if (dump_data
&& xfer
->tx_buf
)
407 spi_test_print_hex_dump(" TX: ",
411 dev_info(&spi
->dev
, " rx_buf: %pK\n", xfer
->rx_buf
);
412 if (dump_data
&& xfer
->rx_buf
)
413 spi_test_print_hex_dump(" RX: ",
416 /* check for unwritten test pattern on rx_buf */
418 for (i
= 0 ; i
< xfer
->len
; i
++) {
419 b
= ((u8
*)xfer
->rx_buf
)[xfer
->len
- 1 - i
];
420 if (b
!= SPI_TEST_PATTERN_UNWRITTEN
)
425 " rx_buf filled with %02x starts at offset: %i\n",
426 SPI_TEST_PATTERN_UNWRITTEN
,
433 struct list_head list
;
438 static int rx_ranges_cmp(void *priv
, struct list_head
*a
, struct list_head
*b
)
440 struct rx_ranges
*rx_a
= list_entry(a
, struct rx_ranges
, list
);
441 struct rx_ranges
*rx_b
= list_entry(b
, struct rx_ranges
, list
);
443 if (rx_a
->start
> rx_b
->start
)
445 if (rx_a
->start
< rx_b
->start
)
450 static int spi_check_rx_ranges(struct spi_device
*spi
,
451 struct spi_message
*msg
,
454 struct spi_transfer
*xfer
;
455 struct rx_ranges ranges
[SPI_TEST_MAX_TRANSFERS
], *r
;
457 LIST_HEAD(ranges_list
);
461 /* loop over all transfers to fill in the rx_ranges */
462 list_for_each_entry(xfer
, &msg
->transfers
, transfer_list
) {
463 /* if there is no rx, then no check is needed */
466 /* fill in the rx_range */
467 if (RANGE_CHECK(xfer
->rx_buf
, xfer
->len
,
468 rx
, SPI_TEST_MAX_SIZE_PLUS
)) {
469 ranges
[i
].start
= xfer
->rx_buf
;
470 ranges
[i
].end
= xfer
->rx_buf
+ xfer
->len
;
471 list_add(&ranges
[i
].list
, &ranges_list
);
476 /* if no ranges, then we can return and avoid the checks...*/
481 list_sort(NULL
, &ranges_list
, rx_ranges_cmp
);
483 /* and iterate over all the rx addresses */
484 for (addr
= rx
; addr
< (u8
*)rx
+ SPI_TEST_MAX_SIZE_PLUS
; addr
++) {
485 /* if we are the DO not write pattern,
486 * then continue with the loop...
488 if (*addr
== SPI_TEST_PATTERN_DO_NOT_WRITE
)
491 /* check if we are inside a range */
492 list_for_each_entry(r
, &ranges_list
, list
) {
493 /* if so then set to end... */
494 if ((addr
>= r
->start
) && (addr
< r
->end
))
497 /* second test after a (hopefull) translation */
498 if (*addr
== SPI_TEST_PATTERN_DO_NOT_WRITE
)
501 /* if still not found then something has modified too much */
502 /* we could list the "closest" transfer here... */
504 "loopback strangeness - rx changed outside of allowed range at: %pK\n",
506 /* do not return, only set ret,
507 * so that we list all addresses
515 static int spi_test_check_elapsed_time(struct spi_device
*spi
,
516 struct spi_test
*test
)
519 unsigned long long estimated_time
= 0;
520 unsigned long long delay_usecs
= 0;
522 for (i
= 0; i
< test
->transfer_count
; i
++) {
523 struct spi_transfer
*xfer
= test
->transfers
+ i
;
524 unsigned long long nbits
= (unsigned long long)BITS_PER_BYTE
*
527 delay_usecs
+= xfer
->delay_usecs
;
530 estimated_time
+= div_u64(nbits
* NSEC_PER_SEC
, xfer
->speed_hz
);
533 estimated_time
+= delay_usecs
* NSEC_PER_USEC
;
534 if (test
->elapsed_time
< estimated_time
) {
536 "elapsed time %lld ns is shorter than minimum estimated time %lld ns\n",
537 test
->elapsed_time
, estimated_time
);
545 static int spi_test_check_loopback_result(struct spi_device
*spi
,
546 struct spi_message
*msg
,
549 struct spi_transfer
*xfer
;
554 /* checks rx_buffer pattern are valid with loopback or without */
556 ret
= spi_check_rx_ranges(spi
, msg
, rx
);
561 /* if we run without loopback, then return now */
565 /* if applicable to transfer check that rx_buf is equal to tx_buf */
566 list_for_each_entry(xfer
, &msg
->transfers
, transfer_list
) {
567 /* if there is no rx, then no check is needed */
568 if (!xfer
->len
|| !xfer
->rx_buf
)
570 /* so depending on tx_buf we need to handle things */
572 for (i
= 0; i
< xfer
->len
; i
++) {
573 txb
= ((u8
*)xfer
->tx_buf
)[i
];
574 rxb
= ((u8
*)xfer
->rx_buf
)[i
];
579 /* first byte received */
580 txb
= ((u8
*)xfer
->rx_buf
)[0];
581 /* first byte may be 0 or xff */
582 if (!((txb
== 0) || (txb
== 0xff))) {
584 "loopback strangeness - we expect 0x00 or 0xff, but not 0x%02x\n",
588 /* check that all bytes are identical */
589 for (i
= 1; i
< xfer
->len
; i
++) {
590 rxb
= ((u8
*)xfer
->rx_buf
)[i
];
601 "loopback strangeness - transfer mismatch on byte %04zx - expected 0x%02x, but got 0x%02x\n",
607 static int spi_test_translate(struct spi_device
*spi
,
608 void **ptr
, size_t len
,
617 /* in the MAX_SIZE_HALF case modify the pointer */
618 if (((size_t)*ptr
) & SPI_TEST_MAX_SIZE_HALF
)
619 /* move the pointer to the correct range */
620 *ptr
+= (SPI_TEST_MAX_SIZE_PLUS
/ 2) -
621 SPI_TEST_MAX_SIZE_HALF
;
624 * - we check against MAX_SIZE_PLUS to allow for automated alignment
626 if (RANGE_CHECK(*ptr
, len
, RX(0), SPI_TEST_MAX_SIZE_PLUS
)) {
634 if (RANGE_CHECK(*ptr
, len
, TX(0), SPI_TEST_MAX_SIZE_PLUS
)) {
642 "PointerRange [%pK:%pK[ not in range [%pK:%pK[ or [%pK:%pK[\n",
644 RX(0), RX(SPI_TEST_MAX_SIZE
),
645 TX(0), TX(SPI_TEST_MAX_SIZE
));
650 static int spi_test_fill_pattern(struct spi_device
*spi
,
651 struct spi_test
*test
)
653 struct spi_transfer
*xfers
= test
->transfers
;
659 #define GET_VALUE_BYTE(value, index, bytes) \
660 (value >> (8 * (bytes - 1 - count % bytes)))
662 #define GET_VALUE_BYTE(value, index, bytes) \
663 (value >> (8 * (count % bytes)))
666 /* fill all transfers with the pattern requested */
667 for (i
= 0; i
< test
->transfer_count
; i
++) {
668 /* fill rx_buf with SPI_TEST_PATTERN_UNWRITTEN */
670 memset(xfers
[i
].rx_buf
, SPI_TEST_PATTERN_UNWRITTEN
,
672 /* if tx_buf is NULL then skip */
673 tx_buf
= (u8
*)xfers
[i
].tx_buf
;
676 /* modify all the transfers */
677 for (j
= 0; j
< xfers
[i
].len
; j
++, tx_buf
++, count
++) {
679 switch (test
->fill_option
) {
681 *tx_buf
= test
->fill_pattern
;
684 *tx_buf
= GET_VALUE_BYTE(test
->fill_pattern
,
688 *tx_buf
= GET_VALUE_BYTE(test
->fill_pattern
,
692 *tx_buf
= GET_VALUE_BYTE(test
->fill_pattern
,
699 *tx_buf
= GET_VALUE_BYTE(count
, count
, 2);
702 *tx_buf
= GET_VALUE_BYTE(count
, count
, 3);
705 *tx_buf
= GET_VALUE_BYTE(count
, count
, 4);
707 case FILL_TRANSFER_BYTE_8
:
710 case FILL_TRANSFER_BYTE_16
:
711 *tx_buf
= GET_VALUE_BYTE(j
, j
, 2);
713 case FILL_TRANSFER_BYTE_24
:
714 *tx_buf
= GET_VALUE_BYTE(j
, j
, 3);
716 case FILL_TRANSFER_BYTE_32
:
717 *tx_buf
= GET_VALUE_BYTE(j
, j
, 4);
719 case FILL_TRANSFER_NUM
:
724 "unsupported fill_option: %i\n",
734 static int _spi_test_run_iter(struct spi_device
*spi
,
735 struct spi_test
*test
,
738 struct spi_message
*msg
= &test
->msg
;
739 struct spi_transfer
*x
;
742 /* initialize message - zero-filled via static initialization */
743 spi_message_init_no_memset(msg
);
745 /* fill rx with the DO_NOT_WRITE pattern */
746 memset(rx
, SPI_TEST_PATTERN_DO_NOT_WRITE
, SPI_TEST_MAX_SIZE_PLUS
);
748 /* add the individual transfers */
749 for (i
= 0; i
< test
->transfer_count
; i
++) {
750 x
= &test
->transfers
[i
];
752 /* patch the values of tx_buf */
753 ret
= spi_test_translate(spi
, (void **)&x
->tx_buf
, x
->len
,
758 /* patch the values of rx_buf */
759 ret
= spi_test_translate(spi
, &x
->rx_buf
, x
->len
,
764 /* and add it to the list */
765 spi_message_add_tail(x
, msg
);
768 /* fill in the transfer buffers with pattern */
769 ret
= spi_test_fill_pattern(spi
, test
);
774 if (test
->execute_msg
)
775 ret
= test
->execute_msg(spi
, test
, tx
, rx
);
777 ret
= spi_test_execute_msg(spi
, test
, tx
, rx
);
780 if (ret
== test
->expected_return
)
784 "test failed - test returned %i, but we expect %i\n",
785 ret
, test
->expected_return
);
790 /* if it is 0, as we expected something else,
791 * then return something special
796 static int spi_test_run_iter(struct spi_device
*spi
,
797 const struct spi_test
*testtemplate
,
804 struct spi_test test
;
805 int i
, tx_count
, rx_count
;
807 /* copy the test template to test */
808 memcpy(&test
, testtemplate
, sizeof(test
));
810 /* if iterate_transfer_mask is not set,
811 * then set it to first transfer only
813 if (!(test
.iterate_transfer_mask
& (BIT(test
.transfer_count
) - 1)))
814 test
.iterate_transfer_mask
= 1;
816 /* count number of transfers with tx/rx_buf != NULL */
817 rx_count
= tx_count
= 0;
818 for (i
= 0; i
< test
.transfer_count
; i
++) {
819 if (test
.transfers
[i
].tx_buf
)
821 if (test
.transfers
[i
].rx_buf
)
825 /* in some iteration cases warn and exit early,
826 * as there is nothing to do, that has not been tested already...
828 if (tx_off
&& (!tx_count
)) {
829 dev_warn_once(&spi
->dev
,
830 "%s: iterate_tx_off configured with tx_buf==NULL - ignoring\n",
834 if (rx_off
&& (!rx_count
)) {
835 dev_warn_once(&spi
->dev
,
836 "%s: iterate_rx_off configured with rx_buf==NULL - ignoring\n",
842 if (!(len
|| tx_off
|| rx_off
)) {
843 dev_info(&spi
->dev
, "Running test %s\n", test
.description
);
846 " with iteration values: len = %zu, tx_off = %zu, rx_off = %zu\n",
847 len
, tx_off
, rx_off
);
850 /* update in the values from iteration values */
851 for (i
= 0; i
< test
.transfer_count
; i
++) {
852 /* only when bit in transfer mask is set */
853 if (!(test
.iterate_transfer_mask
& BIT(i
)))
855 test
.transfers
[i
].len
= len
;
856 if (test
.transfers
[i
].tx_buf
)
857 test
.transfers
[i
].tx_buf
+= tx_off
;
858 if (test
.transfers
[i
].tx_buf
)
859 test
.transfers
[i
].rx_buf
+= rx_off
;
863 return _spi_test_run_iter(spi
, &test
, tx
, rx
);
867 * spi_test_execute_msg - default implementation to run a test
869 * spi: @spi_device on which to run the @spi_message
870 * test: the test to execute, which already contains @msg
871 * tx: the tx buffer allocated for the test sequence
872 * rx: the rx buffer allocated for the test sequence
874 * Returns: error code of spi_sync as well as basic error checking
876 int spi_test_execute_msg(struct spi_device
*spi
, struct spi_test
*test
,
879 struct spi_message
*msg
= &test
->msg
;
883 /* only if we do not simulate */
884 if (!simulate_only
) {
887 /* dump the complete message before and after the transfer */
888 if (dump_messages
== 3)
889 spi_test_dump_message(spi
, msg
, true);
892 /* run spi message */
893 ret
= spi_sync(spi
, msg
);
894 test
->elapsed_time
= ktime_to_ns(ktime_sub(ktime_get(), start
));
895 if (ret
== -ETIMEDOUT
) {
897 "spi-message timed out - reruning...\n");
898 /* rerun after a few explicit schedules */
899 for (i
= 0; i
< 16; i
++)
901 ret
= spi_sync(spi
, msg
);
905 "Failed to execute spi_message: %i\n",
910 /* do some extra error checks */
911 if (msg
->frame_length
!= msg
->actual_length
) {
913 "actual length differs from expected\n");
918 /* run rx-buffer tests */
919 ret
= spi_test_check_loopback_result(spi
, msg
, tx
, rx
);
923 ret
= spi_test_check_elapsed_time(spi
, test
);
926 /* if requested or on error dump message (including data) */
928 if (dump_messages
|| ret
)
929 spi_test_dump_message(spi
, msg
,
930 (dump_messages
>= 2) || (ret
));
934 EXPORT_SYMBOL_GPL(spi_test_execute_msg
);
937 * spi_test_run_test - run an individual spi_test
938 * including all the relevant iterations on:
939 * length and buffer alignment
941 * spi: the spi_device to send the messages to
942 * test: the test which we need to execute
943 * tx: the tx buffer allocated for the test sequence
944 * rx: the rx buffer allocated for the test sequence
946 * Returns: status code of spi_sync or other failures
949 int spi_test_run_test(struct spi_device
*spi
, const struct spi_test
*test
,
954 size_t tx_align
, rx_align
;
957 /* test for transfer limits */
958 if (test
->transfer_count
>= SPI_TEST_MAX_TRANSFERS
) {
960 "%s: Exceeded max number of transfers with %i\n",
961 test
->description
, test
->transfer_count
);
965 /* setting up some values in spi_message
966 * based on some settings in spi_master
967 * some of this can also get done in the run() method
970 /* iterate over all the iterable values using macros
971 * (to make it a bit more readable...
973 #define FOR_EACH_ALIGNMENT(var) \
975 var < (test->iterate_##var ? \
976 (spi->master->dma_alignment ? \
977 spi->master->dma_alignment : \
978 test->iterate_##var) : \
982 for (idx_len
= 0; idx_len
< SPI_TEST_MAX_ITERATE
&&
983 (len
= test
->iterate_len
[idx_len
]) != -1; idx_len
++) {
984 FOR_EACH_ALIGNMENT(tx_align
) {
985 FOR_EACH_ALIGNMENT(rx_align
) {
986 /* and run the iteration */
987 ret
= spi_test_run_iter(spi
, test
,
1000 EXPORT_SYMBOL_GPL(spi_test_run_test
);
1003 * spi_test_run_tests - run an array of spi_messages tests
1004 * @spi: the spi device on which to run the tests
1005 * @tests: NULL-terminated array of @spi_test
1007 * Returns: status errors as per @spi_test_run_test()
1010 int spi_test_run_tests(struct spi_device
*spi
,
1011 struct spi_test
*tests
)
1013 char *rx
= NULL
, *tx
= NULL
;
1014 int ret
= 0, count
= 0;
1015 struct spi_test
*test
;
1017 /* allocate rx/tx buffers of 128kB size without devm
1018 * in the hope that is on a page boundary
1021 rx
= vmalloc(SPI_TEST_MAX_SIZE_PLUS
);
1023 rx
= kzalloc(SPI_TEST_MAX_SIZE_PLUS
, GFP_KERNEL
);
1030 tx
= vmalloc(SPI_TEST_MAX_SIZE_PLUS
);
1032 tx
= kzalloc(SPI_TEST_MAX_SIZE_PLUS
, GFP_KERNEL
);
1038 /* now run the individual tests in the table */
1039 for (test
= tests
, count
= 0; test
->description
[0];
1041 /* only run test if requested */
1042 if ((run_only_test
> -1) && (count
!= run_only_test
))
1044 /* run custom implementation */
1046 ret
= test
->run_test(spi
, test
, tx
, rx
);
1048 ret
= spi_test_run_test(spi
, test
, tx
, rx
);
1051 /* add some delays so that we can easily
1052 * detect the individual tests when using a logic analyzer
1053 * we also add scheduling to avoid potential spi_timeouts...
1064 EXPORT_SYMBOL_GPL(spi_test_run_tests
);