spi/trace: include buffer contents in traces
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fri, 21 Dec 2018 10:35:36 +0000 (11:35 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 7 Jan 2019 18:33:10 +0000 (18:33 +0000)
It highly improves usability when the buffer contents are inspecable via
tracing.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
include/trace/events/spi.h

index 6eb014f59efb24b7a12d9f00ddc4a768d6231119..aef6869f563dfce8f0ce54bb7d417d8d141f6f44 100644 (file)
@@ -109,6 +109,16 @@ TRACE_EVENT(spi_message_done,
                   (unsigned)__entry->actual, (unsigned)__entry->frame)
 );
 
+/*
+ * consider a buffer valid if non-NULL and if it doesn't match the dummy buffer
+ * that only exist to work with controllers that have SPI_CONTROLLER_MUST_TX or
+ * SPI_CONTROLLER_MUST_RX.
+ */
+#define spi_valid_txbuf(msg, xfer) \
+       (xfer->tx_buf && xfer->tx_buf != msg->spi->controller->dummy_tx)
+#define spi_valid_rxbuf(msg, xfer) \
+       (xfer->rx_buf && xfer->rx_buf != msg->spi->controller->dummy_rx)
+
 DECLARE_EVENT_CLASS(spi_transfer,
 
        TP_PROTO(struct spi_message *msg, struct spi_transfer *xfer),
@@ -120,6 +130,10 @@ DECLARE_EVENT_CLASS(spi_transfer,
                __field(        int,            chip_select     )
                __field(        struct spi_transfer *,   xfer   )
                __field(        int,            len             )
+               __dynamic_array(u8, rx_buf,
+                               spi_valid_rxbuf(msg, xfer) ? xfer->len : 0)
+               __dynamic_array(u8, tx_buf,
+                               spi_valid_txbuf(msg, xfer) ? xfer->len : 0)
        ),
 
        TP_fast_assign(
@@ -127,11 +141,21 @@ DECLARE_EVENT_CLASS(spi_transfer,
                __entry->chip_select = msg->spi->chip_select;
                __entry->xfer = xfer;
                __entry->len = xfer->len;
+
+               if (spi_valid_txbuf(msg, xfer))
+                       memcpy(__get_dynamic_array(tx_buf),
+                              xfer->tx_buf, xfer->len);
+
+               if (spi_valid_rxbuf(msg, xfer))
+                       memcpy(__get_dynamic_array(rx_buf),
+                              xfer->rx_buf, xfer->len);
        ),
 
-        TP_printk("spi%d.%d %p len=%d",
+       TP_printk("spi%d.%d %p len=%d tx=[%*phD] rx=[%*phD]",
                  __entry->bus_num, __entry->chip_select,
-                 __entry->xfer, __entry->len)
+                 __entry->xfer, __entry->len,
+                 __get_dynamic_array_len(tx_buf), __get_dynamic_array(tx_buf),
+                 __get_dynamic_array_len(rx_buf), __get_dynamic_array(rx_buf))
 );
 
 DEFINE_EVENT(spi_transfer, spi_transfer_start,