summaryrefslogtreecommitdiffstats
path: root/sysfs.cpp
Commit message (Collapse)AuthorAgeFilesLines
* hwmonio: split IoAccess object outPatrick Venture2018-04-241-208/+1
| | | | | | | | Split out the hwmon io access object from the sysfs namespace into its own. Change-Id: I8d1a45630117d1d503d0d5fa6061163911b695e8 Signed-off-by: Patrick Venture <venture@google.com>
* Remove OCC EAGAIN workaroundMatthew Barth2018-04-131-8/+1
| | | | | | | | | | | | | | | | The ability to handle an EAGAIN for a sensor from the OCC device can be done by defining the EAGAIN return code(11) as a sensor removal return code within each OCC config file. This return code can be defined at the device level within the config file to be applied across all sensors the OCC provides. Tested: OCC sensors are removed from Dbus when EAGAIN is returned Resolves openbmc/openbmc#2327 Change-Id: If16ec37da6d960d54de1d47af3a39944249df772 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
* Add configure option for how read fails behavePatrick Venture2018-03-301-0/+4
| | | | | | | | | | | | | | | | Different platforms have different requirements for handling hwmon sysfs access failures. The default behavior is that a read failure leads to the daemon exiting after some number of read failures. This can be controlled to then remove the object from the dbus on failure. Now, it can instead be controlled to return -errno on read failure. This new behavior to set the value to -errno must be checked by whatever mechanism is reporting the value. Change-Id: I50b93aea56f22267da79c9571319f281e24a1e6f Signed-off-by: Patrick Venture <venture@google.com>
* Handle OCC EAGAIN & EREMOTEIO in 4.13Matthew Barth2018-03-221-1/+21
| | | | | | | | | | | | | | | | | | | This is a temporary fix until the following issues are completed: openbmc/openbmc#2327 openbmc/openbmc#2329 When an EAGAIN or an EREMOTEIO return code is received by hwmon from the OCC driver in the 4.13 kernel, they should be translated to an unavailable sensor(0x00) and failed sensor(0xFF) scaled values respectively. This will keep the OCC hwmon instance running and allow applications to continue using these sensors as they were reported under the mainline openbmc/linux 4.10 kernel. Tested: Verified return codes are caught and sensor value modified Change-Id: Ie61859863e7d88878caa942e5f5b062acabe67aa Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
* Add findHwmonFromDevPath()Matt Spinler2018-03-071-0/+38
| | | | | | | | | | | | | | | | | | This function can find the hwmon path from a /devices path. This path is similar to what udev lists as the device path, but with the /hwmon/hwmonN directories removed from the end. In addition, any ':' characters in the path have been converted to '--', so the code needs to convert them back. This is done because some devices are not in the device tree, and hence wouldn't have the open firmware device path that the code previously only supported. Tested: Tested with the new /devices path. Change-Id: Ic26646c6f609323cff86d4cd10bbe0a44d7d61ac Signed-off-by: Matt Spinler <spinler@us.ibm.com>
* Rename functionMatt Spinler2018-03-051-1/+1
| | | | | | | | | | | A future commit will add a new function to find the hwmon device from a different type of path, so clarify the current function name in preparation. Tested: Compiled Change-Id: I3c990f4a91b12e592e22818b085dcd3736e5fcde Signed-off-by: Matt Spinler <spinler@us.ibm.com>
* Clear errno before reading/writingMatt Spinler2018-01-171-0/+2
| | | | | | | | | | | | | | | | | Ensure the errno is cleared before accessing the sysfs file, so exceptions thrown without setting an errno can be recognized as such. Without this, the errno could still be set to a nonzero value from a previous operation, and the error handling code would think it happened on the current operation. The difference being if there is a nonzero errno a Read/WriteFailure error will be logged, and if zero the exception will be rethrown. Change-Id: Ia958376ca80484d4d594872ab8ab0154d1b767ca Signed-off-by: Matt Spinler <spinler@us.ibm.com>
* Silently exit on ENODEVEdward A. James2017-12-111-11/+3
| | | | | | | | | | | ENODEV should be included in the check for "disappeared" device or directory when hwmon driver is being unloaded. There is a race condition between unloading drivers and stopping hwmon polling, even up to several seconds, which exceeds the previous retry period for ENODEV. Change-Id: I39c8ae9ea79aa41028f5529c7ea9816d4736fc65 Signed-off-by: Edward A. James <eajames@us.ibm.com>
* Support reading 64 bit integersMatt Spinler2017-11-291-2/+2
| | | | | | | | | | | | | Some sysfs *_input values may be bigger than 32 bits, for example power values reported in microwatts. As such, read an int64_t value out of sysfs instead of just a uint32_t. The D-Bus property that will hold the value is also the same type, an int64_t. Resolves openbmc/openbmc#2686 Change-Id: I4376de120825b73580d18d339fe76be454eeb18d Signed-off-by: Matt Spinler <spinler@us.ibm.com>
* Retry on ENODATA errorsMatt Spinler2017-11-161-0/+8
| | | | | | | | | | | | | | | A particular device in a particular system is known to fail with an ENODATA errno when another entity is using the same path to access it. Add it to the retry list so that phosphor-hwmon will retry and hopefully be able to get a clean read. Even for devices where this contention isn't the case, the code may as well retry as opposed to trying once and giving up. Resolves openbmc/openbmc#2645 Change-Id: Ib7aaaa14be33a33794a8c62d6991f77ab65a2ffa Signed-off-by: Matt Spinler <spinler@us.ibm.com>
* Retry on ENODEV errnosMatt Spinler2017-10-091-0/+8
| | | | | | | | | | | | | | This errno can be returned by certain device drivers when they are in the process of being unbound. Retrying will give the driver time to finish unbinding, and phosphor-hwmon will then die off naturally as phosphor-hwmon's lifetime is tied to the loaded driver's. Resolves openbmc/openbmc#2401 Change-Id: Ife888f3b608d7694d22f95412a7d320377daefa4 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
* sysfs IO enhancementsBrad Bishop2017-09-081-42/+123
| | | | | | | | | | | | | | | | | | Add retries for some sysfs IO errors: EIO: Tolerate intermittant device or bus failures. ETIMEDOUT: Tolerate intermittant timeouts. EAGAIN: Tolerate drivers that do not block. ENXIO: Tolerate momentarily unplugged devices on busses that don't support hotplug. EBADMSG: Tolerate CRC errors. Flush stdio buffers after writes. Remove redundant retry and delay constants. Resolves: openbmc/openbmc#2262 Change-Id: I2104139bf7ced96bb10f7450b42ca36e61c84287 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* sysfs: Removed unused codeBrad Bishop2017-08-311-113/+0
| | | | | | | A number of methods have been deprecated. Remove. Change-Id: I87fa63724d67770719e93a85803fa37737d5cfad Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* Add hwmon io wrapper classBrad Bishop2017-08-311-0/+104
| | | | | | | | | | | | | Add a convenience class for doing hwmon attribute sysfs IO. A convenience class is warranted given some necessary workarounds for some GCC io exception bugs, and more importantly to remove the burden of the rest of the application checking for ENOENT in the case of a driver unbind event. Change-Id: I73d5a9aaaac1d5546109ae18854fe5db0b5acb26 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* sysfs: refactor findCalloutBrad Bishop2017-08-311-23/+73
| | | | | | | | | | | | | | - Export findCalloutPath so other modules can use it. - Change parameter to hwmon instance path to avoid fs::canonical outside sysfs.cpp. - Check for the iio-hwmon driver instead of relying on DT nodes having 'iio-hwmon' in them. - For iio devices, provide a /sys/devices path rather than a DT path. - Use existing application indenting and doxygen style. Change-Id: I16c2dc7417eb68f7cbef44243f481df8040ec1fd Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* sysfs: refactor findHwmonBrad Bishop2017-08-311-15/+23
| | | | | | | | - Invert branch logic to reduce indent levels. - Handle disappearing hwmon instances while searching. Change-Id: I20f93003bd3fa4f849341c4cf08a0f6a29bf785a Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* sysfs: refactor findPhandleMatchBrad Bishop2017-08-291-47/+42
| | | | | | | | | | | | | - Use same indenting style as the rest of the application. - Invert branch logic to reduce indent levels. - Move logic that does not depend on loop variants outside loop. - Fix a bug where the io-channels phandle is read from the wrong file. - Remove unnecessary try/catch block around DT IOs (DT is immutable). - Export findPhandle so other modules can use it. - Document current method limitations. Change-Id: I34c1c6731a5e2334075b2d25c6583143c2997207 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* sysfs: Removed unused headersBrad Bishop2017-08-281-2/+1
| | | | | | | Also put fstream in the right place. Change-Id: I3c199c49f6c4068f0483b923f51dc4750aa42596 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* Allow EAGAIN failuresMatt Spinler2017-07-281-1/+7
| | | | | | | | | | | | | | Certain devices are known to return EAGAIN failures when read too frequently, so be tolerant of them. On startup, the code will retry for up to a second to get a good first reading, and then in the main loop the code will just stick with the current value if it fails that way. Resolves openbmc/openbmc#2038 Change-Id: I7621aa30429c43276239982a03ec3eef02ce9c6e Signed-off-by: Matt Spinler <spinler@us.ibm.com>
* Don't exit program on sysfs read failures.Patrick Venture2017-07-271-3/+6
| | | | | | | | | | | | | | | | | | | | | We have an unreliable fan in one of the test systems and at present if the sysfs entry is unavailable or returns failure, then the program will exit. The program could be serving many sensors, and any one failure will cause it to exit. This is true not only when initially creating the sensors, but also if any sensor read fails at run-time. Testing: I verified the program logged the failures, which may not be ideal if there is a buggy sensor, but, I also ran it and managed to catch it where the sensor wasn't there initially and it cleanly reported only the sensors that were responsive and didn't just exit. There is certainly a case to be made for re-scanning periodically if the sensor returns or there was a timing issue, and there is a separate bug for that. This commit means only to make the program more robust on failure. Change-Id: I310a3e3c0e0ea86e439341a296b741ded18f46f2 Signed-off-by: Patrick Venture <venture@google.com>
* Fix high CPU usage noted with BMP280Brandon Wyman2017-06-261-4/+2
| | | | | | | | The call to findCallOutPath() is really only needed if we have encountered a read or write error. Change-Id: I81136156ba3a42546a5e2cec85283a0082358853 Signed-off-by: Brandon Wyman <v2cib530@us.ibm.com>
* Don't exit with error when hwmon dir is removedAndrew Geissler2017-06-161-0/+12
| | | | | | | | | | | | | There is a race condition between when an hwmon directory is removed and systemd halting the phosphor-hwmon application monitoring it. This code change ensures the application does not return an error in these cases. Resolves openbmc/openbmc#1789 Change-Id: If4f032759c522aa811d4092e7a7d8ea275480e4a Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
* Update call out algorithm for iio hwmon instanceBrandon Wyman2017-06-061-23/+91
| | | | | | | | | | | | | | | When readSysfsWithCallout() or writeSysfsWithCallout() get run, use the instancePath to search for a call out path. For instances with an hwmon driver, the passed in path should be used. For instances with an iio driver, search for a phandle file that has a value matching to that in the io-channels file for this phosphor-hwmon instance. If an error occurs on the read or write, use that matching phandle path to create a call out path. Resolves openbmc/openbmc#1265 Change-Id: I6390d0dfb3d67ce8a55d171ca9a3cb8f3057a8c9 Signed-off-by: Brandon Wyman <v2cib530@us.ibm.com>
* Update algorithm to find iio hwmon instanceBrandon Wyman2017-06-061-0/+33
| | | | | | | | If the hwmon instance cannot be found via the path symlink, try to find the instance via the phandle value in io-channels. Change-Id: I20966ec465baca41c1122afe714c1260926eade9 Signed-off-by: Brandon Wyman <v2cib530@us.ibm.com>
* Cater for change in elog create and commit interfaceMarri Devender Rao2017-04-151-26/+14
| | | | | Change-Id: I2a3fb65781965502d705bca772ebfb11e2334af9 Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
* Update sysfs readsMatthew Barth2017-03-301-6/+15
| | | | | | | Log an error with a device callout on read failures Change-Id: Ic9cd7ce3964e49879efd4bb19f197fd6a306773c Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
* Update hwmon fan target sysfs entriesMatthew Barth2017-03-301-1/+55
| | | | | | | | | | | | | Override the default FanSpeed.Target set implementation so when a target value is written to the FanSpeed interface it is also updated in the related fan target sysfs file. This sets a particular fan to the given target speed. Resolves openbmc/openbmc#962 Resolves openbmc/phosphor-hwmon#1 Change-Id: I867811737269b3f42d2a0dc15b37782a74f147b8 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
* Use std::filesystem when generating callout pathsBrad Bishop2017-03-271-7/+9
| | | | | Change-Id: Ia4dbe7e27368a7136d3767f105f6af78d9627c3f Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* Use std::filesystem in favor of custom moduleBrad Bishop2017-03-081-17/+10
| | | | | | | | | Reuse some code. Fix a bug in the process. Resolves openbmc/openbmc#1254 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com> Change-Id: I3fdbb70d6372f4a3193204bd2c9b6535315a3c70
* Log failing path after sysfs access failuresBrad Bishop2017-03-011-0/+43
| | | | | | | | Log failing device path and error after a sysfs access failure. Gracefully exit rather than crash. Change-Id: I41316e84a70ceda8c166f31ab3269f97978da3ab Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
* Find hwmon instances from OF device pathsBrad Bishop2017-01-171-0/+54
Provide a method that scans the hwmon subtree for a matching open firmware device path. Change-Id: Ic71dea90113c6894d9d2b61e03bd02f6b550e1e6 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
OpenPOWER on IntegriCloud