Skip to content

Commit 94ec448

Browse files
Hans Verkuilgregkh
authored andcommitted
media: cec: add new tx/rx status bits to detect aborts/timeouts
commit 7ec2b3b upstream. If the HDMI cable is disconnected or the CEC adapter is manually unconfigured, then all pending transmits and wait-for-replies are aborted. Signal this with new status bits (CEC_RX/TX_STATUS_ABORTED). If due to (usually) a driver bug a transmit never ends (i.e. the transmit_done was never called by the driver), then when this times out the message is marked with CEC_TX_STATUS_TIMEOUT. This should not happen and is an indication of a driver bug. Without a separate status bit for this it was impossible to detect this from userspace. The 'transmit timed out' kernel message is now a warning, so this should be more prominent in the kernel log as well. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Cc: <stable@vger.kernel.org> # for v4.18 and up Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 587960d commit 94ec448

3 files changed

Lines changed: 44 additions & 50 deletions

File tree

‎Documentation/media/uapi/cec/cec-ioc-receive.rst‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
1616
Synopsis
1717
========
1818

19-
.. c:function:: int ioctl( int fd, CEC_RECEIVE, struct cec_msg *argp )
19+
.. c:function:: int ioctl( int fd, CEC_RECEIVE, struct cec_msg \*argp )
2020
:name: CEC_RECEIVE
2121

22-
.. c:function:: int ioctl( int fd, CEC_TRANSMIT, struct cec_msg *argp )
22+
.. c:function:: int ioctl( int fd, CEC_TRANSMIT, struct cec_msg \*argp )
2323
:name: CEC_TRANSMIT
2424

