All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] spi: loopback-test: add new tests and bug fixes
@ 2017-03-17 18:17 Akinobu Mita
       [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 18+ messages in thread
From: Akinobu Mita @ 2017-03-17 18:17 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Akinobu Mita, Martin Sperl, Mark Brown

This patch series fixes a few minor bugs and adds the following new
tests for spi-loopback-test.

- execute various spi_messages including zero-length transfer
- execute spi_messages with delay after transfers

Akinobu Mita (6):
  spi: loopback-test: correct mismatched test description and
    configuration
  spi: loopback-test: don't skip comparing the first byte of rx_buf
  spi: loopback-test: add ability to test zero-length transfer
  spi: loopback-test: test zero-length transfer
  spi: loopback-test: add elapsed time check
  spi: loopback-test: add test spi_message with delay after transfers

 drivers/spi/spi-loopback-test.c | 118 ++++++++++++++++++++++++++--------------
 drivers/spi/spi-test.h          |  21 +++----
 2 files changed, 88 insertions(+), 51 deletions(-)

Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/6] spi: loopback-test: correct mismatched test description and configuration
       [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-03-17 18:17   ` Akinobu Mita
       [not found]     ` <1489774651-30170-2-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2017-03-17 18:17   ` [PATCH 2/6] spi: loopback-test: don't skip comparing the first byte of rx_buf Akinobu Mita
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Akinobu Mita @ 2017-03-17 18:17 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Akinobu Mita, Martin Sperl, Mark Brown

The test "two tx-transfers - alter first" actually alters the second
not the first transfer.  Similarly the test "two tx-transfers - alter
second" actually alters the first not the second transfer.

The mismatches for the two symmetrical tests cancel each other's
mistakes.  But it's better to fix the mismatches to avoid confusion.

Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 50e620f..99422f3 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -132,7 +132,7 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
-		.iterate_transfer_mask = BIT(1),
+		.iterate_transfer_mask = BIT(0),
 		.transfers		= {
 			{
 				.len = 1,
@@ -149,7 +149,7 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
-		.iterate_transfer_mask = BIT(0),
+		.iterate_transfer_mask = BIT(1),
 		.transfers		= {
 			{
 				.len = 16,
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/6] spi: loopback-test: don't skip comparing the first byte of rx_buf
       [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2017-03-17 18:17   ` [PATCH 1/6] spi: loopback-test: correct mismatched test description and configuration Akinobu Mita
@ 2017-03-17 18:17   ` Akinobu Mita
       [not found]     ` <1489774651-30170-3-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2017-03-17 18:17   ` [PATCH 3/6] spi: loopback-test: add ability to test zero-length transfer Akinobu Mita
                     ` (3 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Akinobu Mita @ 2017-03-17 18:17 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Akinobu Mita, Martin Sperl, Mark Brown

When the loopback parameter is set, rx_buf are compared with tx_buf
after the spi_message is executed.  But the first byte of buffer is
not checked.

Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 99422f3..85c0c4e 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -507,7 +507,7 @@ static int spi_test_check_loopback_result(struct spi_device *spi,
 			continue;
 		/* so depending on tx_buf we need to handle things */
 		if (xfer->tx_buf) {
-			for (i = 1; i < xfer->len; i++) {
+			for (i = 0; i < xfer->len; i++) {
 				txb = ((u8 *)xfer->tx_buf)[i];
 				rxb = ((u8 *)xfer->rx_buf)[i];
 				if (txb != rxb)
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/6] spi: loopback-test: add ability to test zero-length transfer
       [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2017-03-17 18:17   ` [PATCH 1/6] spi: loopback-test: correct mismatched test description and configuration Akinobu Mita
  2017-03-17 18:17   ` [PATCH 2/6] spi: loopback-test: don't skip comparing the first byte of rx_buf Akinobu Mita
@ 2017-03-17 18:17   ` Akinobu Mita
       [not found]     ` <1489774651-30170-4-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2017-03-17 18:17   ` [PATCH 4/6] spi: loopback-test: test zero-length transfer Akinobu Mita
                     ` (2 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Akinobu Mita @ 2017-03-17 18:17 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Akinobu Mita, Martin Sperl, Mark Brown

The spi-loopback-test module currently cannot test the spi_message
including a zero-length transfer.  Because the zero-length transfer is
treated as a special value in several meanings.

1. The number of spi_transfer to execute in one test case is described
by spi_test.transfer_count.  It is normally computed by counting number
of transfers with len > 0 in spi_test.transfers array.

This change stops the detection for the number of spi_transfer.  Each
spi_test.transfer_count needs to be filled by hand now.

2. The spi_test.iterate_len is a list of transfer length to iterate on.
This list is terminated by zero, so zero-length transfer cannot be
included.

This changes the terminal value from 0 to -1.

3. The length for the spi_transfer masked by spi_test.iterate_transfer_mask
is iterated.  Before starting the iteration, the default value which
is statically initialized is applied.  In order to specify the default
value, zero-length is reserved.

Currently, the default values are always '1'.  So this removes this
trick and add '1' to iterate_len list.

By applying all these changes, the spi-loopback-test can execute spi
messages with zero-length transfer.

Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 55 +++++++++++++----------------------------
 drivers/spi/spi-test.h          | 19 +++++++-------
 2 files changed, 26 insertions(+), 48 deletions(-)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 85c0c4e..6df6ddd 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -63,9 +63,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_rx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 				.rx_buf = RX(0),
 			},
@@ -77,9 +77,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_rx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(PAGE_SIZE - 4),
 				.rx_buf = RX(PAGE_SIZE - 4),
 			},
@@ -90,9 +90,9 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 		},
@@ -102,9 +102,9 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_rx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.rx_buf = RX(0),
 			},
 		},
@@ -115,13 +115,12 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				/* this is why we cant use ITERATE_MAX_LEN */
 				.tx_buf = TX(SPI_TEST_MAX_SIZE_HALF),
 			},
@@ -133,9 +132,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(64),
 			},
 			{
@@ -150,13 +149,13 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
 				.len = 16,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				.tx_buf = TX(64),
 			},
 		},
@@ -167,13 +166,12 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				.rx_buf = RX(0),
 			},
 		},
@@ -184,9 +182,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
@@ -201,13 +199,13 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
 				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				.rx_buf = RX(0),
 			},
 		},
