|
Packit |
7b02f3 |
Linux I2C fault injection
|
|
Packit |
7b02f3 |
=========================
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
The GPIO based I2C bus master driver can be configured to provide fault
|
|
Packit |
7b02f3 |
injection capabilities. It is then meant to be connected to another I2C bus
|
|
Packit |
7b02f3 |
which is driven by the I2C bus master driver under test. The GPIO fault
|
|
Packit |
7b02f3 |
injection driver can create special states on the bus which the other I2C bus
|
|
Packit |
7b02f3 |
master driver should handle gracefully.
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
Once the Kconfig option I2C_GPIO_FAULT_INJECTOR is enabled, there will be an
|
|
Packit |
7b02f3 |
'i2c-fault-injector' subdirectory in the Kernel debugfs filesystem, usually
|
|
Packit |
7b02f3 |
mounted at /sys/kernel/debug. There will be a separate subdirectory per GPIO
|
|
Packit |
7b02f3 |
driven I2C bus. Each subdirectory will contain files to trigger the fault
|
|
Packit |
7b02f3 |
injection. They will be described now along with their intended use-cases.
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
"scl"
|
|
Packit |
7b02f3 |
-----
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
By reading this file, you get the current state of SCL. By writing, you can
|
|
Packit |
7b02f3 |
change its state to either force it low or to release it again. So, by using
|
|
Packit |
7b02f3 |
"echo 0 > scl" you force SCL low and thus, no communication will be possible
|
|
Packit |
7b02f3 |
because the bus master under test will not be able to clock. It should detect
|
|
Packit |
7b02f3 |
the condition of SCL being unresponsive and report an error to the upper
|
|
Packit |
7b02f3 |
layers.
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
"sda"
|
|
Packit |
7b02f3 |
-----
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
By reading this file, you get the current state of SDA. By writing, you can
|
|
Packit |
7b02f3 |
change its state to either force it low or to release it again. So, by using
|
|
Packit |
7b02f3 |
"echo 0 > sda" you force SDA low and thus, data cannot be transmitted. The bus
|
|
Packit |
7b02f3 |
master under test should detect this condition and trigger a bus recovery (see
|
|
Packit |
7b02f3 |
I2C specification version 4, section 3.1.16) using the helpers of the Linux I2C
|
|
Packit |
7b02f3 |
core (see 'struct bus_recovery_info'). However, the bus recovery will not
|
|
Packit |
7b02f3 |
succeed because SDA is still pinned low until you manually release it again
|
|
Packit |
7b02f3 |
with "echo 1 > sda". A test with an automatic release can be done with the
|
|
Packit |
7b02f3 |
'incomplete_transfer' file.
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
"incomplete_transfer"
|
|
Packit |
7b02f3 |
---------------------
|
|
Packit |
7b02f3 |
|
|
Packit |
7b02f3 |
This file is write only and you need to write the address of an existing I2C
|
|
Packit |
7b02f3 |
client device to it. Then, a transfer to this device will be started, but it
|
|
Packit |
7b02f3 |
will stop at the ACK phase after the address of the client has been
|
|
Packit |
7b02f3 |
transmitted. Because the device will ACK its presence, this results in SDA
|
|
Packit |
7b02f3 |
being pulled low by the device while SCL is high. So, similar to the "sda" file
|
|
Packit |
7b02f3 |
above, the bus master under test should detect this condition and try a bus
|
|
Packit |
7b02f3 |
recovery. This time, however, it should succeed and the device should release
|
|
Packit |
7b02f3 |
SDA after toggling SCL. Please note: there are I2C client devices which detect
|
|
Packit |
7b02f3 |
a stuck SDA on their side and release it on their own after a few milliseconds.
|
|
Packit |
7b02f3 |
Also, there are external devices deglitching and monitoring the I2C bus. They
|
|
Packit |
7b02f3 |
can also detect a stuck SDA and will init a bus recovery on their own. If you
|
|
Packit |
7b02f3 |
want to implement bus recovery in a bus master driver, make sure you checked
|
|
Packit |
7b02f3 |
your hardware setup carefully before.
|