2525
Arguments
@@ -272,6 +272,19 @@ View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
272272
- The transmit failed after one or more retries. This status bit is
273273
mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`.
274274
Other bits can still be set to explain which failures were seen.
275+
* .. _`CEC-TX-STATUS-ABORTED`:
276+
277+
- ``CEC_TX_STATUS_ABORTED``
278+
- 0x40
279+
- The transmit was aborted due to an HDMI disconnect, or the adapter
280+
was unconfigured, or a transmit was interrupted, or the driver
281+
returned an error when attempting to start a transmit.
282+
* .. _`CEC-TX-STATUS-TIMEOUT`:
283+
284+
- ``CEC_TX_STATUS_TIMEOUT``
285+
- 0x80
286+
- The transmit timed out. This should not normally happen and this
287+
indicates a driver problem.
275288

276289

277290
.. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
@@ -300,6 +313,14 @@ View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
300313
- The message was received successfully but the reply was
301314
``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
302315
was the reply to an earlier transmitted message.
316+
* .. _`CEC-RX-STATUS-ABORTED`:
317+
318+
- ``CEC_RX_STATUS_ABORTED``
319+
- 0x08
320+
- The wait for a reply to an earlier transmitted message was aborted
321+
because the HDMI cable was disconnected, the adapter was unconfigured
322+
or the :ref:`CEC_TRANSMIT <CEC_RECEIVE>` that waited for a
323+
reply was interrupted.
303324

304325

305326

‎drivers/media/cec/cec-adap.c‎

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static void cec_data_completed(struct cec_data *data)
341341
*
342342
* This function is called with adap->lock held.
343343
*/
344-
static void cec_data_cancel(struct cec_data *data)
344+
static void cec_data_cancel(struct cec_data *data, u8 tx_status)
345345
{
346346
/*
347347
* It's either the current transmit, or it is a pending
@@ -356,13 +356,11 @@ static void cec_data_cancel(struct cec_data *data)
356356
}
357357

358358
if (data->msg.tx_status & CEC_TX_STATUS_OK) {
359-
/* Mark the canceled RX as a timeout */
360359
data->msg.rx_ts = ktime_get_ns();
361-
data->msg.rx_status = CEC_RX_STATUS_TIMEOUT;
360+
data->msg.rx_status = CEC_RX_STATUS_ABORTED;
362361
} else {
363-
/* Mark the canceled TX as an error */
364362
data->msg.tx_ts = ktime_get_ns();
365-
data->msg.tx_status |= CEC_TX_STATUS_ERROR |
363+
data->msg.tx_status |= tx_status |
366364
CEC_TX_STATUS_MAX_RETRIES;
367365
data->msg.tx_error_cnt++;
368366
data->attempts = 0;
@@ -390,15 +388,15 @@ static void cec_flush(struct cec_adapter *adap)
390388
while (!list_empty(&adap->transmit_queue)) {
391389
data = list_first_entry(&adap->transmit_queue,
392390
struct cec_data, list);
393-
cec_data_cancel(data);
391+
cec_data_cancel(data, CEC_TX_STATUS_ABORTED);
394392
}
395393
if (adap->transmitting)
396-
cec_data_cancel(adap->transmitting);
394+
cec_data_cancel(adap->transmitting, CEC_TX_STATUS_ABORTED);
397395

398396
/* Cancel the pending timeout work. */
399397
list_for_each_entry_safe(data, n, &adap->wait_queue, list) {
400398
if (cancel_delayed_work(&data->work))
401-
cec_data_cancel(data);
399+
cec_data_cancel(data, CEC_TX_STATUS_OK);
402400
/*
403401
* If cancel_delayed_work returned false, then
404402
* the cec_wait_timeout function is running,
@@ -474,12 +472,13 @@ int cec_thread_func(void *_adap)
474472
* so much traffic on the bus that the adapter was
475473
* unable to transmit for CEC_XFER_TIMEOUT_MS (2.1s).
476474
*/
477-
dprintk(1, "%s: message %*ph timed out\n", __func__,
475+
pr_warn("cec-%s: message %*ph timed out\n", adap->name,
478476
adap->transmitting->msg.len,
479477
adap->transmitting->msg.msg);
480478
adap->tx_timeouts++;
481479
/* Just give up on this. */
482-
cec_data_cancel(adap->transmitting);
480+
cec_data_cancel(adap->transmitting,
481+
CEC_TX_STATUS_TIMEOUT);
483482
goto unlock;
484483
}
485484

@@ -530,7 +529,7 @@ int cec_thread_func(void *_adap)
530529
/* Tell the adapter to transmit, cancel on error */
531530
if (adap->ops->adap_transmit(adap, data->attempts,
532531
signal_free_time, &data->msg))
533-
cec_data_cancel(data);
532+
cec_data_cancel(data, CEC_TX_STATUS_ABORTED);
534533

535534
unlock:
536535
mutex_unlock(&adap->lock);
@@ -702,8 +701,6 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg,
702701
{
703702
struct cec_data *data;
704703
u8 last_initiator = 0xff;
705-
unsigned int timeout;
706-
int res = 0;
707704

708705
msg->rx_ts = 0;
709706
msg->tx_ts = 0;
@@ -845,48 +842,21 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg,
845842
if (!block)
846843
return 0;
847844

848-
/*
849-
* If we don't get a completion before this time something is really
850-
* wrong and we time out.
851-
*/
852-
timeout = CEC_XFER_TIMEOUT_MS;
853-
/* Add the requested timeout if we have to wait for a reply as well */
854-
if (msg->timeout)
855-
timeout += msg->timeout;
856-
857845
/*
858846
* Release the lock and wait, retake the lock afterwards.
859847
*/
860848
mutex_unlock(&adap->lock);
861-
res = wait_for_completion_killable_timeout(&data->c,
862-
msecs_to_jiffies(timeout));
849+
wait_for_completion_killable(&data->c);
863850
mutex_lock(&adap->lock);
864851

865-
if (data->completed) {
866-
/* The transmit completed (possibly with an error) */
867-
*msg = data->msg;
868-
kfree(data);
869-
return 0;
870-
}
871-
/*
872-
* The wait for completion timed out or was interrupted, so mark this
873-
* as non-blocking and disconnect from the filehandle since it is
874-
* still 'in flight'. When it finally completes it will just drop the
875-
* result silently.
876-
*/
877-
data->blocking = false;
878-
if (data->fh)
879-
list_del(&data->xfer_list);
880-
data->fh = NULL;
852+
/* Cancel the transmit if it was interrupted */
853+
if (!data->completed)
854+
cec_data_cancel(data, CEC_TX_STATUS_ABORTED);
881855

882-
if (res == 0) { /* timed out */
883-
/* Check if the reply or the transmit failed */
884-
if (msg->timeout && (msg->tx_status & CEC_TX_STATUS_OK))
885-
msg->rx_status = CEC_RX_STATUS_TIMEOUT;
886-
else
887-
msg->tx_status = CEC_TX_STATUS_MAX_RETRIES;
888-
}
889-
return res > 0 ? 0 : res;
856+
/* The transmit completed (possibly with an error) */
857+
*msg = data->msg;
858+
kfree(data);
859+
return 0;
890860
}
891861

892862
/* Helper function to be used by drivers and this framework. */

‎include/uapi/linux/cec.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ static inline void cec_msg_set_reply_to(struct cec_msg *msg,
152152
#define CEC_TX_STATUS_LOW_DRIVE (1 << 3)
153153
#define CEC_TX_STATUS_ERROR (1 << 4)
154154
#define CEC_TX_STATUS_MAX_RETRIES (1 << 5)
155+
#define CEC_TX_STATUS_ABORTED (1 << 6)
156+
#define CEC_TX_STATUS_TIMEOUT (1 << 7)
155157

156158
#define CEC_RX_STATUS_OK (1 << 0)
157159
#define CEC_RX_STATUS_TIMEOUT (1 << 1)
158160
#define CEC_RX_STATUS_FEATURE_ABORT (1 << 2)
161+
#define CEC_RX_STATUS_ABORTED (1 << 3)
159162

160163
static inline int cec_msg_status_is_ok(const struct cec_msg *msg)
161164
{

0 commit comments

Comments
 (0)