gpio-fault-injection 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. Linux I2C fault injection
  2. =========================
  3. The GPIO based I2C bus master driver can be configured to provide fault
  4. injection capabilities. It is then meant to be connected to another I2C bus
  5. which is driven by the I2C bus master driver under test. The GPIO fault
  6. injection driver can create special states on the bus which the other I2C bus
  7. master driver should handle gracefully.
  8. Once the Kconfig option I2C_GPIO_FAULT_INJECTOR is enabled, there will be an
  9. 'i2c-fault-injector' subdirectory in the Kernel debugfs filesystem, usually
  10. mounted at /sys/kernel/debug. There will be a separate subdirectory per GPIO
  11. driven I2C bus. Each subdirectory will contain files to trigger the fault
  12. injection. They will be described now along with their intended use-cases.
  13. "scl"
  14. -----
  15. By reading this file, you get the current state of SCL. By writing, you can
  16. change its state to either force it low or to release it again. So, by using
  17. "echo 0 > scl" you force SCL low and thus, no communication will be possible
  18. because the bus master under test will not be able to clock. It should detect
  19. the condition of SCL being unresponsive and report an error to the upper
  20. layers.
  21. "sda"
  22. -----
  23. By reading this file, you get the current state of SDA. By writing, you can
  24. change its state to either force it low or to release it again. So, by using
  25. "echo 0 > sda" you force SDA low and thus, data cannot be transmitted. The bus
  26. master under test should detect this condition and trigger a bus recovery (see
  27. I2C specification version 4, section 3.1.16) using the helpers of the Linux I2C
  28. core (see 'struct bus_recovery_info'). However, the bus recovery will not
  29. succeed because SDA is still pinned low until you manually release it again
  30. with "echo 1 > sda". A test with an automatic release can be done with the
  31. following class of fault injectors.
  32. Introduction to incomplete transfers
  33. ------------------------------------
  34. The following fault injectors create situations where SDA will be held low by a
  35. device. Bus recovery should be able to fix these situations. But please note:
  36. there are I2C client devices which detect a stuck SDA on their side and release
  37. it on their own after a few milliseconds. Also, there might be an external
  38. device deglitching and monitoring the I2C bus. It could also detect a stuck SDA
  39. and will init a bus recovery on its own. If you want to implement bus recovery
  40. in a bus master driver, make sure you checked your hardware setup for such
  41. devices before. And always verify with a scope or logic analyzer!
  42. "incomplete_address_phase"
  43. --------------------------
  44. This file is write only and you need to write the address of an existing I2C
  45. client device to it. Then, a read transfer to this device will be started, but
  46. it will stop at the ACK phase after the address of the client has been
  47. transmitted. Because the device will ACK its presence, this results in SDA
  48. being pulled low by the device while SCL is high. So, similar to the "sda" file
  49. above, the bus master under test should detect this condition and try a bus
  50. recovery. This time, however, it should succeed and the device should release
  51. SDA after toggling SCL.
  52. "incomplete_write_byte"
  53. -----------------------
  54. Similar to above, this file is write only and you need to write the address of
  55. an existing I2C client device to it.
  56. The injector will again stop at one ACK phase, so the device will keep SDA low
  57. because it acknowledges data. However, there are two differences compared to
  58. 'incomplete_address_phase':
  59. a) the message sent out will be a write message
  60. b) after the address byte, a 0x00 byte will be transferred. Then, stop at ACK.
  61. This is a highly delicate state, the device is set up to write any data to
  62. register 0x00 (if it has registers) when further clock pulses happen on SCL.
  63. This is why bus recovery (up to 9 clock pulses) must either check SDA or send
  64. additional STOP conditions to ensure the bus has been released. Otherwise
  65. random data will be written to a device!