cec-pin-error-inj.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. _cec_pin_error_inj:
  3. CEC Pin Framework Error Injection
  4. =================================
  5. The CEC Pin Framework is a core CEC framework for CEC hardware that only
  6. has low-level support for the CEC bus. Most hardware today will have
  7. high-level CEC support where the hardware deals with driving the CEC bus,
  8. but some older devices aren't that fancy. However, this framework also
  9. allows you to connect the CEC pin to a GPIO on e.g. a Raspberry Pi and
  10. you have now made a CEC adapter.
  11. What makes doing this so interesting is that since we have full control
  12. over the bus it is easy to support error injection. This is ideal to
  13. test how well CEC adapters can handle error conditions.
  14. Currently only the cec-gpio driver (when the CEC line is directly
  15. connected to a pull-up GPIO line) and the AllWinner A10/A20 drm driver
  16. support this framework.
  17. If ``CONFIG_CEC_PIN_ERROR_INJ`` is enabled, then error injection is available
  18. through debugfs. Specifically, in ``/sys/kernel/debug/cec/cecX/`` there is
  19. now an ``error-inj`` file.
  20. .. note::
  21. The error injection commands are not a stable ABI and may change in the
  22. future.
  23. With ``cat error-inj`` you can see both the possible commands and the current
  24. error injection status::
  25. $ cat /sys/kernel/debug/cec/cec0/error-inj
  26. # Clear error injections:
  27. # clear clear all rx and tx error injections
  28. # rx-clear clear all rx error injections
  29. # tx-clear clear all tx error injections
  30. # <op> clear clear all rx and tx error injections for <op>
  31. # <op> rx-clear clear all rx error injections for <op>
  32. # <op> tx-clear clear all tx error injections for <op>
  33. #
  34. # RX error injection settings:
  35. # rx-no-low-drive do not generate low-drive pulses
  36. #
  37. # RX error injection:
  38. # <op>[,<mode>] rx-nack NACK the message instead of sending an ACK
  39. # <op>[,<mode>] rx-low-drive <bit> force a low-drive condition at this bit position
  40. # <op>[,<mode>] rx-add-byte add a spurious byte to the received CEC message
  41. # <op>[,<mode>] rx-remove-byte remove the last byte from the received CEC message
  42. # any[,<mode>] rx-arb-lost [<poll>] generate a POLL message to trigger an arbitration lost
  43. #
  44. # TX error injection settings:
  45. # tx-ignore-nack-until-eom ignore early NACKs until EOM
  46. # tx-custom-low-usecs <usecs> define the 'low' time for the custom pulse
  47. # tx-custom-high-usecs <usecs> define the 'high' time for the custom pulse
  48. # tx-custom-pulse transmit the custom pulse once the bus is idle
  49. # tx-glitch-low-usecs <usecs> define the 'low' time for the glitch pulse
  50. # tx-glitch-high-usecs <usecs> define the 'high' time for the glitch pulse
  51. # tx-glitch-falling-edge send the glitch pulse after every falling edge
  52. # tx-glitch-rising-edge send the glitch pulse after every rising edge
  53. #
  54. # TX error injection:
  55. # <op>[,<mode>] tx-no-eom don't set the EOM bit
  56. # <op>[,<mode>] tx-early-eom set the EOM bit one byte too soon
  57. # <op>[,<mode>] tx-add-bytes <num> append <num> (1-255) spurious bytes to the message
  58. # <op>[,<mode>] tx-remove-byte drop the last byte from the message
  59. # <op>[,<mode>] tx-short-bit <bit> make this bit shorter than allowed
  60. # <op>[,<mode>] tx-long-bit <bit> make this bit longer than allowed
  61. # <op>[,<mode>] tx-custom-bit <bit> send the custom pulse instead of this bit
  62. # <op>[,<mode>] tx-short-start send a start pulse that's too short
  63. # <op>[,<mode>] tx-long-start send a start pulse that's too long
  64. # <op>[,<mode>] tx-custom-start send the custom pulse instead of the start pulse
  65. # <op>[,<mode>] tx-last-bit <bit> stop sending after this bit
  66. # <op>[,<mode>] tx-low-drive <bit> force a low-drive condition at this bit position
  67. #
  68. # <op> CEC message opcode (0-255) or 'any'
  69. # <mode> 'once' (default), 'always', 'toggle' or 'off'
  70. # <bit> CEC message bit (0-159)
  71. # 10 bits per 'byte': bits 0-7: data, bit 8: EOM, bit 9: ACK
  72. # <poll> CEC poll message used to test arbitration lost (0x00-0xff, default 0x0f)
  73. # <usecs> microseconds (0-10000000, default 1000)
  74. clear
  75. You can write error injection commands to ``error-inj`` using
  76. ``echo 'cmd' >error-inj`` or ``cat cmd.txt >error-inj``. The ``cat error-inj``
  77. output contains the current error commands. You can save the output to a file
  78. and use it as an input to ``error-inj`` later.
  79. Basic Syntax
  80. ------------
  81. Leading spaces/tabs are ignored. If the next character is a ``#`` or the end
  82. of the line was reached, then the whole line is ignored. Otherwise a command
  83. is expected.
  84. The error injection commands fall in two main groups: those relating to
  85. receiving CEC messages and those relating to transmitting CEC messages. In
  86. addition, there are commands to clear existing error injection commands and
  87. to create custom pulses on the CEC bus.
  88. Most error injection commands can be executed for specific CEC opcodes or for
  89. all opcodes (``any``). Each command also has a 'mode' which can be ``off``
  90. (can be used to turn off an existing error injection command), ``once``
  91. (the default) which will trigger the error injection only once for the next
  92. received or transmitted message, ``always`` to always trigger the error
  93. injection and ``toggle`` to toggle the error injection on or off for every
  94. transmit or receive.
  95. So '``any rx-nack``' will NACK the next received CEC message,
  96. '``any,always rx-nack``' will NACK all received CEC messages and
  97. '``0x82,toggle rx-nack``' will only NACK if an Active Source message was
  98. received and do that only for every other received message.
  99. After an error was injected with mode ``once`` the error injection command
  100. is cleared automatically, so ``once`` is a one-time deal.
  101. All combinations of ``<op>`` and error injection commands can co-exist. So
  102. this is fine::
  103. 0x9e tx-add-bytes 1
  104. 0x9e tx-early-eom
  105. 0x9f tx-add-bytes 2
  106. any rx-nack
  107. All four error injection commands will be active simultaneously.
  108. However, if the same ``<op>`` and command combination is specified,
  109. but with different arguments::
  110. 0x9e tx-add-bytes 1
  111. 0x9e tx-add-bytes 2
  112. Then the second will overwrite the first.
  113. Clear Error Injections
  114. ----------------------
  115. ``clear``
  116. Clear all error injections.
  117. ``rx-clear``
  118. Clear all receive error injections
  119. ``tx-clear``
  120. Clear all transmit error injections
  121. ``<op> clear``
  122. Clear all error injections for the given opcode.
  123. ``<op> rx-clear``
  124. Clear all receive error injections for the given opcode.
  125. ``<op> tx-clear``
  126. Clear all transmit error injections for the given opcode.
  127. Receive Messages
  128. ----------------
  129. ``<op>[,<mode>] rx-nack``
  130. NACK broadcast messages and messages directed to this CEC adapter.
  131. Every byte of the message will be NACKed in case the transmitter
  132. keeps transmitting after the first byte was NACKed.
  133. ``<op>[,<mode>] rx-low-drive <bit>``
  134. Force a Low Drive condition at this bit position. If <op> specifies
  135. a specific CEC opcode then the bit position must be at least 18,
  136. otherwise the opcode hasn't been received yet. This tests if the
  137. transmitter can handle the Low Drive condition correctly and reports
  138. the error correctly. Note that a Low Drive in the first 4 bits can also
  139. be interpreted as an Arbitration Lost condition by the transmitter.
  140. This is implementation dependent.
  141. ``<op>[,<mode>] rx-add-byte``
  142. Add a spurious 0x55 byte to the received CEC message, provided
  143. the message was 15 bytes long or less. This is useful to test
  144. the high-level protocol since spurious bytes should be ignored.
  145. ``<op>[,<mode>] rx-remove-byte``
  146. Remove the last byte from the received CEC message, provided it
  147. was at least 2 bytes long. This is useful to test the high-level
  148. protocol since messages that are too short should be ignored.
  149. ``<op>[,<mode>] rx-arb-lost <poll>``
  150. Generate a POLL message to trigger an Arbitration Lost condition.
  151. This command is only allowed for ``<op>`` values of ``next`` or ``all``.
  152. As soon as a start bit has been received the CEC adapter will switch
  153. to transmit mode and it will transmit a POLL message. By default this is
  154. 0x0f, but it can also be specified explicitly via the ``<poll>`` argument.
  155. This command can be used to test the Arbitration Lost condition in
  156. the remote CEC transmitter. Arbitration happens when two CEC adapters
  157. start sending a message at the same time. In that case the initiator
  158. with the most leading zeroes wins and the other transmitter has to
  159. stop transmitting ('Arbitration Lost'). This is very hard to test,
  160. except by using this error injection command.
  161. This does not work if the remote CEC transmitter has logical address
  162. 0 ('TV') since that will always win.
  163. ``rx-no-low-drive``
  164. The receiver will ignore situations that would normally generate a
  165. Low Drive pulse (3.6 ms). This is typically done if a spurious pulse is
  166. detected when receiving a message, and it indicates to the transmitter that
  167. the message has to be retransmitted since the receiver got confused.
  168. Disabling this is useful to test how other CEC devices handle glitches
  169. by ensuring we will not be the one that generates a Low Drive.
  170. Transmit Messages
  171. -----------------
  172. ``tx-ignore-nack-until-eom``
  173. This setting changes the behavior of transmitting CEC messages. Normally
  174. as soon as the receiver NACKs a byte the transmit will stop, but the
  175. specification also allows that the full message is transmitted and only
  176. at the end will the transmitter look at the ACK bit. This is not
  177. recommended behavior since there is no point in keeping the CEC bus busy
  178. for longer than is strictly needed. Especially given how slow the bus is.
  179. This setting can be used to test how well a receiver deals with
  180. transmitters that ignore NACKs until the very end of the message.
  181. ``<op>[,<mode>] tx-no-eom``
  182. Don't set the EOM bit. Normally the last byte of the message has the EOM
  183. (End-Of-Message) bit set. With this command the transmit will just stop
  184. without ever sending an EOM. This can be used to test how a receiver
  185. handles this case. Normally receivers have a time-out after which
  186. they will go back to the Idle state.
  187. ``<op>[,<mode>] tx-early-eom``
  188. Set the EOM bit one byte too soon. This obviously only works for messages
  189. of two bytes or more. The EOM bit will be set for the second-to-last byte
  190. and not for the final byte. The receiver should ignore the last byte in
  191. this case. Since the resulting message is likely to be too short for this
  192. same reason the whole message is typically ignored. The receiver should be
  193. in Idle state after the last byte was transmitted.
  194. ``<op>[,<mode>] tx-add-bytes <num>``
  195. Append ``<num>`` (1-255) spurious bytes to the message. The extra bytes
  196. have the value of the byte position in the message. So if you transmit a
  197. two byte message (e.g. a Get CEC Version message) and add 2 bytes, then
  198. the full message received by the remote CEC adapter is
  199. ``0x40 0x9f 0x02 0x03``.
  200. This command can be used to test buffer overflows in the receiver. E.g.
  201. what does it do when it receives more than the maximum message size of 16
  202. bytes.
  203. ``<op>[,<mode>] tx-remove-byte``
  204. Drop the last byte from the message, provided the message is at least
  205. two bytes long. The receiver should ignore messages that are too short.
  206. ``<op>[,<mode>] tx-short-bit <bit>``
  207. Make this bit period shorter than allowed. The bit position cannot be
  208. an Ack bit. If <op> specifies a specific CEC opcode then the bit position
  209. must be at least 18, otherwise the opcode hasn't been received yet.
  210. Normally the period of a data bit is between 2.05 and 2.75 milliseconds.
  211. With this command the period of this bit is 1.8 milliseconds, this is
  212. done by reducing the time the CEC bus is high. This bit period is less
  213. than is allowed and the receiver should respond with a Low Drive
  214. condition.
  215. This command is ignored for 0 bits in bit positions 0 to 3. This is
  216. because the receiver also looks for an Arbitration Lost condition in
  217. those first four bits and it is undefined what will happen if it
  218. sees a too-short 0 bit.
  219. ``<op>[,<mode>] tx-long-bit <bit>``
  220. Make this bit period longer than is valid. The bit position cannot be
  221. an Ack bit. If <op> specifies a specific CEC opcode then the bit position
  222. must be at least 18, otherwise the opcode hasn't been received yet.
  223. Normally the period of a data bit is between 2.05 and 2.75 milliseconds.
  224. With this command the period of this bit is 2.9 milliseconds, this is
  225. done by increasing the time the CEC bus is high.
  226. Even though this bit period is longer than is valid it is undefined what
  227. a receiver will do. It might just accept it, or it might time out and
  228. return to Idle state. Unfortunately the CEC specification is silent about
  229. this.
  230. This command is ignored for 0 bits in bit positions 0 to 3. This is
  231. because the receiver also looks for an Arbitration Lost condition in
  232. those first four bits and it is undefined what will happen if it
  233. sees a too-long 0 bit.
  234. ``<op>[,<mode>] tx-short-start``
  235. Make this start bit period shorter than allowed. Normally the period of
  236. a start bit is between 4.3 and 4.7 milliseconds. With this command the
  237. period of the start bit is 4.1 milliseconds, this is done by reducing
  238. the time the CEC bus is high. This start bit period is less than is
  239. allowed and the receiver should return to Idle state when this is detected.
  240. ``<op>[,<mode>] tx-long-start``
  241. Make this start bit period longer than is valid. Normally the period of
  242. a start bit is between 4.3 and 4.7 milliseconds. With this command the
  243. period of the start bit is 5 milliseconds, this is done by increasing
  244. the time the CEC bus is high. This start bit period is more than is
  245. valid and the receiver should return to Idle state when this is detected.
  246. Even though this start bit period is longer than is valid it is undefined
  247. what a receiver will do. It might just accept it, or it might time out and
  248. return to Idle state. Unfortunately the CEC specification is silent about
  249. this.
  250. ``<op>[,<mode>] tx-last-bit <bit>``
  251. Just stop transmitting after this bit. If <op> specifies a specific CEC
  252. opcode then the bit position must be at least 18, otherwise the opcode
  253. hasn't been received yet. This command can be used to test how the receiver
  254. reacts when a message just suddenly stops. It should time out and go back
  255. to Idle state.
  256. ``<op>[,<mode>] tx-low-drive <bit>``
  257. Force a Low Drive condition at this bit position. If <op> specifies a
  258. specific CEC opcode then the bit position must be at least 18, otherwise
  259. the opcode hasn't been received yet. This can be used to test how the
  260. receiver handles Low Drive conditions. Note that if this happens at bit
  261. positions 0-3 the receiver can interpret this as an Arbitration Lost
  262. condition. This is implementation dependent.
  263. Custom Pulses
  264. -------------
  265. ``tx-custom-low-usecs <usecs>``
  266. This defines the duration in microseconds that the custom pulse pulls
  267. the CEC line low. The default is 1000 microseconds.
  268. ``tx-custom-high-usecs <usecs>``
  269. This defines the duration in microseconds that the custom pulse keeps the
  270. CEC line high (unless another CEC adapter pulls it low in that time).
  271. The default is 1000 microseconds. The total period of the custom pulse is
  272. ``tx-custom-low-usecs + tx-custom-high-usecs``.
  273. ``<op>[,<mode>] tx-custom-bit <bit>``
  274. Send the custom bit instead of a regular data bit. The bit position cannot
  275. be an Ack bit. If <op> specifies a specific CEC opcode then the bit
  276. position must be at least 18, otherwise the opcode hasn't been received yet.
  277. ``<op>[,<mode>] tx-custom-start``
  278. Send the custom bit instead of a regular start bit.
  279. ``tx-custom-pulse``
  280. Transmit a single custom pulse as soon as the CEC bus is idle.
  281. Glitch Pulses
  282. -------------
  283. This emulates what happens if the signal on the CEC line is seeing spurious
  284. pulses. Typically this happens after the falling or rising edge where there
  285. is a short voltage fluctuation that, if the CEC hardware doesn't do
  286. deglitching, can be seen as a spurious pulse and can cause a Low Drive
  287. condition or corrupt data.
  288. ``tx-glitch-low-usecs <usecs>``
  289. This defines the duration in microseconds that the glitch pulse pulls
  290. the CEC line low. The default is 1 microsecond. The range is 0-100
  291. microseconds. If 0, then no glitch pulse will be generated.
  292. ``tx-glitch-high-usecs <usecs>``
  293. This defines the duration in microseconds that the glitch pulse keeps the
  294. CEC line high (unless another CEC adapter pulls it low in that time).
  295. The default is 1 microseconds. The range is 0-100 microseconds. If 0, then
  296. no glitch pulse will be generated.The total period of the glitch pulse is
  297. ``tx-custom-low-usecs + tx-custom-high-usecs``.
  298. ``tx-glitch-falling-edge``
  299. Send the glitch pulse right after the falling edge.
  300. ``tx-glitch-rising-edge``
  301. Send the glitch pulse right after the rising edge.