Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 1 | /** |
Patrick Venture | e84b4dd | 2018-11-01 16:06:31 -0700 | [diff] [blame] | 2 | * Copyright (C) 2017 IBM Corporation |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 16 | #include "registration.hpp" |
| 17 | |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 18 | #include <org/open_power/Proc/FSI/error.hpp> |
Ramesh Iyyar | 6230b0d | 2019-12-05 10:06:44 -0600 | [diff] [blame] | 19 | #include <phosphor-logging/elog-errors.hpp> |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 20 | #include <phosphor-logging/log.hpp> |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 21 | |
Brad Bishop | 5e5d445 | 2020-10-27 19:46:13 -0400 | [diff] [blame] | 22 | #include <filesystem> |
| 23 | #include <fstream> |
| 24 | |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 25 | namespace openpower |
| 26 | { |
| 27 | namespace openfsi |
| 28 | { |
| 29 | |
| 30 | using namespace phosphor::logging; |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 31 | namespace fsi_error = sdbusplus::org::open_power::Proc::FSI::Error; |
| 32 | |
Joel Stanley | 60db8b1 | 2019-09-27 15:23:39 +0930 | [diff] [blame] | 33 | constexpr auto masterScanPath = "/sys/class/fsi-master/fsi0/rescan"; |
| 34 | constexpr auto hubScanPath = "/sys/class/fsi-master/fsi1/rescan"; |
| 35 | constexpr auto masterCalloutPath = "/sys/class/fsi-master/fsi0/slave@00:00/raw"; |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 36 | |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 37 | /** |
| 38 | * Writes a 1 to the sysfs file passed in to trigger |
| 39 | * the device driver to do an FSI scan. |
| 40 | * |
| 41 | * @param[in] path - the sysfs path to write a 1 to |
| 42 | */ |
| 43 | static void doScan(const std::string& path) |
| 44 | { |
| 45 | std::ofstream file; |
| 46 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 47 | file.exceptions(std::ofstream::failbit | // logic error on operation |
| 48 | std::ofstream::badbit | // read/write error on operation |
| 49 | std::ofstream::eofbit); // end of file reached |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 50 | try |
| 51 | { |
| 52 | file.open(path); |
| 53 | file << "1"; |
| 54 | } |
| 55 | catch (std::exception& e) |
| 56 | { |
| 57 | auto err = errno; |
| 58 | throw std::system_error(err, std::generic_category()); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Performs an FSI master scan followed by an FSI hub scan. |
| 64 | * This is where the device driver detects which chips are present. |
| 65 | * |
| 66 | * This is unrelated to scanning a ring out of a chip. |
| 67 | */ |
| 68 | void scan() |
| 69 | { |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 70 | // Note: Currently the FSI device driver will always return success on both |
| 71 | // the master and hub scans. The only way we can detect something |
| 72 | // went wrong is if the master scan didn't create the hub scan file, so |
| 73 | // we will check for that. |
| 74 | // It is possible the driver will be updated in the future to actually |
| 75 | // return a failure so the code will still check for them. |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 76 | |
| 77 | try |
| 78 | { |
| 79 | doScan(masterScanPath); |
| 80 | } |
| 81 | catch (std::system_error& e) |
| 82 | { |
| 83 | log<level::ERR>("Failed to run the FSI master scan"); |
| 84 | |
| 85 | using metadata = org::open_power::Proc::FSI::MasterDetectionFailure; |
| 86 | |
| 87 | elog<fsi_error::MasterDetectionFailure>( |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 88 | metadata::CALLOUT_ERRNO(e.code().value()), |
| 89 | metadata::CALLOUT_DEVICE_PATH(masterCalloutPath)); |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 90 | } |
| 91 | |
Brad Bishop | 56d14d0 | 2020-10-09 15:28:51 -0400 | [diff] [blame] | 92 | if (!std::filesystem::exists(hubScanPath)) |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 93 | { |
| 94 | log<level::ERR>("The FSI master scan did not create a hub scan file"); |
| 95 | |
| 96 | using metadata = org::open_power::Proc::FSI::MasterDetectionFailure; |
| 97 | |
| 98 | elog<fsi_error::MasterDetectionFailure>( |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 99 | metadata::CALLOUT_ERRNO(0), |
| 100 | metadata::CALLOUT_DEVICE_PATH(masterCalloutPath)); |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | try |
| 104 | { |
| 105 | doScan(hubScanPath); |
| 106 | } |
| 107 | catch (std::system_error& e) |
| 108 | { |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 109 | // If the device driver is ever updated in the future to fail the sysfs |
| 110 | // write call on a scan failure then it should also provide some hints |
| 111 | // about which hardware failed so we can do an appropriate callout |
| 112 | // here. At this point in time, the driver shouldn't ever fail so |
| 113 | // we won't worry about guessing at the callout. |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 114 | |
| 115 | log<level::ERR>("Failed to run the FSI hub scan"); |
| 116 | |
| 117 | using metadata = org::open_power::Proc::FSI::SlaveDetectionFailure; |
| 118 | |
| 119 | elog<fsi_error::SlaveDetectionFailure>( |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 120 | metadata::ERRNO(e.code().value())); |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
Brad Bishop | 63508a7 | 2020-10-27 18:55:01 -0400 | [diff] [blame] | 124 | REGISTER_PROCEDURE("scanFSI", scan) |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 125 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 126 | } // namespace openfsi |
| 127 | } // namespace openpower |