Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mattst88...
[sfrench/cifs-2.6.git] / Documentation / media / uapi / cec / cec-ioc-receive.rst
1 .. Permission is granted to copy, distribute and/or modify this
2 .. document under the terms of the GNU Free Documentation License,
3 .. Version 1.1 or any later version published by the Free Software
4 .. Foundation, with no Invariant Sections, no Front-Cover Texts
5 .. and no Back-Cover Texts. A copy of the license is included at
6 .. Documentation/media/uapi/fdl-appendix.rst.
7 ..
8 .. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9
10 .. _CEC_TRANSMIT:
11 .. _CEC_RECEIVE:
12
13 ***********************************
14 ioctls CEC_RECEIVE and CEC_TRANSMIT
15 ***********************************
16
17 Name
18 ====
19
20 CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
21
22
23 Synopsis
24 ========
25
26 .. c:function:: int ioctl( int fd, CEC_RECEIVE, struct cec_msg \*argp )
27     :name: CEC_RECEIVE
28
29 .. c:function:: int ioctl( int fd, CEC_TRANSMIT, struct cec_msg \*argp )
30     :name: CEC_TRANSMIT
31
32 Arguments
33 =========
34
35 ``fd``
36     File descriptor returned by :c:func:`open() <cec-open>`.
37
38 ``argp``
39     Pointer to struct cec_msg.
40
41 Description
42 ===========
43
44 To receive a CEC message the application has to fill in the
45 ``timeout`` field of struct :c:type:`cec_msg` and pass it to
46 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
47 If the file descriptor is in non-blocking mode and there are no received
48 messages pending, then it will return -1 and set errno to the ``EAGAIN``
49 error code. If the file descriptor is in blocking mode and ``timeout``
50 is non-zero and no message arrived within ``timeout`` milliseconds, then
51 it will return -1 and set errno to the ``ETIMEDOUT`` error code.
52
53 A received message can be:
54
55 1. a message received from another CEC device (the ``sequence`` field will
56    be 0).
57 2. the result of an earlier non-blocking transmit (the ``sequence`` field will
58    be non-zero).
59
60 To send a CEC message the application has to fill in the struct
61 :c:type:`cec_msg` and pass it to :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
62 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
63 ``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
64 queue, then it will return -1 and set errno to the ``EBUSY`` error code.
65 The transmit queue has enough room for 18 messages (about 1 second worth
66 of 2-byte messages). Note that the CEC kernel framework will also reply
67 to core messages (see :ref:`cec-core-processing`), so it is not a good
68 idea to fully fill up the transmit queue.
69
70 If the file descriptor is in non-blocking mode then the transmit will
71 return 0 and the result of the transmit will be available via
72 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished
73 (including waiting for a reply, if requested).
74
75 The ``sequence`` field is filled in for every transmit and this can be
76 checked against the received messages to find the corresponding transmit
77 result.
78
79 Normally calling :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` when the physical
80 address is invalid (due to e.g. a disconnect) will return ``ENONET``.
81
82 However, the CEC specification allows sending messages from 'Unregistered' to
83 'TV' when the physical address is invalid since some TVs pull the hotplug detect
84 pin of the HDMI connector low when they go into standby, or when switching to
85 another input.
86
87 When the hotplug detect pin goes low the EDID disappears, and thus the
88 physical address, but the cable is still connected and CEC still works.
89 In order to detect/wake up the device it is allowed to send poll and 'Image/Text
90 View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
91
92 .. tabularcolumns:: |p{1.0cm}|p{3.5cm}|p{13.0cm}|
93
94 .. c:type:: cec_msg
95
96 .. cssclass:: longtable
97
98 .. flat-table:: struct cec_msg
99     :header-rows:  0
100     :stub-columns: 0
101     :widths:       1 1 16
102
103     * - __u64
104       - ``tx_ts``
105       - Timestamp in ns of when the last byte of the message was transmitted.
106         The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
107         the same clock from userspace use :c:func:`clock_gettime`.
108     * - __u64
109       - ``rx_ts``
110       - Timestamp in ns of when the last byte of the message was received.
111         The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
112         the same clock from userspace use :c:func:`clock_gettime`.
113     * - __u32
114       - ``len``
115       - The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
116         by the application. The driver will fill this in for
117         :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
118         filled in by the driver with the length of the reply message if ``reply`` was set.
119     * - __u32
120       - ``timeout``
121       - The timeout in milliseconds. This is the time the device will wait
122         for a message to be received before timing out. If it is set to 0,
123         then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
124         If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
125         then it will be replaced by 1000 if the ``reply`` is non-zero or
126         ignored if ``reply`` is 0.
127     * - __u32
128       - ``sequence``
129       - A non-zero sequence number is automatically assigned by the CEC framework
130         for all transmitted messages. It is used by the CEC framework when it queues
131         the transmit result (when transmit was called in non-blocking mode). This
132         allows the application to associate the received message with the original
133         transmit.
134     * - __u32
135       - ``flags``
136       - Flags. See :ref:`cec-msg-flags` for a list of available flags.
137     * - __u8
138       - ``tx_status``
139       - The status bits of the transmitted message. See
140         :ref:`cec-tx-status` for the possible status values. It is 0 if
141         this message was received, not transmitted.
142     * - __u8
143       - ``msg[16]``
144       - The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
145         application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
146         For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
147         the payload of the reply message if ``timeout`` was set.
148     * - __u8
149       - ``reply``
150       - Wait until this message is replied. If ``reply`` is 0 and the
151         ``timeout`` is 0, then don't wait for a reply but return after
152         transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
153         The case where ``reply`` is 0 (this is the opcode for the Feature Abort
154         message) and ``timeout`` is non-zero is specifically allowed to make it
155         possible to send a message and wait up to ``timeout`` milliseconds for a
156         Feature Abort reply. In this case ``rx_status`` will either be set
157         to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
158         :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.
159
160         If the transmitter message is ``CEC_MSG_INITIATE_ARC`` then the ``reply``
161         values ``CEC_MSG_REPORT_ARC_INITIATED`` and ``CEC_MSG_REPORT_ARC_TERMINATED``
162         are processed differently: either value will match both possible replies.
163         The reason is that the ``CEC_MSG_INITIATE_ARC`` message is the only CEC
164         message that has two possible replies other than Feature Abort. The
165         ``reply`` field will be updated with the actual reply so that it is
166         synchronized with the contents of the received message.
167     * - __u8
168       - ``rx_status``
169       - The status bits of the received message. See
170         :ref:`cec-rx-status` for the possible status values. It is 0 if
171         this message was transmitted, not received, unless this is the
172         reply to a transmitted message. In that case both ``rx_status``
173         and ``tx_status`` are set.
174     * - __u8
175       - ``tx_status``
176       - The status bits of the transmitted message. See
177         :ref:`cec-tx-status` for the possible status values. It is 0 if
178         this message was received, not transmitted.
179     * - __u8
180       - ``tx_arb_lost_cnt``
181       - A counter of the number of transmit attempts that resulted in the
182         Arbitration Lost error. This is only set if the hardware supports
183         this, otherwise it is always 0. This counter is only valid if the
184         :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.
185     * - __u8
186       - ``tx_nack_cnt``
187       - A counter of the number of transmit attempts that resulted in the
188         Not Acknowledged error. This is only set if the hardware supports
189         this, otherwise it is always 0. This counter is only valid if the
190         :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.
191     * - __u8
192       - ``tx_low_drive_cnt``
193       - A counter of the number of transmit attempts that resulted in the
194         Arbitration Lost error. This is only set if the hardware supports
195         this, otherwise it is always 0. This counter is only valid if the
196         :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.
197     * - __u8
198       - ``tx_error_cnt``
199       - A counter of the number of transmit errors other than Arbitration
200         Lost or Not Acknowledged. This is only set if the hardware
201         supports this, otherwise it is always 0. This counter is only
202         valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.
203
204
205 .. tabularcolumns:: |p{6.2cm}|p{1.0cm}|p{10.3cm}|
206
207 .. _cec-msg-flags:
208
209 .. flat-table:: Flags for struct cec_msg
210     :header-rows:  0
211     :stub-columns: 0
212     :widths:       3 1 4
213
214     * .. _`CEC-MSG-FL-REPLY-TO-FOLLOWERS`:
215
216       - ``CEC_MSG_FL_REPLY_TO_FOLLOWERS``
217       - 1
218       - If a CEC transmit expects a reply, then by default that reply is only sent to
219         the filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If this
220         flag is set, then the reply is also sent to all followers, if any. If the
221         filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is also a
222         follower, then that filehandle will receive the reply twice: once as the
223         result of the :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`, and once via
224         :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
225
226
227 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
228
229 .. _cec-tx-status:
230
231 .. flat-table:: CEC Transmit Status
232     :header-rows:  0
233     :stub-columns: 0
234     :widths:       3 1 16
235
236     * .. _`CEC-TX-STATUS-OK`:
237
238       - ``CEC_TX_STATUS_OK``
239       - 0x01
240       - The message was transmitted successfully. This is mutually
241         exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`.
242         Other bits can still be set if earlier attempts met with failure before
243         the transmit was eventually successful.
244     * .. _`CEC-TX-STATUS-ARB-LOST`:
245
246       - ``CEC_TX_STATUS_ARB_LOST``
247       - 0x02
248       - CEC line arbitration was lost, i.e. another transmit started at the
249         same time with a higher priority. Optional status, not all hardware
250         can detect this error condition.
251     * .. _`CEC-TX-STATUS-NACK`:
252
253       - ``CEC_TX_STATUS_NACK``
254       - 0x04
255       - Message was not acknowledged. Note that some hardware cannot tell apart
256         a 'Not Acknowledged' status from other error conditions, i.e. the result
257         of a transmit is just OK or FAIL. In that case this status will be
258         returned when the transmit failed.
259     * .. _`CEC-TX-STATUS-LOW-DRIVE`:
260
261       - ``CEC_TX_STATUS_LOW_DRIVE``
262       - 0x08
263       - Low drive was detected on the CEC bus. This indicates that a
264         follower detected an error on the bus and requests a
265         retransmission. Optional status, not all hardware can detect this
266         error condition.
267     * .. _`CEC-TX-STATUS-ERROR`:
268
269       - ``CEC_TX_STATUS_ERROR``
270       - 0x10
271       - Some error occurred. This is used for any errors that do not fit
272         ``CEC_TX_STATUS_ARB_LOST`` or ``CEC_TX_STATUS_LOW_DRIVE``, either because
273         the hardware could not tell which error occurred, or because the hardware
274         tested for other conditions besides those two. Optional status.
275     * .. _`CEC-TX-STATUS-MAX-RETRIES`:
276
277       - ``CEC_TX_STATUS_MAX_RETRIES``
278       - 0x20
279       - The transmit failed after one or more retries. This status bit is
280         mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`.
281         Other bits can still be set to explain which failures were seen.
282     * .. _`CEC-TX-STATUS-ABORTED`:
283
284       - ``CEC_TX_STATUS_ABORTED``
285       - 0x40
286       - The transmit was aborted due to an HDMI disconnect, or the adapter
287         was unconfigured, or a transmit was interrupted, or the driver
288         returned an error when attempting to start a transmit.
289     * .. _`CEC-TX-STATUS-TIMEOUT`:
290
291       - ``CEC_TX_STATUS_TIMEOUT``
292       - 0x80
293       - The transmit timed out. This should not normally happen and this
294         indicates a driver problem.
295
296
297 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
298
299 .. _cec-rx-status:
300
301 .. flat-table:: CEC Receive Status
302     :header-rows:  0
303     :stub-columns: 0
304     :widths:       3 1 16
305
306     * .. _`CEC-RX-STATUS-OK`:
307
308       - ``CEC_RX_STATUS_OK``
309       - 0x01
310       - The message was received successfully.
311     * .. _`CEC-RX-STATUS-TIMEOUT`:
312
313       - ``CEC_RX_STATUS_TIMEOUT``
314       - 0x02
315       - The reply to an earlier transmitted message timed out.
316     * .. _`CEC-RX-STATUS-FEATURE-ABORT`:
317
318       - ``CEC_RX_STATUS_FEATURE_ABORT``
319       - 0x04
320       - The message was received successfully but the reply was
321         ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
322         was the reply to an earlier transmitted message.
323     * .. _`CEC-RX-STATUS-ABORTED`:
324
325       - ``CEC_RX_STATUS_ABORTED``
326       - 0x08
327       - The wait for a reply to an earlier transmitted message was aborted
328         because the HDMI cable was disconnected, the adapter was unconfigured
329         or the :ref:`CEC_TRANSMIT <CEC_RECEIVE>` that waited for a
330         reply was interrupted.
331
332
333
334 Return Value
335 ============
336
337 On success 0 is returned, on error -1 and the ``errno`` variable is set
338 appropriately. The generic error codes are described at the
339 :ref:`Generic Error Codes <gen-errors>` chapter.
340
341 The :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` can return the following
342 error codes:
343
344 EAGAIN
345     No messages are in the receive queue, and the filehandle is in non-blocking mode.
346
347 ETIMEDOUT
348     The ``timeout`` was reached while waiting for a message.
349
350 ERESTARTSYS
351     The wait for a message was interrupted (e.g. by Ctrl-C).
352
353 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` can return the following
354 error codes:
355
356 ENOTTY
357     The ``CEC_CAP_TRANSMIT`` capability wasn't set, so this ioctl is not supported.
358
359 EPERM
360     The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
361     has never been called.
362
363 ENONET
364     The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
365     was called, but the physical address is invalid so no logical address was claimed.
366     An exception is made in this case for transmits from initiator 0xf ('Unregistered')
367     to destination 0 ('TV'). In that case the transmit will proceed as usual.
368
369 EBUSY
370     Another filehandle is in exclusive follower or initiator mode, or the filehandle
371     is in mode ``CEC_MODE_NO_INITIATOR``. This is also returned if the transmit
372     queue is full.
373
374 EINVAL
375     The contents of struct :c:type:`cec_msg` is invalid.
376
377 ERESTARTSYS
378     The wait for a successful transmit was interrupted (e.g. by Ctrl-C).