@@ -218,14 +216,13 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 				.rx_buf = RX(0),
 			},
 			{
-				.len = 1,
 				/* making sure we align without overwrite
 				 * the reason we can not use ITERATE_MAX_LEN
 				 */
@@ -240,9 +237,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				/* making sure we align without overwrite */
 				.tx_buf = TX(1024),
 				.rx_buf = RX(1024),
@@ -261,6 +258,7 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
 				.len = 1,
@@ -268,7 +266,6 @@ static struct spi_test spi_tests[] = {
 				.rx_buf = RX(0),
 			},
 			{
-				.len = 1,
 				/* making sure we align without overwrite */
 				.tx_buf = TX(1024),
 				.rx_buf = RX(1024),
@@ -503,7 +500,7 @@ static int spi_test_check_loopback_result(struct spi_device *spi,
 	/* if applicable to transfer check that rx_buf is equal to tx_buf */
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
 		/* if there is no rx, then no check is needed */
-		if (!xfer->rx_buf)
+		if (!xfer->len || !xfer->rx_buf)
 			continue;
 		/* so depending on tx_buf we need to handle things */
 		if (xfer->tx_buf) {
@@ -745,15 +742,6 @@ static int spi_test_run_iter(struct spi_device *spi,
 	/* copy the test template to test */
 	memcpy(&test, testtemplate, sizeof(test));
 
-	/* set up test->transfers to the correct count */
-	if (!test.transfer_count) {
-		for (i = 0;
-		    (i < SPI_TEST_MAX_TRANSFERS) && test.transfers[i].len;
-		    i++) {
-			test.transfer_count++;
-		}
-	}
-
 	/* if iterate_transfer_mask is not set,
 	 * then set it to first transfer only
 	 */
@@ -799,8 +787,7 @@ static int spi_test_run_iter(struct spi_device *spi,
 		/* only when bit in transfer mask is set */
 		if (!(test.iterate_transfer_mask & BIT(i)))
 			continue;
-		if (len)
-			test.transfers[i].len = len;
+		test.transfers[i].len = len;
 		if (test.transfers[i].tx_buf)
 			test.transfers[i].tx_buf += tx_off;
 		if (test.transfers[i].tx_buf)
@@ -910,15 +897,6 @@ int spi_test_run_test(struct spi_device *spi, const struct spi_test *test,
 	/* iterate over all the iterable values using macros
 	 * (to make it a bit more readable...
 	 */
-#define FOR_EACH_ITERATE(var, defaultvalue)				\
-	for (idx_##var = -1, var = defaultvalue;			\
-	     ((idx_##var < 0) ||					\
-		     (							\
-			     (idx_##var < SPI_TEST_MAX_ITERATE) &&	\
-			     (var = test->iterate_##var[idx_##var])	\
-		     )							\
-	     );								\
-	     idx_##var++)
 #define FOR_EACH_ALIGNMENT(var)						\
 	for (var = 0;							\
 	    var < (test->iterate_##var ?				\
@@ -928,7 +906,8 @@ int spi_test_run_test(struct spi_device *spi, const struct spi_test *test,
 			1);						\
 	    var++)
 
-	FOR_EACH_ITERATE(len, 0) {
+	for (idx_len = 0; idx_len < SPI_TEST_MAX_ITERATE &&
+	     (len = test->iterate_len[idx_len]) != -1; idx_len++) {
 		FOR_EACH_ALIGNMENT(tx_align) {
 			FOR_EACH_ALIGNMENT(rx_align) {
 				/* and run the iteration */
diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h
index 922c528..2dd5691 100644
--- a/drivers/spi/spi-test.h
+++ b/drivers/spi/spi-test.h
@@ -48,9 +48,8 @@
  *
  * @msg:              a template @spi_message usedfor the default settings
  * @transfers:        array of @spi_transfers that are part of the
- *                    resulting spi_message. The first transfer with len == 0
- *                    signifies the end of the list
- * @transfer_count:   normally computed number of transfers with len > 0
+ *                    resulting spi_message.
+ * @transfer_count:   number of transfers
  *
  * @run_test:         run a specific spi_test - this allows to override
  *                    the default implementation of @spi_test_run_transfer
@@ -62,8 +61,7 @@
  * @expected_return:  the expected return code - in some cases we want to
  *                    test also for error conditions
  *
- * @iterate_len:      list of length to iterate on (in addition to the
- *                    explicitly set @spi_transfer.len)
+ * @iterate_len:      list of length to iterate on
  * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf
  *                    for all values in the below range if set.
  *                    the ranges are:
@@ -89,7 +87,7 @@ struct spi_test {
 	int (*execute_msg)(struct spi_device *spi, struct spi_test *test,
 			   void *tx, void *rx);
 	int expected_return;
-	/* iterate over all the non-zero values */
+	/* iterate over all values, terminated by a -1 */
 	int iterate_len[SPI_TEST_MAX_ITERATE];
 	int iterate_tx_align;
 	int iterate_rx_align;
@@ -126,11 +124,12 @@ int spi_test_execute_msg(struct spi_device *spi,
 int spi_test_run_tests(struct spi_device *spi,
 		       struct spi_test *tests);
 
-/* some of the default @spi_transfer.len to test */
-#define ITERATE_LEN 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
+#define ITERATE_LEN_LIST 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
 		1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
-
-#define ITERATE_MAX_LEN ITERATE_LEN, SPI_TEST_MAX_SIZE - 1, SPI_TEST_MAX_SIZE
+/* some of the default @spi_transfer.len to test, terminated by a -1 */
+#define ITERATE_LEN ITERATE_LEN_LIST, -1
+#define ITERATE_MAX_LEN ITERATE_LEN_LIST, (SPI_TEST_MAX_SIZE - 1), \
+		SPI_TEST_MAX_SIZE, -1
 
 /* the default alignment to test */
 #define ITERATE_ALIGN sizeof(int)
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/6] spi: loopback-test: test zero-length transfer
       [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
                     ` (2 preceding siblings ...)
  2017-03-17 18:17   ` [PATCH 3/6] spi: loopback-test: add ability to test zero-length transfer Akinobu Mita
@ 2017-03-17 18:17   ` Akinobu Mita
       [not found]     ` <1489774651-30170-5-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2017-03-17 18:17   ` [PATCH 5/6] spi: loopback-test: add elapsed time check Akinobu Mita
  2017-03-17 18:17   ` [PATCH 6/6] spi: loopback-test: add test spi_message with delay after transfers Akinobu Mita
  5 siblings, 1 reply; 18+ messages in thread
From: Akinobu Mita @ 2017-03-17 18:17 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Akinobu Mita, Martin Sperl, Mark Brown

In order to test various spi_messages including zero-length transfer,
this adds zero length into the iterate_len list.

Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/spi/spi-test.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h
index 2dd5691..82fff4a 100644
--- a/drivers/spi/spi-test.h
+++ b/drivers/spi/spi-test.h
@@ -124,7 +124,7 @@ int spi_test_execute_msg(struct spi_device *spi,
 int spi_test_run_tests(struct spi_device *spi,
 		       struct spi_test *tests);
 
-#define ITERATE_LEN_LIST 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
+#define ITERATE_LEN_LIST 0, 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
 		1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
 /* some of the default @spi_transfer.len to test, terminated by a -1 */
 #define ITERATE_LEN ITERATE_LEN_LIST, -1
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 5/6] spi: loopback-test: add elapsed time check
       [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
                     ` (3 preceding siblings ...)
  2017-03-17 18:17   ` [PATCH 4/6] spi: loopback-test: test zero-length transfer Akinobu Mita
@ 2017-03-17 18:17   ` Akinobu Mita
       [not found]     ` <1489774651-30170-6-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2024-01-12 16:19     ` [PATCH 5/6] spi: loopback-test: add elapsed time check Tudor Ambarus
  2017-03-17 18:17   ` [PATCH 6/6] spi: loopback-test: add test spi_message with delay after transfers Akinobu Mita
  5 siblings, 2 replies; 18+ messages in thread
From: Akinobu Mita @ 2017-03-17 18:17 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Akinobu Mita, Martin Sperl, Mark Brown

This adds checks whether the elapsed time is longer than the minimam
estimated time.  The estimated time is calculated with the total
transfer length per clock rate and optional spi_transfer.delay_usecs.

Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/spi/spi-test.h          |  2 ++
 2 files changed, 40 insertions(+)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 6df6ddd..66e8cfd0 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -20,6 +20,7 @@
 
 #include <linux/delay.h>
 #include <linux/kernel.h>
+#include <linux/ktime.h>
 #include <linux/list.h>
 #include <linux/list_sort.h>
 #include <linux/module.h>
@@ -479,6 +480,35 @@ static int spi_check_rx_ranges(struct spi_device *spi,
 	return ret;
 }
 
+static int spi_test_check_elapsed_time(struct spi_device *spi,
+				       struct spi_test *test)
+{
+	int i;
+	unsigned long long estimated_time = 0;
+	unsigned long long delay_usecs = 0;
+
+	for (i = 0; i < test->transfer_count; i++) {
+		struct spi_transfer *xfer = test->transfers + i;
+		unsigned long long nbits = BITS_PER_BYTE * xfer->len;
+
+		delay_usecs += xfer->delay_usecs;
+		if (!xfer->speed_hz)
+			continue;
+		estimated_time += div_u64(nbits * NSEC_PER_SEC, xfer->speed_hz);
+	}
+
+	estimated_time += delay_usecs * NSEC_PER_USEC;
+	if (test->elapsed_time < estimated_time) {
+		dev_err(&spi->dev,
+			"elapsed time %lld ns is shorter than minimam estimated time %lld ns\n",
+			test->elapsed_time, estimated_time);
+
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int spi_test_check_loopback_result(struct spi_device *spi,
 					  struct spi_message *msg,
 					  void *tx, void *rx)
@@ -817,12 +847,16 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test,
 
 	/* only if we do not simulate */
 	if (!simulate_only) {
+		ktime_t start;
+
 		/* dump the complete message before and after the transfer */
 		if (dump_messages == 3)
 			spi_test_dump_message(spi, msg, true);
 
+		start = ktime_get();
 		/* run spi message */
 		ret = spi_sync(spi, msg);
+		test->elapsed_time = ktime_to_ns(ktime_sub(ktime_get(), start));
 		if (ret == -ETIMEDOUT) {
 			dev_info(&spi->dev,
 				 "spi-message timed out - reruning...\n");
@@ -848,6 +882,10 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test,
 
 		/* run rx-buffer tests */
 		ret = spi_test_check_loopback_result(spi, msg, tx, rx);
+		if (ret)
+			goto exit;
+
+		ret = spi_test_check_elapsed_time(spi, test);
 	}
 
 	/* if requested or on error dump message (including data) */
diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h
index 82fff4a..6ed7b89 100644
--- a/drivers/spi/spi-test.h
+++ b/drivers/spi/spi-test.h
@@ -75,6 +75,7 @@
  * @fill_option:      define the way how tx_buf is filled
  * @fill_pattern:     fill pattern to apply to the tx_buf
  *                    (used in some of the @fill_options)
+ * @elapsed_time:     elapsed time in nanoseconds
  */
 
 struct spi_test {
@@ -108,6 +109,7 @@ struct spi_test {
 #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */
 #define FILL_TRANSFER_NUM     16 /* fill with the transfer number */
 	u32 fill_pattern;
+	unsigned long long elapsed_time;
 };
 
 /* default implementation for @spi_test.run_test */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 6/6] spi: loopback-test: add test spi_message with delay after transfers
       [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
                     ` (4 preceding siblings ...)
  2017-03-17 18:17   ` [PATCH 5/6] spi: loopback-test: add elapsed time check Akinobu Mita
@ 2017-03-17 18:17   ` Akinobu Mita
       [not found]     ` <1489774651-30170-7-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  5 siblings, 1 reply; 18+ messages in thread
From: Akinobu Mita @ 2017-03-17 18:17 UTC (permalink / raw)
  To: linux-spi-u79uwXL29TY76Z2rM5mHXA; +Cc: Akinobu Mita, Martin Sperl, Mark Brown

This adds a new test to check whether the spi_transfer.delay_usecs
setting has properly taken effect.

Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 66e8cfd0..fcae337 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -273,6 +273,25 @@ static struct spi_test spi_tests[] = {
 			},
 		},
 	},
+	{
+		.description	= "two tx+rx transfers - delay after transfer",
+		.fill_option	= FILL_COUNT_8,
+		.iterate_len    = { ITERATE_MAX_LEN },
+		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
+		.transfers		= {
+			{
+				.tx_buf = TX(0),
+				.rx_buf = RX(0),
+				.delay_usecs = 1000,
+			},
+			{
+				.tx_buf = TX(0),
+				.rx_buf = RX(0),
+				.delay_usecs = 1000,
+			},
+		},
+	},
 
 	{ /* end of tests sequence */ }
 };
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Applied "spi: loopback-test: add test spi_message with delay after transfers" to the spi tree
       [not found]     ` <1489774651-30170-7-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-03-17 21:54       ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2017-03-17 21:54 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, Martin Sperl,
	Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA

The patch

   spi: loopback-test: add test spi_message with delay after transfers

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 8687113e1515f4c9104a6eaedc384ec762c6550f Mon Sep 17 00:00:00 2001
From: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Sat, 18 Mar 2017 03:17:31 +0900
Subject: [PATCH] spi: loopback-test: add test spi_message with delay after
 transfers

This adds a new test to check whether the spi_transfer.delay_usecs
setting has properly taken effect.

Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 66e8cfd04395..fcae3377ec26 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -273,6 +273,25 @@ static struct spi_test spi_tests[] = {
 			},
 		},
 	},
+	{
+		.description	= "two tx+rx transfers - delay after transfer",
+		.fill_option	= FILL_COUNT_8,
+		.iterate_len    = { ITERATE_MAX_LEN },
+		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
+		.transfers		= {
+			{
+				.tx_buf = TX(0),
+				.rx_buf = RX(0),
+				.delay_usecs = 1000,
+			},
+			{
+				.tx_buf = TX(0),
+				.rx_buf = RX(0),
+				.delay_usecs = 1000,
+			},
+		},
+	},
 
 	{ /* end of tests sequence */ }
 };
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Applied "spi: loopback-test: add elapsed time check" to the spi tree
       [not found]     ` <1489774651-30170-6-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-03-17 21:54       ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2017-03-17 21:54 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, Martin Sperl,
	Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA

The patch

   spi: loopback-test: add elapsed time check

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From ea9936f32435699907807aaac87f993482208578 Mon Sep 17 00:00:00 2001
From: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Sat, 18 Mar 2017 03:17:30 +0900
Subject: [PATCH] spi: loopback-test: add elapsed time check

This adds checks whether the elapsed time is longer than the minimam
estimated time.  The estimated time is calculated with the total
transfer length per clock rate and optional spi_transfer.delay_usecs.

Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/spi/spi-test.h          |  2 ++
 2 files changed, 40 insertions(+)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 6df6dddc2890..66e8cfd04395 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -20,6 +20,7 @@
 
 #include <linux/delay.h>
 #include <linux/kernel.h>
+#include <linux/ktime.h>
 #include <linux/list.h>
 #include <linux/list_sort.h>
 #include <linux/module.h>
@@ -479,6 +480,35 @@ static int spi_check_rx_ranges(struct spi_device *spi,
 	return ret;
 }
 
+static int spi_test_check_elapsed_time(struct spi_device *spi,
+				       struct spi_test *test)
+{
+	int i;
+	unsigned long long estimated_time = 0;
+	unsigned long long delay_usecs = 0;
+
+	for (i = 0; i < test->transfer_count; i++) {
+		struct spi_transfer *xfer = test->transfers + i;
+		unsigned long long nbits = BITS_PER_BYTE * xfer->len;
+
+		delay_usecs += xfer->delay_usecs;
+		if (!xfer->speed_hz)
+			continue;
+		estimated_time += div_u64(nbits * NSEC_PER_SEC, xfer->speed_hz);
+	}
+
+	estimated_time += delay_usecs * NSEC_PER_USEC;
+	if (test->elapsed_time < estimated_time) {
+		dev_err(&spi->dev,
+			"elapsed time %lld ns is shorter than minimam estimated time %lld ns\n",
+			test->elapsed_time, estimated_time);
+
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int spi_test_check_loopback_result(struct spi_device *spi,
 					  struct spi_message *msg,
 					  void *tx, void *rx)
@@ -817,12 +847,16 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test,
 
 	/* only if we do not simulate */
 	if (!simulate_only) {
+		ktime_t start;
+
 		/* dump the complete message before and after the transfer */
 		if (dump_messages == 3)
 			spi_test_dump_message(spi, msg, true);
 
+		start = ktime_get();
 		/* run spi message */
 		ret = spi_sync(spi, msg);
+		test->elapsed_time = ktime_to_ns(ktime_sub(ktime_get(), start));
 		if (ret == -ETIMEDOUT) {
 			dev_info(&spi->dev,
 				 "spi-message timed out - reruning...\n");
@@ -848,6 +882,10 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test,
 
 		/* run rx-buffer tests */
 		ret = spi_test_check_loopback_result(spi, msg, tx, rx);
+		if (ret)
+			goto exit;
+
+		ret = spi_test_check_elapsed_time(spi, test);
 	}
 
 	/* if requested or on error dump message (including data) */
diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h
index 82fff4a0fd94..6ed7b899da8a 100644
--- a/drivers/spi/spi-test.h
+++ b/drivers/spi/spi-test.h
@@ -75,6 +75,7 @@
  * @fill_option:      define the way how tx_buf is filled
  * @fill_pattern:     fill pattern to apply to the tx_buf
  *                    (used in some of the @fill_options)
+ * @elapsed_time:     elapsed time in nanoseconds
  */
 
 struct spi_test {
@@ -108,6 +109,7 @@ struct spi_test {
 #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */
 #define FILL_TRANSFER_NUM     16 /* fill with the transfer number */
 	u32 fill_pattern;
+	unsigned long long elapsed_time;
 };
 
 /* default implementation for @spi_test.run_test */
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Applied "spi: loopback-test: test zero-length transfer" to the spi tree
       [not found]     ` <1489774651-30170-5-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-03-17 21:54       ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2017-03-17 21:54 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, Martin Sperl,
	Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA

The patch

   spi: loopback-test: test zero-length transfer

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 0bd7fda56b94002d9985040c02bb701956fa657e Mon Sep 17 00:00:00 2001
From: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Sat, 18 Mar 2017 03:17:29 +0900
Subject: [PATCH] spi: loopback-test: test zero-length transfer

In order to test various spi_messages including zero-length transfer,
this adds zero length into the iterate_len list.

Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi-test.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h
index 2dd569138880..82fff4a0fd94 100644
--- a/drivers/spi/spi-test.h
+++ b/drivers/spi/spi-test.h
@@ -124,7 +124,7 @@ int spi_test_execute_msg(struct spi_device *spi,
 int spi_test_run_tests(struct spi_device *spi,
 		       struct spi_test *tests);
 
-#define ITERATE_LEN_LIST 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
+#define ITERATE_LEN_LIST 0, 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
 		1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
 /* some of the default @spi_transfer.len to test, terminated by a -1 */
 #define ITERATE_LEN ITERATE_LEN_LIST, -1
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Applied "spi: loopback-test: add ability to test zero-length transfer" to the spi tree
       [not found]     ` <1489774651-30170-4-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-03-17 21:54       ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2017-03-17 21:54 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, Martin Sperl,
	Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA

The patch

   spi: loopback-test: add ability to test zero-length transfer

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 8916671e93a38c509e2ffb02c2ce3f37efe8af40 Mon Sep 17 00:00:00 2001
From: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Sat, 18 Mar 2017 03:17:28 +0900
Subject: [PATCH] spi: loopback-test: add ability to test zero-length transfer

The spi-loopback-test module currently cannot test the spi_message
including a zero-length transfer.  Because the zero-length transfer is
treated as a special value in several meanings.

1. The number of spi_transfer to execute in one test case is described
by spi_test.transfer_count.  It is normally computed by counting number
of transfers with len > 0 in spi_test.transfers array.

This change stops the detection for the number of spi_transfer.  Each
spi_test.transfer_count needs to be filled by hand now.

2. The spi_test.iterate_len is a list of transfer length to iterate on.
This list is terminated by zero, so zero-length transfer cannot be
included.

This changes the terminal value from 0 to -1.

3. The length for the spi_transfer masked by spi_test.iterate_transfer_mask
is iterated.  Before starting the iteration, the default value which
is statically initialized is applied.  In order to specify the default
value, zero-length is reserved.

Currently, the default values are always '1'.  So this removes this
trick and add '1' to iterate_len list.

By applying all these changes, the spi-loopback-test can execute spi
messages with zero-length transfer.

Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 55 +++++++++++++----------------------------
 drivers/spi/spi-test.h          | 19 +++++++-------
 2 files changed, 26 insertions(+), 48 deletions(-)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 85c0c4e391d9..6df6dddc2890 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -63,9 +63,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_rx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 				.rx_buf = RX(0),
 			},
@@ -77,9 +77,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_rx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(PAGE_SIZE - 4),
 				.rx_buf = RX(PAGE_SIZE - 4),
 			},
@@ -90,9 +90,9 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 		},
@@ -102,9 +102,9 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_rx_align = ITERATE_ALIGN,
+		.transfer_count = 1,
 		.transfers		= {
 			{
-				.len = 1,
 				.rx_buf = RX(0),
 			},
 		},
@@ -115,13 +115,12 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				/* this is why we cant use ITERATE_MAX_LEN */
 				.tx_buf = TX(SPI_TEST_MAX_SIZE_HALF),
 			},
@@ -133,9 +132,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(64),
 			},
 			{
@@ -150,13 +149,13 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
 				.len = 16,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				.tx_buf = TX(64),
 			},
 		},
@@ -167,13 +166,12 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				.rx_buf = RX(0),
 			},
 		},
@@ -184,9 +182,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
@@ -201,13 +199,13 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
 				.len = 1,
 				.tx_buf = TX(0),
 			},
 			{
-				.len = 1,
 				.rx_buf = RX(0),
 			},
 		},
@@ -218,14 +216,13 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0) | BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				.tx_buf = TX(0),
 				.rx_buf = RX(0),
 			},
 			{
-				.len = 1,
 				/* making sure we align without overwrite
 				 * the reason we can not use ITERATE_MAX_LEN
 				 */
@@ -240,9 +237,9 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(0),
+		.transfer_count = 2,
 		.transfers		= {
 			{
-				.len = 1,
 				/* making sure we align without overwrite */
 				.tx_buf = TX(1024),
 				.rx_buf = RX(1024),
@@ -261,6 +258,7 @@ static struct spi_test spi_tests[] = {
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
 		.iterate_transfer_mask = BIT(1),
+		.transfer_count = 2,
 		.transfers		= {
 			{
 				.len = 1,
@@ -268,7 +266,6 @@ static struct spi_test spi_tests[] = {
 				.rx_buf = RX(0),
 			},
 			{
-				.len = 1,
 				/* making sure we align without overwrite */
 				.tx_buf = TX(1024),
 				.rx_buf = RX(1024),
@@ -503,7 +500,7 @@ static int spi_test_check_loopback_result(struct spi_device *spi,
 	/* if applicable to transfer check that rx_buf is equal to tx_buf */
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
 		/* if there is no rx, then no check is needed */
-		if (!xfer->rx_buf)
+		if (!xfer->len || !xfer->rx_buf)
 			continue;
 		/* so depending on tx_buf we need to handle things */
 		if (xfer->tx_buf) {
@@ -745,15 +742,6 @@ static int spi_test_run_iter(struct spi_device *spi,
 	/* copy the test template to test */
 	memcpy(&test, testtemplate, sizeof(test));
 
-	/* set up test->transfers to the correct count */
-	if (!test.transfer_count) {
-		for (i = 0;
-		    (i < SPI_TEST_MAX_TRANSFERS) && test.transfers[i].len;
-		    i++) {
-			test.transfer_count++;
-		}
-	}
-
 	/* if iterate_transfer_mask is not set,
 	 * then set it to first transfer only
 	 */
@@ -799,8 +787,7 @@ static int spi_test_run_iter(struct spi_device *spi,
 		/* only when bit in transfer mask is set */
 		if (!(test.iterate_transfer_mask & BIT(i)))
 			continue;
-		if (len)
-			test.transfers[i].len = len;
+		test.transfers[i].len = len;
 		if (test.transfers[i].tx_buf)
 			test.transfers[i].tx_buf += tx_off;
 		if (test.transfers[i].tx_buf)
@@ -910,15 +897,6 @@ int spi_test_run_test(struct spi_device *spi, const struct spi_test *test,
 	/* iterate over all the iterable values using macros
 	 * (to make it a bit more readable...
 	 */
-#define FOR_EACH_ITERATE(var, defaultvalue)				\
-	for (idx_##var = -1, var = defaultvalue;			\
-	     ((idx_##var < 0) ||					\
-		     (							\
-			     (idx_##var < SPI_TEST_MAX_ITERATE) &&	\
-			     (var = test->iterate_##var[idx_##var])	\
-		     )							\
-	     );								\
-	     idx_##var++)
 #define FOR_EACH_ALIGNMENT(var)						\
 	for (var = 0;							\
 	    var < (test->iterate_##var ?				\
@@ -928,7 +906,8 @@ int spi_test_run_test(struct spi_device *spi, const struct spi_test *test,
 			1);						\
 	    var++)
 
-	FOR_EACH_ITERATE(len, 0) {
+	for (idx_len = 0; idx_len < SPI_TEST_MAX_ITERATE &&
+	     (len = test->iterate_len[idx_len]) != -1; idx_len++) {
 		FOR_EACH_ALIGNMENT(tx_align) {
 			FOR_EACH_ALIGNMENT(rx_align) {
 				/* and run the iteration */
diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h
index 922c52833239..2dd569138880 100644
--- a/drivers/spi/spi-test.h
+++ b/drivers/spi/spi-test.h
@@ -48,9 +48,8 @@
  *
  * @msg:              a template @spi_message usedfor the default settings
  * @transfers:        array of @spi_transfers that are part of the
- *                    resulting spi_message. The first transfer with len == 0
- *                    signifies the end of the list
- * @transfer_count:   normally computed number of transfers with len > 0
+ *                    resulting spi_message.
+ * @transfer_count:   number of transfers
  *
  * @run_test:         run a specific spi_test - this allows to override
  *                    the default implementation of @spi_test_run_transfer
@@ -62,8 +61,7 @@
  * @expected_return:  the expected return code - in some cases we want to
  *                    test also for error conditions
  *
- * @iterate_len:      list of length to iterate on (in addition to the
- *                    explicitly set @spi_transfer.len)
+ * @iterate_len:      list of length to iterate on
  * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf
  *                    for all values in the below range if set.
  *                    the ranges are:
@@ -89,7 +87,7 @@ struct spi_test {
 	int (*execute_msg)(struct spi_device *spi, struct spi_test *test,
 			   void *tx, void *rx);
 	int expected_return;
-	/* iterate over all the non-zero values */
+	/* iterate over all values, terminated by a -1 */
 	int iterate_len[SPI_TEST_MAX_ITERATE];
 	int iterate_tx_align;
 	int iterate_rx_align;
@@ -126,11 +124,12 @@ int spi_test_execute_msg(struct spi_device *spi,
 int spi_test_run_tests(struct spi_device *spi,
 		       struct spi_test *tests);
 
-/* some of the default @spi_transfer.len to test */
-#define ITERATE_LEN 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
+#define ITERATE_LEN_LIST 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
 		1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
-
-#define ITERATE_MAX_LEN ITERATE_LEN, SPI_TEST_MAX_SIZE - 1, SPI_TEST_MAX_SIZE
+/* some of the default @spi_transfer.len to test, terminated by a -1 */
+#define ITERATE_LEN ITERATE_LEN_LIST, -1
+#define ITERATE_MAX_LEN ITERATE_LEN_LIST, (SPI_TEST_MAX_SIZE - 1), \
+		SPI_TEST_MAX_SIZE, -1
 
 /* the default alignment to test */
 #define ITERATE_ALIGN sizeof(int)
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Applied "spi: loopback-test: don't skip comparing the first byte of rx_buf" to the spi tree
       [not found]     ` <1489774651-30170-3-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-03-17 21:54       ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2017-03-17 21:54 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, Martin Sperl,
	Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA

The patch

   spi: loopback-test: don't skip comparing the first byte of rx_buf

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 8494801db1fc21867f587dae465236100bf228cc Mon Sep 17 00:00:00 2001
From: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Sat, 18 Mar 2017 03:17:27 +0900
Subject: [PATCH] spi: loopback-test: don't skip comparing the first byte of
 rx_buf

When the loopback parameter is set, rx_buf are compared with tx_buf
after the spi_message is executed.  But the first byte of buffer is
not checked.

Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 99422f3a15e0..85c0c4e391d9 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -507,7 +507,7 @@ static int spi_test_check_loopback_result(struct spi_device *spi,
 			continue;
 		/* so depending on tx_buf we need to handle things */
 		if (xfer->tx_buf) {
-			for (i = 1; i < xfer->len; i++) {
+			for (i = 0; i < xfer->len; i++) {
 				txb = ((u8 *)xfer->tx_buf)[i];
 				rxb = ((u8 *)xfer->rx_buf)[i];
 				if (txb != rxb)
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Applied "spi: loopback-test: correct mismatched test description and configuration" to the spi tree
       [not found]     ` <1489774651-30170-2-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-03-17 21:55       ` Mark Brown
  0 siblings, 0 replies; 18+ messages in thread
From: Mark Brown @ 2017-03-17 21:55 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA, Martin Sperl,
	Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA

The patch

   spi: loopback-test: correct mismatched test description and configuration

has been applied to the spi tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From c4e121aeb754f1ac5f2bcc791aa4177dcfb3b401 Mon Sep 17 00:00:00 2001
From: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Sat, 18 Mar 2017 03:17:26 +0900
Subject: [PATCH] spi: loopback-test: correct mismatched test description and
 configuration

The test "two tx-transfers - alter first" actually alters the second
not the first transfer.  Similarly the test "two tx-transfers - alter
second" actually alters the first not the second transfer.

The mismatches for the two symmetrical tests cancel each other's
mistakes.  But it's better to fix the mismatches to avoid confusion.

Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi-loopback-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
index 50e620f4e8fe..99422f3a15e0 100644
--- a/drivers/spi/spi-loopback-test.c
+++ b/drivers/spi/spi-loopback-test.c
@@ -132,7 +132,7 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
-		.iterate_transfer_mask = BIT(1),
+		.iterate_transfer_mask = BIT(0),
 		.transfers		= {
 			{
 				.len = 1,
@@ -149,7 +149,7 @@ static struct spi_test spi_tests[] = {
 		.fill_option	= FILL_COUNT_8,
 		.iterate_len    = { ITERATE_MAX_LEN },
 		.iterate_tx_align = ITERATE_ALIGN,
-		.iterate_transfer_mask = BIT(0),
+		.iterate_transfer_mask = BIT(1),
 		.transfers		= {
 			{
 				.len = 16,
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/6] spi: loopback-test: add elapsed time check
  2017-03-17 18:17   ` [PATCH 5/6] spi: loopback-test: add elapsed time check Akinobu Mita
       [not found]     ` <1489774651-30170-6-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2024-01-12 16:19     ` Tudor Ambarus
  2024-01-12 18:37       ` Mark Brown
  1 sibling, 1 reply; 18+ messages in thread
From: Tudor Ambarus @ 2024-01-12 16:19 UTC (permalink / raw)
  To: akinobu.mita, linux-spi, Mark Brown; +Cc: kernel

Hi!

Trying my luck here.

I'm playing with the spi-s3c64xx.c driver and the spi-loopback-test and
sometimes I see that I get the following error:

```elapsed time x ns is shorter than minimum estimated time y ns```

What's strange to me is that if I ignore the return value of
spi_test_check_elapsed_time(), the test passes, there's no transfer
mismatch and what we expect we actually get at RX.

What kind of errors does the spi_test_check_elapsed_time() check want to
discover? Under what conditions the test->elapsed_time is inaccurate?

Thanks! Find below an example of a test that I run:

/ # modprobe spi-loopback-test simulate_only=0 loopback=1 loop_req=1
check_ranges=1 dump_messages=3 delay_ms=300 run_only_test=14
[ 6748.888603] spi-loopback-test spi13.0: feedback delay set to default (0)
[ 6748.888773] spi-loopback-test spi13.0: Executing spi-loopback-tests
[ 6748.888962] spi-loopback-test spi13.0:   with iteration values: len =
512, tx_off = 0, rx_off = 0
[ 6748.889164] spi-loopback-test spi13.0:   spi_msg@00000000cf23e9a1
[ 6748.889295] spi-loopback-test spi13.0:     frame_length:  0
[ 6748.889417] spi-loopback-test spi13.0:     actual_length: 0
[ 6748.889538] spi-loopback-test spi13.0:     spi_transfer@0000000010068ced
[ 6748.889680] spi-loopback-test spi13.0:       len:    1
[ 6748.889793] spi-loopback-test spi13.0:       tx_buf: 000000009aba786a
[ 6748.889959]           TX: 00000000: 00
[ 6748.890097] spi-loopback-test spi13.0:       rx_buf: 000000000819d83b
[ 6748.890343]           RX: 00000000: aa
[ 6748.890501] spi-loopback-test spi13.0:       rx_buf filled with aa
starts at offset: 0
[ 6748.890788] spi-loopback-test spi13.0:     spi_transfer@00000000cd58625b
[ 6748.891045] spi-loopback-test spi13.0:       len:    512
[ 6748.891247] spi-loopback-test spi13.0:       tx_buf: 0000000062a28e45
[ 6748.891494]           TX: 00000000: 01 02 03 04 05 06 07 08 09 0a 0b
0c 0d 0e 0f 10
[ 6748.891786]           TX: 00000010: 11 12 13 14 15 16 17 18 19 1a 1b
1c 1d 1e 1f 20
[ 6748.892079]           TX: 00000020: 21 22 23 24 25 26 27 28 29 2a 2b
2c 2d 2e 2f 30
[ 6748.892371]           TX: 00000030: 31 32 33 34 35 36 37 38 39 3a 3b
3c 3d 3e 3f 40
[ 6748.892664]           TX: 00000040: 41 42 43 44 45 46 47 48 49 4a 4b
4c 4d 4e 4f 50
[ 6748.892957]           TX: 00000050: 51 52 53 54 55 56 57 58 59 5a 5b
5c 5d 5e 5f 60
[ 6748.893249]           TX: 00000060: 61 62 63 64 65 66 67 68 69 6a 6b
6c 6d 6e 6f 70
[ 6748.893542]           TX: 00000070: 71 72 73 74 75 76 77 78 79 7a 7b
7c 7d 7e 7f 80
[ 6748.893835]           TX: 00000080: 81 82 83 84 85 86 87 88 89 8a 8b
8c 8d 8e 8f 90
[ 6748.894128]           TX: 00000090: 91 92 93 94 95 96 97 98 99 9a 9b
9c 9d 9e 9f a0
[ 6748.894420]           TX: 000000a0: a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab
ac ad ae af b0
[ 6748.894719]           TX: 000000b0: b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb
bc bd be bf c0
[ 6748.895006]           TX: 000000c0: c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb
cc cd ce cf d0
[ 6748.895298]           TX: 000000d0: d1 d2 d3 d4 d5 d6 d7 d8 d9 da db
dc dd de df e0
[ 6748.895591]           TX: 000000e0: e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb
ec ed ee ef f0
[ 6748.895883]           TX: 000000f0: f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb
fc fd fe ff 00
[ 6748.896176]           TX: 00000100: 01 02 03 04 05 06 07 08 09 0a 0b
0c 0d 0e 0f 10
[ 6748.896469]           TX: 00000110: 11 12 13 14 15 16 17 18 19 1a 1b
1c 1d 1e 1f 20
[ 6748.896762]           TX: 00000120: 21 22 23 24 25 26 27 28 29 2a 2b
2c 2d 2e 2f 30
[ 6748.897059]           TX: 00000130: 31 32 33 34 35 36 37 38 39 3a 3b
3c 3d 3e 3f 40
[ 6748.897347]           TX: 00000140: 41 42 43 44 45 46 47 48 49 4a 4b
4c 4d 4e 4f 50
[ 6748.897639]           TX: 00000150: 51 52 53 54 55 56 57 58 59 5a 5b
5c 5d 5e 5f 60
[ 6748.897932]           TX: 00000160: 61 62 63 64 65 66 67 68 69 6a 6b
6c 6d 6e 6f 70
[ 6748.898225]           TX: 00000170: 71 72 73 74 75 76 77 78 79 7a 7b
7c 7d 7e 7f 80
[ 6748.898525]           TX: 00000180: 81 82 83 84 85 86 87 88 89 8a 8b
8c 8d 8e 8f 90
[ 6748.898811]           TX: 00000190: 91 92 93 94 95 96 97 98 99 9a 9b
9c 9d 9e 9f a0
[ 6748.899103]           TX: 000001a0: a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab
ac ad ae af b0
[ 6748.899396]           TX: 000001b0: b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb
bc bd be bf c0
[ 6748.899688]           TX: 000001c0: c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb
cc cd ce cf d0
[ 6748.899981]           TX: 000001d0: d1 d2 d3 d4 d5 d6 d7 d8 d9 da db
dc dd de df e0
[ 6748.900274]           TX: 000001e0: e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb
ec ed ee ef f0
[ 6748.900567]           TX: 000001f0: f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb
fc fd fe ff 00
[ 6748.900860] spi-loopback-test spi13.0:       rx_buf: 00000000df223723
[ 6748.901105]           RX: 00000000: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.901398]           RX: 00000010: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.901696]           RX: 00000020: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.901983]           RX: 00000030: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.902276]           RX: 00000040: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.902575]           RX: 00000050: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.902861]           RX: 00000060: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.903154]           RX: 00000070: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.903447]           RX: 00000080: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.903739]           RX: 00000090: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.904036]           RX: 000000a0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.904325]           RX: 000000b0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.904618]           RX: 000000c0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.904910]           RX: 000000d0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.905203]           RX: 000000e0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.905496]           RX: 000000f0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.905788]           RX: 00000100: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.906081]           RX: 00000110: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.906373]           RX: 00000120: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.906675]           RX: 00000130: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.906985]           RX: 00000140: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.907251]           RX: 00000150: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.907544]           RX: 00000160: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.907836]           RX: 00000170: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.908129]           RX: 00000180: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.908422]           RX: 00000190: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.908714]           RX: 000001a0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.909007]           RX: 000001b0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.909300]           RX: 000001c0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.909592]           RX: 000001d0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.909885]           RX: 000001e0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.910177]           RX: 000001f0: aa aa aa aa aa aa aa aa aa aa aa
aa aa aa aa aa
[ 6748.910482] spi-loopback-test spi13.0:       rx_buf filled with aa
starts at offset: 0
[ 6748.910773] spi-loopback-test spi13.0:     spi_transfer@00000000774992f1
[ 6748.911035] spi-loopback-test spi13.0:       len:    1
[ 6748.911225] spi-loopback-test spi13.0:       tx_buf: 00000000401e03ed
[ 6748.911472]           TX: 00000000: 01
[ 6748.911614] spi-loopback-test spi13.0:       rx_buf: 0000000010f7e3e4
[ 6748.911860]           RX: 00000000: aa
[ 6748.912004] spi-loopback-test spi13.0:       rx_buf filled with aa
starts at offset: 0

[ 6748.913400] spi-loopback-test spi13.0: elapsed time 532837 ns is
shorter than minimum estimated time 82240000 ns

[ 6748.913611] spi-loopback-test spi13.0:   spi_msg@00000000cf23e9a1
[ 6748.913741] spi-loopback-test spi13.0:     frame_length:  514
[ 6748.913863] spi-loopback-test spi13.0:     actual_length: 514
[ 6748.913985] spi-loopback-test spi13.0:     spi_transfer@0000000010068ced
[ 6748.914222] spi-loopback-test spi13.0:       len:    1
[ 6748.914418] spi-loopback-test spi13.0:       tx_buf: 000000009aba786a
[ 6748.914673]           TX: 00000000: 00
[ 6748.914808] spi-loopback-test spi13.0:       rx_buf: 000000000819d83b
[ 6748.915053]           RX: 00000000: 00
[ 6748.915197] spi-loopback-test spi13.0:     spi_transfer@00000000cd58625b
[ 6748.915453] spi-loopback-test spi13.0:       len:    512
[ 6748.915656] spi-loopback-test spi13.0:       tx_buf: 0000000062a28e45
[ 6748.915901]           TX: 00000000: 01 02 03 04 05 06 07 08 09 0a 0b
0c 0d 0e 0f 10
[ 6748.916194]           TX: 00000010: 11 12 13 14 15 16 17 18 19 1a 1b
1c 1d 1e 1f 20
[ 6748.916492]           TX: 00000020: 21 22 23 24 25 26 27 28 29 2a 2b
2c 2d 2e 2f 30
[ 6748.916780]           TX: 00000030: 31 32 33 34 35 36 37 38 39 3a 3b
3c 3d 3e 3f 40
[ 6748.917072]           TX: 00000040: 41 42 43 44 45 46 47 48 49 4a 4b
4c 4d 4e 4f 50
[ 6748.917365]           TX: 00000050: 51 52 53 54 55 56 57 58 59 5a 5b
5c 5d 5e 5f 60
[ 6748.917658]           TX: 00000060: 61 62 63 64 65 66 67 68 69 6a 6b
6c 6d 6e 6f 70
[ 6748.917950]           TX: 00000070: 71 72 73 74 75 76 77 78 79 7a 7b
7c 7d 7e 7f 80
[ 6748.918243]           TX: 00000080: 81 82 83 84 85 86 87 88 89 8a 8b
8c 8d 8e 8f 90
[ 6748.918539]           TX: 00000090: 91 92 93 94 95 96 97 98 99 9a 9b
9c 9d 9e 9f a0
[ 6748.918833]           TX: 000000a0: a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab
ac ad ae af b0
[ 6748.919121]           TX: 000000b0: b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb
bc bd be bf c0
[ 6748.919414]           TX: 000000c0: c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb
cc cd ce cf d0
[ 6748.919706]           TX: 000000d0: d1 d2 d3 d4 d5 d6 d7 d8 d9 da db
dc dd de df e0
[ 6748.919999]           TX: 000000e0: e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb
ec ed ee ef f0
[ 6748.920292]           TX: 000000f0: f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb
fc fd fe ff 00
[ 6748.920584]           TX: 00000100: 01 02 03 04 05 06 07 08 09 0a 0b
0c 0d 0e 0f 10
[ 6748.920877]           TX: 00000110: 11 12 13 14 15 16 17 18 19 1a 1b
1c 1d 1e 1f 20
[ 6748.921174]           TX: 00000120: 21 22 23 24 25 26 27 28 29 2a 2b
2c 2d 2e 2f 30
[ 6748.921463]           TX: 00000130: 31 32 33 34 35 36 37 38 39 3a 3b
3c 3d 3e 3f 40
[ 6748.921755]           TX: 00000140: 41 42 43 44 45 46 47 48 49 4a 4b
4c 4d 4e 4f 50
[ 6748.922048]           TX: 00000150: 51 52 53 54 55 56 57 58 59 5a 5b
5c 5d 5e 5f 60
[ 6748.922341]           TX: 00000160: 61 62 63 64 65 66 67 68 69 6a 6b
6c 6d 6e 6f 70
[ 6748.922636]           TX: 00000170: 71 72 73 74 75 76 77 78 79 7a 7b
7c 7d 7e 7f 80
[ 6748.922926]           TX: 00000180: 81 82 83 84 85 86 87 88 89 8a 8b
8c 8d 8e 8f 90
[ 6748.923219]           TX: 00000190: 91 92 93 94 95 96 97 98 99 9a 9b
9c 9d 9e 9f a0
[ 6748.923516]           TX: 000001a0: a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab
ac ad ae af b0
[ 6748.923804]           TX: 000001b0: b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb
bc bd be bf c0
[ 6748.924097]           TX: 000001c0: c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb
cc cd ce cf d0
[ 6748.924390]           TX: 000001d0: d1 d2 d3 d4 d5 d6 d7 d8 d9 da db
dc dd de df e0
[ 6748.924682]           TX: 000001e0: e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb
ec ed ee ef f0
[ 6748.924975]           TX: 000001f0: f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb
fc fd fe ff 00
[ 6748.925268] spi-loopback-test spi13.0:       rx_buf: 00000000df223723
[ 6748.925514]           RX: 00000000: 01 02 03 04 05 06 07 08 09 0a 0b
0c 0d 0e 0f 10
[ 6748.925811]           RX: 00000010: 11 12 13 14 15 16 17 18 19 1a 1b
1c 1d 1e 1f 20
[ 6748.926099]           RX: 00000020: 21 22 23 24 25 26 27 28 29 2a 2b
2c 2d 2e 2f 30
[ 6748.926392]           RX: 00000030: 31 32 33 34 35 36 37 38 39 3a 3b
3c 3d 3e 3f 40
[ 6748.926687]           RX: 00000040: 41 42 43 44 45 46 47 48 49 4a 4b
4c 4d 4e 4f 50
[ 6748.926977]           RX: 00000050: 51 52 53 54 55 56 57 58 59 5a 5b
5c 5d 5e 5f 60
[ 6748.927270]           RX: 00000060: 61 62 63 64 65 66 67 68 69 6a 6b
6c 6d 6e 6f 70
[ 6748.927562]           RX: 00000070: 71 72 73 74 75 76 77 78 79 7a 7b
7c 7d 7e 7f 80
[ 6748.927855]           RX: 00000080: 81 82 83 84 85 86 87 88 89 8a 8b
8c 8d 8e 8f 90
[ 6748.928153]           RX: 00000090: 91 92 93 94 95 96 97 98 99 9a 9b
9c 9d 9e 9f a0
[ 6748.928440]           RX: 000000a0: a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab
ac ad ae af b0
[ 6748.928733]           RX: 000000b0: b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb
bc bd be bf c0
[ 6748.929026]           RX: 000000c0: c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb
cc cd ce cf d0
[ 6748.929318]           RX: 000000d0: d1 d2 d3 d4 d5 d6 d7 d8 d9 da db
dc dd de df e0
[ 6748.929611]           RX: 000000e0: e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb
ec ed ee ef f0
[ 6748.929904]           RX: 000000f0: f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb
fc fd fe ff 00
[ 6748.930197]           RX: 00000100: 01 02 03 04 05 06 07 08 09 0a 0b
0c 0d 0e 0f 10
[ 6748.930493]           RX: 00000110: 11 12 13 14 15 16 17 18 19 1a 1b
1c 1d 1e 1f 20
[ 6748.930782]           RX: 00000120: 21 22 23 24 25 26 27 28 29 2a 2b
2c 2d 2e 2f 30
[ 6748.931074]           RX: 00000130: 31 32 33 34 35 36 37 38 39 3a 3b
3c 3d 3e 3f 40
[ 6748.931367]           RX: 00000140: 41 42 43 44 45 46 47 48 49 4a 4b
4c 4d 4e 4f 50
[ 6748.931660]           RX: 00000150: 51 52 53 54 55 56 57 58 59 5a 5b
5c 5d 5e 5f 60
[ 6748.931953]           RX: 00000160: 61 62 63 64 65 66 67 68 69 6a 6b
6c 6d 6e 6f 70
[ 6748.932245]           RX: 00000170: 71 72 73 74 75 76 77 78 79 7a 7b
7c 7d 7e 7f 80
[ 6748.932538]           RX: 00000180: 81 82 83 84 85 86 87 88 89 8a 8b
8c 8d 8e 8f 90
[ 6748.932836]           RX: 00000190: 91 92 93 94 95 96 97 98 99 9a 9b
9c 9d 9e 9f a0
[ 6748.933123]           RX: 000001a0: a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab
ac ad ae af b0
[ 6748.933416]           RX: 000001b0: b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb
bc bd be bf c0
[ 6748.933709]           RX: 000001c0: c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb
cc cd ce cf d0
[ 6748.934001]           RX: 000001d0: d1 d2 d3 d4 d5 d6 d7 d8 d9 da db
dc dd de df e0
[ 6748.934294]           RX: 000001e0: e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb
ec ed ee ef f0
[ 6748.934589]           RX: 000001f0: f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb
fc fd fe ff 00
[ 6748.934880] spi-loopback-test spi13.0:     spi_transfer@00000000774992f1
[ 6748.935140] spi-loopback-test spi13.0:       len:    1
[ 6748.935332] spi-loopback-test spi13.0:       tx_buf: 00000000401e03ed
[ 6748.935578]           TX: 00000000: 01
[ 6748.935721] spi-loopback-test spi13.0:       rx_buf: 0000000010f7e3e4
[ 6748.935967]           RX: 00000000: 01
[ 6749.236147] spi-loopback-test spi13.0: Finished spi-loopback-tests
with return: 0

On 3/17/17 18:17, Akinobu Mita wrote:
> This adds checks whether the elapsed time is longer than the minimam
> estimated time.  The estimated time is calculated with the total
> transfer length per clock rate and optional spi_transfer.delay_usecs.
> 
> Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
> Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> Signed-off-by: Akinobu Mita <akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/spi/spi-loopback-test.c | 38 ++++++++++++++++++++++++++++++++++++++
>  drivers/spi/spi-test.h          |  2 ++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c
> index 6df6ddd..66e8cfd0 100644
> --- a/drivers/spi/spi-loopback-test.c
> +++ b/drivers/spi/spi-loopback-test.c
> @@ -20,6 +20,7 @@
>  
>  #include <linux/delay.h>
>  #include <linux/kernel.h>
> +#include <linux/ktime.h>
>  #include <linux/list.h>
>  #include <linux/list_sort.h>
>  #include <linux/module.h>
> @@ -479,6 +480,35 @@ static int spi_check_rx_ranges(struct spi_device *spi,
>  	return ret;
>  }
>  
> +static int spi_test_check_elapsed_time(struct spi_device *spi,
> +				       struct spi_test *test)
> +{
> +	int i;
> +	unsigned long long estimated_time = 0;
> +	unsigned long long delay_usecs = 0;
> +
> +	for (i = 0; i < test->transfer_count; i++) {
> +		struct spi_transfer *xfer = test->transfers + i;
> +		unsigned long long nbits = BITS_PER_BYTE * xfer->len;
> +
> +		delay_usecs += xfer->delay_usecs;
> +		if (!xfer->speed_hz)
> +			continue;
> +		estimated_time += div_u64(nbits * NSEC_PER_SEC, xfer->speed_hz);
> +	}
> +
> +	estimated_time += delay_usecs * NSEC_PER_USEC;
> +	if (test->elapsed_time < estimated_time) {
> +		dev_err(&spi->dev,
> +			"elapsed time %lld ns is shorter than minimam estimated time %lld ns\n",
> +			test->elapsed_time, estimated_time);
> +
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
>  static int spi_test_check_loopback_result(struct spi_device *spi,
>  					  struct spi_message *msg,
>  					  void *tx, void *rx)
> @@ -817,12 +847,16 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test,
>  
>  	/* only if we do not simulate */
>  	if (!simulate_only) {
> +		ktime_t start;
> +
>  		/* dump the complete message before and after the transfer */
>  		if (dump_messages == 3)
>  			spi_test_dump_message(spi, msg, true);
>  
> +		start = ktime_get();
>  		/* run spi message */
>  		ret = spi_sync(spi, msg);
> +		test->elapsed_time = ktime_to_ns(ktime_sub(ktime_get(), start));
>  		if (ret == -ETIMEDOUT) {
>  			dev_info(&spi->dev,
>  				 "spi-message timed out - reruning...\n");
> @@ -848,6 +882,10 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test,
>  
>  		/* run rx-buffer tests */
>  		ret = spi_test_check_loopback_result(spi, msg, tx, rx);
> +		if (ret)
> +			goto exit;
> +
> +		ret = spi_test_check_elapsed_time(spi, test);
>  	}
>  
>  	/* if requested or on error dump message (including data) */
> diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h
> index 82fff4a..6ed7b89 100644
> --- a/drivers/spi/spi-test.h
> +++ b/drivers/spi/spi-test.h
> @@ -75,6 +75,7 @@
>   * @fill_option:      define the way how tx_buf is filled
>   * @fill_pattern:     fill pattern to apply to the tx_buf
>   *                    (used in some of the @fill_options)
> + * @elapsed_time:     elapsed time in nanoseconds
>   */
>  
>  struct spi_test {
> @@ -108,6 +109,7 @@ struct spi_test {
>  #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */
>  #define FILL_TRANSFER_NUM     16 /* fill with the transfer number */
>  	u32 fill_pattern;
> +	unsigned long long elapsed_time;
>  };
>  
>  /* default implementation for @spi_test.run_test */

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/6] spi: loopback-test: add elapsed time check
  2024-01-12 16:19     ` [PATCH 5/6] spi: loopback-test: add elapsed time check Tudor Ambarus
@ 2024-01-12 18:37       ` Mark Brown
  2024-01-18  8:30         ` Tudor Ambarus
  0 siblings, 1 reply; 18+ messages in thread
From: Mark Brown @ 2024-01-12 18:37 UTC (permalink / raw)
  To: Tudor Ambarus; +Cc: akinobu.mita, linux-spi, kernel

[-- Attachment #1: Type: text/plain, Size: 1605 bytes --]

On Fri, Jan 12, 2024 at 04:19:10PM +0000, Tudor Ambarus wrote:

> I'm playing with the spi-s3c64xx.c driver and the spi-loopback-test and
> sometimes I see that I get the following error:

> ```elapsed time x ns is shorter than minimum estimated time y ns```

> What's strange to me is that if I ignore the return value of
> spi_test_check_elapsed_time(), the test passes, there's no transfer
> mismatch and what we expect we actually get at RX.

> What kind of errors does the spi_test_check_elapsed_time() check want to
> discover? Under what conditions the test->elapsed_time is inaccurate?

The test is calculating the expected time based on the intended clock
rate for the bus and any delays in the message.  This should identify if
a driver is either ignoring specified delays or overclocking the bus.

> [ 6748.910773] spi-loopback-test spi13.0:     spi_transfer@00000000774992f1
> [ 6748.911035] spi-loopback-test spi13.0:       len:    1
> [ 6748.911225] spi-loopback-test spi13.0:       tx_buf: 00000000401e03ed
> [ 6748.911472]           TX: 00000000: 01
> [ 6748.911614] spi-loopback-test spi13.0:       rx_buf: 0000000010f7e3e4
> [ 6748.911860]           RX: 00000000: aa
> [ 6748.912004] spi-loopback-test spi13.0:       rx_buf filled with aa
> starts at offset: 0

> [ 6748.913400] spi-loopback-test spi13.0: elapsed time 532837 ns is
> shorter than minimum estimated time 82240000 ns

That's a *very* substantial error, it makes me suspect that the hardware
might be doing loopback at a stage before it actually clocks the bus and
doing something like just connecting the TX and RX FIFOs.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/6] spi: loopback-test: add elapsed time check
  2024-01-12 18:37       ` Mark Brown
@ 2024-01-18  8:30         ` Tudor Ambarus
  2024-01-18 12:42           ` Mark Brown
  0 siblings, 1 reply; 18+ messages in thread
From: Tudor Ambarus @ 2024-01-18  8:30 UTC (permalink / raw)
  To: Mark Brown; +Cc: akinobu.mita, linux-spi, kernel



On 1/12/24 18:37, Mark Brown wrote:
>> [ 6748.913400] spi-loopback-test spi13.0: elapsed time 532837 ns is
>> shorter than minimum estimated time 82240000 ns
> That's a *very* substantial error, it makes me suspect that the hardware
> might be doing loopback at a stage before it actually clocks the bus and
> doing something like just connecting the TX and RX FIFOs.

Thanks, Mark! It was a problem on how the clocks were handled, I ended
up with a higher frequency than I requested.

Cheers,
ta

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/6] spi: loopback-test: add elapsed time check
  2024-01-18  8:30         ` Tudor Ambarus
@ 2024-01-18 12:42           ` Mark Brown
  2024-01-18 13:43             ` Tudor Ambarus
  0 siblings, 1 reply; 18+ messages in thread
From: Mark Brown @ 2024-01-18 12:42 UTC (permalink / raw)
  To: Tudor Ambarus; +Cc: akinobu.mita, linux-spi, kernel

[-- Attachment #1: Type: text/plain, Size: 658 bytes --]

On Thu, Jan 18, 2024 at 08:30:39AM +0000, Tudor Ambarus wrote:
> On 1/12/24 18:37, Mark Brown wrote:

> >> [ 6748.913400] spi-loopback-test spi13.0: elapsed time 532837 ns is
> >> shorter than minimum estimated time 82240000 ns

> > That's a *very* substantial error, it makes me suspect that the hardware
> > might be doing loopback at a stage before it actually clocks the bus and
> > doing something like just connecting the TX and RX FIFOs.

> Thanks, Mark! It was a problem on how the clocks were handled, I ended
> up with a higher frequency than I requested.

Ouch, hopefully that's only affecting loopback mode and not normal
operation for everyone.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/6] spi: loopback-test: add elapsed time check
  2024-01-18 12:42           ` Mark Brown
@ 2024-01-18 13:43             ` Tudor Ambarus
  0 siblings, 0 replies; 18+ messages in thread
From: Tudor Ambarus @ 2024-01-18 13:43 UTC (permalink / raw)
  To: Mark Brown; +Cc: akinobu.mita, linux-spi, kernel



On 1/18/24 12:42, Mark Brown wrote:
> On Thu, Jan 18, 2024 at 08:30:39AM +0000, Tudor Ambarus wrote:
>> On 1/12/24 18:37, Mark Brown wrote:
> 
>>>> [ 6748.913400] spi-loopback-test spi13.0: elapsed time 532837 ns is
>>>> shorter than minimum estimated time 82240000 ns
> 
>>> That's a *very* substantial error, it makes me suspect that the hardware
>>> might be doing loopback at a stage before it actually clocks the bus and
>>> doing something like just connecting the TX and RX FIFOs.
> 
>> Thanks, Mark! It was a problem on how the clocks were handled, I ended
>> up with a higher frequency than I requested.
> 
> Ouch, hopefully that's only affecting loopback mode and not normal
> operation for everyone.

It was a problem on the clock driver which is not yet upstream. SPI is
fine, in loopback mode at least, that's all I could test for now.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-01-18 13:43 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-17 18:17 [PATCH 0/6] spi: loopback-test: add new tests and bug fixes Akinobu Mita
     [not found] ` <1489774651-30170-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-17 18:17   ` [PATCH 1/6] spi: loopback-test: correct mismatched test description and configuration Akinobu Mita
     [not found]     ` <1489774651-30170-2-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-17 21:55       ` Applied "spi: loopback-test: correct mismatched test description and configuration" to the spi tree Mark Brown
2017-03-17 18:17   ` [PATCH 2/6] spi: loopback-test: don't skip comparing the first byte of rx_buf Akinobu Mita
     [not found]     ` <1489774651-30170-3-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-17 21:54       ` Applied "spi: loopback-test: don't skip comparing the first byte of rx_buf" to the spi tree Mark Brown
2017-03-17 18:17   ` [PATCH 3/6] spi: loopback-test: add ability to test zero-length transfer Akinobu Mita
     [not found]     ` <1489774651-30170-4-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-17 21:54       ` Applied "spi: loopback-test: add ability to test zero-length transfer" to the spi tree Mark Brown
2017-03-17 18:17   ` [PATCH 4/6] spi: loopback-test: test zero-length transfer Akinobu Mita
     [not found]     ` <1489774651-30170-5-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-17 21:54       ` Applied "spi: loopback-test: test zero-length transfer" to the spi tree Mark Brown
2017-03-17 18:17   ` [PATCH 5/6] spi: loopback-test: add elapsed time check Akinobu Mita
     [not found]     ` <1489774651-30170-6-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-17 21:54       ` Applied "spi: loopback-test: add elapsed time check" to the spi tree Mark Brown
2024-01-12 16:19     ` [PATCH 5/6] spi: loopback-test: add elapsed time check Tudor Ambarus
2024-01-12 18:37       ` Mark Brown
2024-01-18  8:30         ` Tudor Ambarus
2024-01-18 12:42           ` Mark Brown
2024-01-18 13:43             ` Tudor Ambarus
2017-03-17 18:17   ` [PATCH 6/6] spi: loopback-test: add test spi_message with delay after transfers Akinobu Mita
     [not found]     ` <1489774651-30170-7-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-03-17 21:54       ` Applied "spi: loopback-test: add test spi_message with delay after transfers" to the spi tree Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.