All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: broonie@kernel.org
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	eha@deif.com, angelo@sysam.it, andrew.smirnov@gmail.com,
	gustavo@embeddedor.com, weic@nvidia.com, mhosny@nvidia.com
Subject: [PATCH 07/12] spi: Do spi_take_timestamp_pre for as many times as necessary
Date: Thu,  5 Mar 2020 00:00:39 +0200	[thread overview]
Message-ID: <20200304220044.11193-8-olteanv@gmail.com> (raw)
In-Reply-To: <20200304220044.11193-1-olteanv@gmail.com>

From: Vladimir Oltean <vladimir.oltean@nxp.com>

When dealing with a SPI controller driver that is sending more than 1
byte at once (or the entire buffer at once), and the SPI peripheral
driver has requested timestamping for a byte in the middle of the
buffer, we find that spi_take_timestamp_pre never records a "pre"
timestamp.

This happens because the function currently expects to be called with
the "progress" argument >= to what the peripheral has requested to be
timestamped. But clearly there are cases when that isn't going to fly.

And since we can't change the past when we realize that the opportunity
to take a "pre" timestamp has just passed and there isn't going to be
another one, the approach taken is to keep recording the "pre" timestamp
on each call, overwriting the previously recorded one until the "post"
timestamp is also taken.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/spi/spi.c       | 19 +++++++------------
 include/linux/spi/spi.h |  3 +--
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a8495fd3bb47..22baf204a09d 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1515,17 +1515,15 @@ void spi_take_timestamp_pre(struct spi_controller *ctlr,
 	if (!xfer->ptp_sts)
 		return;
 
-	if (xfer->timestamped_pre)
+	if (xfer->timestamped)
 		return;
 
-	if (progress < xfer->ptp_sts_word_pre)
+	if (progress > xfer->ptp_sts_word_pre)
 		return;
 
 	/* Capture the resolution of the timestamp */
 	xfer->ptp_sts_word_pre = progress;
 
-	xfer->timestamped_pre = true;
-
 	if (irqs_off) {
 		local_irq_save(ctlr->irq_flags);
 		preempt_disable();
@@ -1554,7 +1552,7 @@ void spi_take_timestamp_post(struct spi_controller *ctlr,
 	if (!xfer->ptp_sts)
 		return;
 
-	if (xfer->timestamped_post)
+	if (xfer->timestamped)
 		return;
 
 	if (progress < xfer->ptp_sts_word_post)
@@ -1570,7 +1568,7 @@ void spi_take_timestamp_post(struct spi_controller *ctlr,
 	/* Capture the resolution of the timestamp */
 	xfer->ptp_sts_word_post = progress;
 
-	xfer->timestamped_post = true;
+	xfer->timestamped = true;
 }
 EXPORT_SYMBOL_GPL(spi_take_timestamp_post);
 
@@ -1675,12 +1673,9 @@ void spi_finalize_current_message(struct spi_controller *ctlr)
 		}
 	}
 
-	if (unlikely(ctlr->ptp_sts_supported)) {
-		list_for_each_entry(xfer, &mesg->transfers, transfer_list) {
-			WARN_ON_ONCE(xfer->ptp_sts && !xfer->timestamped_pre);
-			WARN_ON_ONCE(xfer->ptp_sts && !xfer->timestamped_post);
-		}
-	}
+	if (unlikely(ctlr->ptp_sts_supported))
+		list_for_each_entry(xfer, &mesg->transfers, transfer_list)
+			WARN_ON_ONCE(xfer->ptp_sts && !xfer->timestamped);
 
 	spi_unmap_msg(ctlr, mesg);
 
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 600e3793303e..87105272879b 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -933,8 +933,7 @@ struct spi_transfer {
 
 	struct ptp_system_timestamp *ptp_sts;
 
-	bool		timestamped_pre;
-	bool		timestamped_post;
+	bool		timestamped;
 
 	struct list_head transfer_list;
 };
-- 
2.17.1


  parent reply	other threads:[~2020-03-04 22:02 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-04 22:00 [PATCH 00/12] TCFQ to XSPI migration for NXP DSPI driver Vladimir Oltean
2020-03-04 22:00 ` Vladimir Oltean
2020-03-04 22:00 ` [PATCH 01/12] spi: spi-fsl-dspi: Simplify bytes_per_word gymnastics Vladimir Oltean
2020-03-05 14:38   ` Applied "spi: spi-fsl-dspi: Simplify bytes_per_word gymnastics" to the spi tree Mark Brown
2020-03-05 14:38     ` Mark Brown
2020-03-04 22:00 ` [PATCH 02/12] spi: spi-fsl-dspi: Remove unused chip->void_write_data Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Remove unused chip->void_write_data" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 03/12] spi: spi-fsl-dspi: Don't mask off undefined bits Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Don't mask off undefined bits" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 04/12] spi: spi-fsl-dspi: Add comments around dspi_pop_tx and dspi_push_rx functions Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Add comments around dspi_pop_tx and dspi_push_rx functions" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 05/12] spi: spi-fsl-dspi: Rename fifo_{read,write} and {tx,cmd}_fifo_write Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Rename fifo_{read,write} and {tx,cmd}_fifo_write" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 06/12] spi: spi-fsl-dspi: Implement .max_message_size method for EOQ mode Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Implement .max_message_size method for EOQ mode" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` Vladimir Oltean [this message]
2020-03-05 12:12   ` [PATCH 07/12] spi: Do spi_take_timestamp_pre for as many times as necessary Mark Brown
2020-03-05 12:12     ` Mark Brown
2020-03-05 13:00     ` Vladimir Oltean
2020-03-05 13:04       ` Mark Brown
2020-03-05 13:04         ` Mark Brown
2020-03-05 13:13         ` Vladimir Oltean
2020-03-05 13:13           ` Vladimir Oltean
2020-03-05 13:16           ` Mark Brown
2020-03-05 13:16             ` Mark Brown
2020-03-05 14:37   ` Applied "spi: Do spi_take_timestamp_pre for as many times as necessary" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 08/12] spi: spi-fsl-dspi: Convert TCFQ users to XSPI FIFO mode Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Convert TCFQ users to XSPI FIFO mode" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 09/12] spi: spi-fsl-dspi: Accelerate transfers using larger word size if possible Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Accelerate transfers using larger word size if possible" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 10/12] spi: spi-fsl-dspi: Optimize dspi_setup_accel for lowest interrupt count Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Optimize dspi_setup_accel for lowest interrupt count" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 11/12] spi: spi-fsl-dspi: Use EOQ for last word in buffer even for XSPI mode Vladimir Oltean
2020-03-04 22:00   ` Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Use EOQ for last word in buffer even for XSPI mode" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown
2020-03-04 22:00 ` [PATCH 12/12] spi: spi-fsl-dspi: Take software timestamp in dspi_fifo_write Vladimir Oltean
2020-03-04 22:00   ` Vladimir Oltean
2020-03-05 14:37   ` Applied "spi: spi-fsl-dspi: Take software timestamp in dspi_fifo_write" to the spi tree Mark Brown
2020-03-05 14:37     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200304220044.11193-8-olteanv@gmail.com \
    --to=olteanv@gmail.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=angelo@sysam.it \
    --cc=broonie@kernel.org \
    --cc=eha@deif.com \
    --cc=gustavo@embeddedor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mhosny@nvidia.com \
    --cc=weic@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.