Commit 980e0b36 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] cec: split the timestamp into an rx and tx timestamp

When transmitting a message and waiting for a reply it would be good
to know the time between when the message was transmitted and when
the reply arrived. With only one timestamp field it was set to when
the reply arrived and the original transmit time was overwritten.

Just taking the timestamp in userspace right before CEC_TRANSMIT is
called is not reliable, since the actual transmit can be delayed if
the CEC bus is busy. Only the driver can fill this in accurately.

So split up the ts field into an rx_ts and a tx_ts. Also move the
status fields to after the 'reply' field: they were placed in a
strange position and make much more sense when grouped with the
other status-related fields.

This patch also makes sure that the timestamp is taken as soon as
possible.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 52d802d6
...@@ -284,7 +284,7 @@ static void cec_data_cancel(struct cec_data *data) ...@@ -284,7 +284,7 @@ static void cec_data_cancel(struct cec_data *data)
list_del_init(&data->list); list_del_init(&data->list);
/* Mark it as an error */ /* Mark it as an error */
data->msg.ts = ktime_get_ns(); data->msg.tx_ts = ktime_get_ns();
data->msg.tx_status = CEC_TX_STATUS_ERROR | data->msg.tx_status = CEC_TX_STATUS_ERROR |
CEC_TX_STATUS_MAX_RETRIES; CEC_TX_STATUS_MAX_RETRIES;
data->attempts = 0; data->attempts = 0;
...@@ -459,6 +459,7 @@ void cec_transmit_done(struct cec_adapter *adap, u8 status, u8 arb_lost_cnt, ...@@ -459,6 +459,7 @@ void cec_transmit_done(struct cec_adapter *adap, u8 status, u8 arb_lost_cnt,
{ {
struct cec_data *data; struct cec_data *data;
struct cec_msg *msg; struct cec_msg *msg;
u64 ts = ktime_get_ns();
dprintk(2, "cec_transmit_done %02x\n", status); dprintk(2, "cec_transmit_done %02x\n", status);
mutex_lock(&adap->lock); mutex_lock(&adap->lock);
...@@ -477,7 +478,7 @@ void cec_transmit_done(struct cec_adapter *adap, u8 status, u8 arb_lost_cnt, ...@@ -477,7 +478,7 @@ void cec_transmit_done(struct cec_adapter *adap, u8 status, u8 arb_lost_cnt,
/* Drivers must fill in the status! */ /* Drivers must fill in the status! */
WARN_ON(status == 0); WARN_ON(status == 0);
msg->ts = ktime_get_ns(); msg->tx_ts = ts;
msg->tx_status |= status; msg->tx_status |= status;
msg->tx_arb_lost_cnt += arb_lost_cnt; msg->tx_arb_lost_cnt += arb_lost_cnt;
msg->tx_nack_cnt += nack_cnt; msg->tx_nack_cnt += nack_cnt;
...@@ -561,7 +562,7 @@ static void cec_wait_timeout(struct work_struct *work) ...@@ -561,7 +562,7 @@ static void cec_wait_timeout(struct work_struct *work)
/* Mark the message as timed out */ /* Mark the message as timed out */
list_del_init(&data->list); list_del_init(&data->list);
data->msg.ts = ktime_get_ns(); data->msg.rx_ts = ktime_get_ns();
data->msg.rx_status = CEC_RX_STATUS_TIMEOUT; data->msg.rx_status = CEC_RX_STATUS_TIMEOUT;
cec_data_completed(data); cec_data_completed(data);
unlock: unlock:
...@@ -766,13 +767,14 @@ void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg) ...@@ -766,13 +767,14 @@ void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg)
if (WARN_ON(!msg->len || msg->len > CEC_MAX_MSG_SIZE)) if (WARN_ON(!msg->len || msg->len > CEC_MAX_MSG_SIZE))
return; return;
mutex_lock(&adap->lock); msg->rx_ts = ktime_get_ns();
msg->ts = ktime_get_ns();
msg->rx_status = CEC_RX_STATUS_OK; msg->rx_status = CEC_RX_STATUS_OK;
msg->tx_status = 0;
msg->sequence = msg->reply = msg->timeout = 0; msg->sequence = msg->reply = msg->timeout = 0;
msg->tx_status = 0;
msg->tx_ts = 0;
msg->flags = 0; msg->flags = 0;
mutex_lock(&adap->lock);
dprintk(2, "cec_received_msg: %*ph\n", msg->len, msg->msg); dprintk(2, "cec_received_msg: %*ph\n", msg->len, msg->msg);
/* Check if this message was for us (directed or broadcast). */ /* Check if this message was for us (directed or broadcast). */
...@@ -794,7 +796,6 @@ void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg) ...@@ -794,7 +796,6 @@ void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg)
*/ */
list_for_each_entry(data, &adap->wait_queue, list) { list_for_each_entry(data, &adap->wait_queue, list) {
struct cec_msg *dst = &data->msg; struct cec_msg *dst = &data->msg;
u8 dst_reply;
/* Does the command match? */ /* Does the command match? */
if ((abort && cmd != dst->msg[1]) || if ((abort && cmd != dst->msg[1]) ||
...@@ -807,11 +808,10 @@ void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg) ...@@ -807,11 +808,10 @@ void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg)
continue; continue;
/* We got a reply */ /* We got a reply */
msg->sequence = dst->sequence; memcpy(dst->msg, msg->msg, msg->len);
msg->tx_status = dst->tx_status; dst->len = msg->len;
dst_reply = dst->reply; dst->rx_ts = msg->rx_ts;
*dst = *msg; dst->rx_status = msg->rx_status;
dst->reply = dst_reply;
if (abort) { if (abort) {
dst->reply = 0; dst->reply = 0;
dst->rx_status |= CEC_RX_STATUS_FEATURE_ABORT; dst->rx_status |= CEC_RX_STATUS_FEATURE_ABORT;
......
...@@ -48,9 +48,10 @@ ...@@ -48,9 +48,10 @@
/** /**
* struct cec_msg - CEC message structure. * struct cec_msg - CEC message structure.
* @ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the * @tx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the
* driver. It is set when the message transmission has finished * driver when the message transmission has finished.
* and it is set when a message was received. * @rx_ts: Timestamp in nanoseconds using CLOCK_MONOTONIC. Set by the
* driver when the message was received.
* @len: Length in bytes of the message. * @len: Length in bytes of the message.
* @timeout: The timeout (in ms) that is used to timeout CEC_RECEIVE. * @timeout: The timeout (in ms) that is used to timeout CEC_RECEIVE.
* Set to 0 if you want to wait forever. This timeout can also be * Set to 0 if you want to wait forever. This timeout can also be
...@@ -61,8 +62,6 @@ ...@@ -61,8 +62,6 @@
* sent. This can be used to track replies to previously sent * sent. This can be used to track replies to previously sent
* messages. * messages.
* @flags: Set to 0. * @flags: Set to 0.
* @rx_status: The message receive status bits. Set by the driver.
* @tx_status: The message transmit status bits. Set by the driver.
* @msg: The message payload. * @msg: The message payload.
* @reply: This field is ignored with CEC_RECEIVE and is only used by * @reply: This field is ignored with CEC_RECEIVE and is only used by
* CEC_TRANSMIT. If non-zero, then wait for a reply with this * CEC_TRANSMIT. If non-zero, then wait for a reply with this
...@@ -80,6 +79,8 @@ ...@@ -80,6 +79,8 @@
* broadcast, then -EINVAL is returned. * broadcast, then -EINVAL is returned.
* if reply is non-zero, then timeout is set to 1000 (the required * if reply is non-zero, then timeout is set to 1000 (the required
* maximum response time). * maximum response time).
* @rx_status: The message receive status bits. Set by the driver.
* @tx_status: The message transmit status bits. Set by the driver.
* @tx_arb_lost_cnt: The number of 'Arbitration Lost' events. Set by the driver. * @tx_arb_lost_cnt: The number of 'Arbitration Lost' events. Set by the driver.
* @tx_nack_cnt: The number of 'Not Acknowledged' events. Set by the driver. * @tx_nack_cnt: The number of 'Not Acknowledged' events. Set by the driver.
* @tx_low_drive_cnt: The number of 'Low Drive Detected' events. Set by the * @tx_low_drive_cnt: The number of 'Low Drive Detected' events. Set by the
...@@ -87,15 +88,16 @@ ...@@ -87,15 +88,16 @@
* @tx_error_cnt: The number of 'Error' events. Set by the driver. * @tx_error_cnt: The number of 'Error' events. Set by the driver.
*/ */
struct cec_msg { struct cec_msg {
__u64 ts; __u64 tx_ts;
__u64 rx_ts;
__u32 len; __u32 len;
__u32 timeout; __u32 timeout;
__u32 sequence; __u32 sequence;
__u32 flags; __u32 flags;
__u8 rx_status;
__u8 tx_status;
__u8 msg[CEC_MAX_MSG_SIZE]; __u8 msg[CEC_MAX_MSG_SIZE];
__u8 reply; __u8 reply;
__u8 rx_status;
__u8 tx_status;
__u8 tx_arb_lost_cnt; __u8 tx_arb_lost_cnt;
__u8 tx_nack_cnt; __u8 tx_nack_cnt;
__u8 tx_low_drive_cnt; __u8 tx_low_drive_cnt;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment