• Home
  • Raw
  • Download

Lines Matching +full:rx +full:- +full:tx

2  *  linux/drivers/spi/spi-loopback-test.c
32 #include "spi-test.h"
46 /* the device is jumpered for loopback - enabling some rx_buf tests */
66 static int run_only_test = -1;
69 "only run the test with this number (0-based !)");
77 /* check rx ranges */
86 .description = "tx/rx-transfer - start of page",
94 .tx_buf = TX(0),
95 .rx_buf = RX(0),
100 .description = "tx/rx-transfer - crossing PAGE_SIZE",
108 .tx_buf = TX(PAGE_SIZE - 4),
109 .rx_buf = RX(PAGE_SIZE - 4),
114 .description = "tx-transfer - only",
121 .tx_buf = TX(0),
126 .description = "rx-transfer - only",
133 .rx_buf = RX(0),
138 .description = "two tx-transfers - alter both",
146 .tx_buf = TX(0),
150 .tx_buf = TX(SPI_TEST_MAX_SIZE_HALF),
155 .description = "two tx-transfers - alter first",
163 .tx_buf = TX(64),
167 .tx_buf = TX(0),
172 .description = "two tx-transfers - alter second",
181 .tx_buf = TX(0),
184 .tx_buf = TX(64),
189 .description = "two transfers tx then rx - alter both",
197 .tx_buf = TX(0),
200 .rx_buf = RX(0),
205 .description = "two transfers tx then rx - alter tx",
213 .tx_buf = TX(0),
217 .rx_buf = RX(0),
222 .description = "two transfers tx then rx - alter rx",
231 .tx_buf = TX(0),
234 .rx_buf = RX(0),
239 .description = "two tx+rx transfers - alter both",
247 .tx_buf = TX(0),
248 .rx_buf = RX(0),
254 .tx_buf = TX(SPI_TEST_MAX_SIZE_HALF),
255 .rx_buf = RX(SPI_TEST_MAX_SIZE_HALF),
260 .description = "two tx+rx transfers - alter first",
269 .tx_buf = TX(1024),
270 .rx_buf = RX(1024),
275 .tx_buf = TX(0),
276 .rx_buf = RX(0),
281 .description = "two tx+rx transfers - alter second",
290 .tx_buf = TX(0),
291 .rx_buf = RX(0),
295 .tx_buf = TX(1024),
296 .rx_buf = RX(1024),
301 .description = "two tx+rx transfers - delay after transfer",
308 .tx_buf = TX(0),
309 .rx_buf = RX(0),
313 .tx_buf = TX(0),
314 .rx_buf = RX(0),
328 spi->mode |= loop_req ? SPI_LOOP : 0; in spi_loopback_test_probe()
329 spi->mode |= no_cs ? SPI_NO_CS : 0; in spi_loopback_test_probe()
332 dev_err(&spi->dev, "SPI setup with SPI_LOOP or SPI_NO_CS failed (%d)\n", in spi_loopback_test_probe()
338 dev_info(&spi->dev, "Executing spi-loopback-tests\n"); in spi_loopback_test_probe()
342 dev_info(&spi->dev, "Finished spi-loopback-tests with return: %i\n", in spi_loopback_test_probe()
350 { .compatible = "linux,spi-loopback-test", },
363 .name = "spi-loopback-test",
376 /*-------------------------------------------------------------------------*/
400 pr_info("%s truncated - continuing at offset %04zx\n", in spi_test_print_hex_dump()
401 pre, len - 512); in spi_test_print_hex_dump()
404 ptr + (len - 512), 512, 0); in spi_test_print_hex_dump()
415 dev_info(&spi->dev, " spi_msg@%pK\n", msg); in spi_test_dump_message()
416 if (msg->status) in spi_test_dump_message()
417 dev_info(&spi->dev, " status: %i\n", in spi_test_dump_message()
418 msg->status); in spi_test_dump_message()
419 dev_info(&spi->dev, " frame_length: %i\n", in spi_test_dump_message()
420 msg->frame_length); in spi_test_dump_message()
421 dev_info(&spi->dev, " actual_length: %i\n", in spi_test_dump_message()
422 msg->actual_length); in spi_test_dump_message()
424 list_for_each_entry(xfer, &msg->transfers, transfer_list) { in spi_test_dump_message()
425 dev_info(&spi->dev, " spi_transfer@%pK\n", xfer); in spi_test_dump_message()
426 dev_info(&spi->dev, " len: %i\n", xfer->len); in spi_test_dump_message()
427 dev_info(&spi->dev, " tx_buf: %pK\n", xfer->tx_buf); in spi_test_dump_message()
428 if (dump_data && xfer->tx_buf) in spi_test_dump_message()
429 spi_test_print_hex_dump(" TX: ", in spi_test_dump_message()
430 xfer->tx_buf, in spi_test_dump_message()
431 xfer->len); in spi_test_dump_message()
433 dev_info(&spi->dev, " rx_buf: %pK\n", xfer->rx_buf); in spi_test_dump_message()
434 if (dump_data && xfer->rx_buf) in spi_test_dump_message()
435 spi_test_print_hex_dump(" RX: ", in spi_test_dump_message()
436 xfer->rx_buf, in spi_test_dump_message()
437 xfer->len); in spi_test_dump_message()
439 if (xfer->rx_buf) { in spi_test_dump_message()
440 for (i = 0 ; i < xfer->len ; i++) { in spi_test_dump_message()
441 b = ((u8 *)xfer->rx_buf)[xfer->len - 1 - i]; in spi_test_dump_message()
446 dev_info(&spi->dev, in spi_test_dump_message()
449 xfer->len - i); in spi_test_dump_message()
465 if (rx_a->start > rx_b->start) in rx_ranges_cmp()
467 if (rx_a->start < rx_b->start) in rx_ranges_cmp()
468 return -1; in rx_ranges_cmp()
474 void *rx) in spi_check_rx_ranges() argument
484 list_for_each_entry(xfer, &msg->transfers, transfer_list) { in spi_check_rx_ranges()
485 /* if there is no rx, then no check is needed */ in spi_check_rx_ranges()
486 if (!xfer->rx_buf) in spi_check_rx_ranges()
489 if (RANGE_CHECK(xfer->rx_buf, xfer->len, in spi_check_rx_ranges()
490 rx, SPI_TEST_MAX_SIZE_PLUS)) { in spi_check_rx_ranges()
491 ranges[i].start = xfer->rx_buf; in spi_check_rx_ranges()
492 ranges[i].end = xfer->rx_buf + xfer->len; in spi_check_rx_ranges()
505 /* and iterate over all the rx addresses */ in spi_check_rx_ranges()
506 for (addr = rx; addr < (u8 *)rx + SPI_TEST_MAX_SIZE_PLUS; addr++) { in spi_check_rx_ranges()
516 if ((addr >= r->start) && (addr < r->end)) in spi_check_rx_ranges()
517 addr = r->end; in spi_check_rx_ranges()
525 dev_err(&spi->dev, in spi_check_rx_ranges()
526 "loopback strangeness - rx changed outside of allowed range at: %pK\n", in spi_check_rx_ranges()
531 ret = -ERANGE; in spi_check_rx_ranges()
544 for (i = 0; i < test->transfer_count; i++) { in spi_test_check_elapsed_time()
545 struct spi_transfer *xfer = test->transfers + i; in spi_test_check_elapsed_time()
547 xfer->len; in spi_test_check_elapsed_time()
549 delay_usecs += xfer->delay_usecs; in spi_test_check_elapsed_time()
550 if (!xfer->speed_hz) in spi_test_check_elapsed_time()
552 estimated_time += div_u64(nbits * NSEC_PER_SEC, xfer->speed_hz); in spi_test_check_elapsed_time()
556 if (test->elapsed_time < estimated_time) { in spi_test_check_elapsed_time()
557 dev_err(&spi->dev, in spi_test_check_elapsed_time()
559 test->elapsed_time, estimated_time); in spi_test_check_elapsed_time()
561 return -EINVAL; in spi_test_check_elapsed_time()
569 void *tx, void *rx) in spi_test_check_loopback_result() argument
578 ret = spi_check_rx_ranges(spi, msg, rx); in spi_test_check_loopback_result()
588 list_for_each_entry(xfer, &msg->transfers, transfer_list) { in spi_test_check_loopback_result()
589 /* if there is no rx, then no check is needed */ in spi_test_check_loopback_result()
590 if (!xfer->len || !xfer->rx_buf) in spi_test_check_loopback_result()
593 if (xfer->tx_buf) { in spi_test_check_loopback_result()
594 for (i = 0; i < xfer->len; i++) { in spi_test_check_loopback_result()
595 txb = ((u8 *)xfer->tx_buf)[i]; in spi_test_check_loopback_result()
596 rxb = ((u8 *)xfer->rx_buf)[i]; in spi_test_check_loopback_result()
602 txb = ((u8 *)xfer->rx_buf)[0]; in spi_test_check_loopback_result()
605 dev_err(&spi->dev, in spi_test_check_loopback_result()
606 "loopback strangeness - we expect 0x00 or 0xff, but not 0x%02x\n", in spi_test_check_loopback_result()
608 return -EINVAL; in spi_test_check_loopback_result()
611 for (i = 1; i < xfer->len; i++) { in spi_test_check_loopback_result()
612 rxb = ((u8 *)xfer->rx_buf)[i]; in spi_test_check_loopback_result()
622 dev_err(&spi->dev, in spi_test_check_loopback_result()
623 "loopback strangeness - transfer mismatch on byte %04zx - expected 0x%02x, but got 0x%02x\n", in spi_test_check_loopback_result()
626 return -EINVAL; in spi_test_check_loopback_result()
631 void *tx, void *rx) in spi_test_translate() argument
642 *ptr += (SPI_TEST_MAX_SIZE_PLUS / 2) - in spi_test_translate()
645 /* RX range in spi_test_translate()
646 * - we check against MAX_SIZE_PLUS to allow for automated alignment in spi_test_translate()
648 if (RANGE_CHECK(*ptr, len, RX(0), SPI_TEST_MAX_SIZE_PLUS)) { in spi_test_translate()
649 off = *ptr - RX(0); in spi_test_translate()
650 *ptr = rx + off; in spi_test_translate()
655 /* TX range */ in spi_test_translate()
656 if (RANGE_CHECK(*ptr, len, TX(0), SPI_TEST_MAX_SIZE_PLUS)) { in spi_test_translate()
657 off = *ptr - TX(0); in spi_test_translate()
658 *ptr = tx + off; in spi_test_translate()
663 dev_err(&spi->dev, in spi_test_translate()
666 RX(0), RX(SPI_TEST_MAX_SIZE), in spi_test_translate()
667 TX(0), TX(SPI_TEST_MAX_SIZE)); in spi_test_translate()
669 return -EINVAL; in spi_test_translate()
675 struct spi_transfer *xfers = test->transfers; in spi_test_fill_pattern()
682 (value >> (8 * (bytes - 1 - count % bytes))) in spi_test_fill_pattern()
689 for (i = 0; i < test->transfer_count; i++) { in spi_test_fill_pattern()
700 /* fill tx */ in spi_test_fill_pattern()
701 switch (test->fill_option) { in spi_test_fill_pattern()
703 *tx_buf = test->fill_pattern; in spi_test_fill_pattern()
706 *tx_buf = GET_VALUE_BYTE(test->fill_pattern, in spi_test_fill_pattern()
710 *tx_buf = GET_VALUE_BYTE(test->fill_pattern, in spi_test_fill_pattern()
714 *tx_buf = GET_VALUE_BYTE(test->fill_pattern, in spi_test_fill_pattern()
745 dev_err(&spi->dev, in spi_test_fill_pattern()
747 test->fill_option); in spi_test_fill_pattern()
748 return -EINVAL; in spi_test_fill_pattern()
758 void *tx, void *rx) in _spi_test_run_iter() argument
760 struct spi_message *msg = &test->msg; in _spi_test_run_iter()
764 /* initialize message - zero-filled via static initialization */ in _spi_test_run_iter()
767 /* fill rx with the DO_NOT_WRITE pattern */ in _spi_test_run_iter()
768 memset(rx, SPI_TEST_PATTERN_DO_NOT_WRITE, SPI_TEST_MAX_SIZE_PLUS); in _spi_test_run_iter()
771 for (i = 0; i < test->transfer_count; i++) { in _spi_test_run_iter()
772 x = &test->transfers[i]; in _spi_test_run_iter()
775 ret = spi_test_translate(spi, (void **)&x->tx_buf, x->len, in _spi_test_run_iter()
776 (void *)tx, rx); in _spi_test_run_iter()
781 ret = spi_test_translate(spi, &x->rx_buf, x->len, in _spi_test_run_iter()
782 (void *)tx, rx); in _spi_test_run_iter()
796 if (test->execute_msg) in _spi_test_run_iter()
797 ret = test->execute_msg(spi, test, tx, rx); in _spi_test_run_iter()
799 ret = spi_test_execute_msg(spi, test, tx, rx); in _spi_test_run_iter()
802 if (ret == test->expected_return) in _spi_test_run_iter()
805 dev_err(&spi->dev, in _spi_test_run_iter()
806 "test failed - test returned %i, but we expect %i\n", in _spi_test_run_iter()
807 ret, test->expected_return); in _spi_test_run_iter()
815 return -EFAULT; in _spi_test_run_iter()
820 void *tx, void *rx, in spi_test_run_iter() argument
835 if (!(test.iterate_transfer_mask & (BIT(test.transfer_count) - 1))) in spi_test_run_iter()
838 /* count number of transfers with tx/rx_buf != NULL */ in spi_test_run_iter()
851 dev_warn_once(&spi->dev, in spi_test_run_iter()
852 "%s: iterate_tx_off configured with tx_buf==NULL - ignoring\n", in spi_test_run_iter()
857 dev_warn_once(&spi->dev, in spi_test_run_iter()
858 "%s: iterate_rx_off configured with rx_buf==NULL - ignoring\n", in spi_test_run_iter()
865 dev_info(&spi->dev, "Running test %s\n", test.description); in spi_test_run_iter()
867 dev_info(&spi->dev, in spi_test_run_iter()
885 return _spi_test_run_iter(spi, &test, tx, rx); in spi_test_run_iter()
889 * spi_test_execute_msg - default implementation to run a test
893 * tx: the tx buffer allocated for the test sequence
894 * rx: the rx buffer allocated for the test sequence
899 void *tx, void *rx) in spi_test_execute_msg() argument
901 struct spi_message *msg = &test->msg; in spi_test_execute_msg()
916 test->elapsed_time = ktime_to_ns(ktime_sub(ktime_get(), start)); in spi_test_execute_msg()
917 if (ret == -ETIMEDOUT) { in spi_test_execute_msg()
918 dev_info(&spi->dev, in spi_test_execute_msg()
919 "spi-message timed out - rerunning...\n"); in spi_test_execute_msg()
926 dev_err(&spi->dev, in spi_test_execute_msg()
933 if (msg->frame_length != msg->actual_length) { in spi_test_execute_msg()
934 dev_err(&spi->dev, in spi_test_execute_msg()
936 ret = -EIO; in spi_test_execute_msg()
940 /* run rx-buffer tests */ in spi_test_execute_msg()
941 ret = spi_test_check_loopback_result(spi, msg, tx, rx); in spi_test_execute_msg()
959 * spi_test_run_test - run an individual spi_test
965 * tx: the tx buffer allocated for the test sequence
966 * rx: the rx buffer allocated for the test sequence
972 void *tx, void *rx) in spi_test_run_test() argument
980 if (test->transfer_count >= SPI_TEST_MAX_TRANSFERS) { in spi_test_run_test()
981 dev_err(&spi->dev, in spi_test_run_test()
983 test->description, test->transfer_count); in spi_test_run_test()
984 return -E2BIG; in spi_test_run_test()
997 var < (test->iterate_##var ? \ in spi_test_run_test()
998 (spi->master->dma_alignment ? \ in spi_test_run_test()
999 spi->master->dma_alignment : \ in spi_test_run_test()
1000 test->iterate_##var) : \ in spi_test_run_test()
1005 (len = test->iterate_len[idx_len]) != -1; idx_len++) { in spi_test_run_test()
1010 tx, rx, in spi_test_run_test()
1025 * spi_test_run_tests - run an array of spi_messages tests
1027 * @tests: NULL-terminated array of @spi_test
1035 char *rx = NULL, *tx = NULL; in spi_test_run_tests() local
1039 /* allocate rx/tx buffers of 128kB size without devm in spi_test_run_tests()
1043 rx = vmalloc(SPI_TEST_MAX_SIZE_PLUS); in spi_test_run_tests()
1045 rx = kzalloc(SPI_TEST_MAX_SIZE_PLUS, GFP_KERNEL); in spi_test_run_tests()
1046 if (!rx) in spi_test_run_tests()
1047 return -ENOMEM; in spi_test_run_tests()
1051 tx = vmalloc(SPI_TEST_MAX_SIZE_PLUS); in spi_test_run_tests()
1053 tx = kzalloc(SPI_TEST_MAX_SIZE_PLUS, GFP_KERNEL); in spi_test_run_tests()
1054 if (!tx) { in spi_test_run_tests()
1055 ret = -ENOMEM; in spi_test_run_tests()
1060 for (test = tests, count = 0; test->description[0]; in spi_test_run_tests()
1063 if ((run_only_test > -1) && (count != run_only_test)) in spi_test_run_tests()
1066 if (test->run_test) in spi_test_run_tests()
1067 ret = test->run_test(spi, test, tx, rx); in spi_test_run_tests()
1069 ret = spi_test_run_test(spi, test, tx, rx); in spi_test_run_tests()
1081 kvfree(tx); in spi_test_run_tests()
1083 kvfree(rx); in spi_test_run_tests()