summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/sensors/dbus-sensors/0002-Fix-PECI-client-creation-flow.patch
blob: cfdc99d6623d02bc776e5a0bb65bb237f2be77f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
From 0a1b2a13f6dbc64b5851ac2b1ca99d57afa78d60 Mon Sep 17 00:00:00 2001
From: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
Date: Wed, 27 Jan 2021 15:52:16 -0800
Subject: [PATCH] Fix PECI client creation flow

This commit fixes the PECI client creation flow to make it retry
the creation when the client is not exposed correctly.

Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
---
 src/CPUSensorMain.cpp | 66 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 54 insertions(+), 12 deletions(-)

diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index f304e3f..92c1716 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -82,6 +82,7 @@ struct CPUConfig
 };
 
 static constexpr const char* peciDev = "/dev/peci-";
+static constexpr const char* peciDevPath = "/sys/bus/peci/devices/";
 static constexpr const unsigned int rankNumMax = 8;
 
 namespace fs = std::filesystem;
@@ -167,7 +168,7 @@ bool createSensors(boost::asio::io_service& io,
     }
 
     std::vector<fs::path> hwmonNamePaths;
-    if (!findFiles(fs::path(R"(/sys/bus/peci/devices)"),
+    if (!findFiles(fs::path(peciDevPath),
                    R"(peci-\d+/\d+-.+/peci-.+/hwmon/hwmon\d+/name$)",
                    hwmonNamePaths, 6))
     {
@@ -403,7 +404,7 @@ bool createSensors(boost::asio::io_service& io,
     return true;
 }
 
-void exportDevice(const CPUConfig& config)
+int exportDevice(const CPUConfig& config)
 {
     std::ostringstream hex;
     hex << std::hex << config.addr;
@@ -411,9 +412,12 @@ void exportDevice(const CPUConfig& config)
     std::string busStr = std::to_string(config.bus);
 
     std::string parameters = "peci-client 0x" + addrHexStr;
-    std::string device = "/sys/bus/peci/devices/peci-" + busStr + "/new_device";
+    std::string devPath = peciDevPath;
+    std::string delDevice = devPath + "peci-" + busStr + "/delete_device";
+    std::string newDevice = devPath + "peci-" + busStr + "/new_device";
+    std::string newClient = devPath + busStr + "-" + addrHexStr + "/driver";
 
-    std::filesystem::path devicePath(device);
+    std::filesystem::path devicePath(newDevice);
     const std::string& dir = devicePath.parent_path().string();
     for (const auto& path : std::filesystem::directory_iterator(dir))
     {
@@ -431,20 +435,38 @@ void exportDevice(const CPUConfig& config)
                 std::cout << parameters << " on bus " << busStr
                           << " is already exported\n";
             }
-            return;
+
+            std::ofstream delDeviceFile(delDevice);
+            if (!delDeviceFile.good())
+            {
+                std::cerr << "Error opening " << delDevice << "\n";
+                return -1;
+            }
+            delDeviceFile << parameters;
+            delDeviceFile.close();
+
+            break;
         }
     }
 
-    std::ofstream deviceFile(device);
+    std::ofstream deviceFile(newDevice);
     if (!deviceFile.good())
     {
-        std::cerr << "Error writing " << device << "\n";
-        return;
+        std::cerr << "Error opening " << newDevice << "\n";
+        return -1;
     }
     deviceFile << parameters;
     deviceFile.close();
 
+    if (!std::filesystem::exists(newClient))
+    {
+        std::cerr << "Error creating " << newClient << "\n";
+        return -1;
+    }
+
     std::cout << parameters << " on bus " << busStr << " is exported\n";
+
+    return 0;
 }
 
 void detectCpu(boost::asio::deadline_timer& pingTimer,
@@ -460,6 +482,11 @@ void detectCpu(boost::asio::deadline_timer& pingTimer,
 
     for (CPUConfig& config : cpuConfigs)
     {
+        if (config.state == State::READY)
+        {
+            continue;
+        }
+
         std::string peciDevPath = peciDev + std::to_string(config.bus);
         auto file = open(peciDevPath.c_str(), O_RDWR | O_CLOEXEC);
         if (file < 0)
@@ -510,16 +537,29 @@ void detectCpu(boost::asio::deadline_timer& pingTimer,
             newState = State::OFF;
         }
 
-        close(file);
-
         if (config.state != newState)
         {
             if (newState != State::OFF)
             {
                 if (config.state == State::OFF)
                 {
-                    std::cout << config.name << " is detected\n";
-                    exportDevice(config);
+                    struct peci_rd_pkg_cfg_msg msg;
+                    msg.addr = config.addr;
+                    msg.index = PECI_MBX_INDEX_CPU_ID;
+                    msg.param = 0;
+                    msg.rx_len = 4;
+                    if (!ioctl(file, PECI_IOC_RD_PKG_CFG, &msg))
+                    {
+                        std::cout << config.name << " is detected\n";
+                        if (exportDevice(config))
+                        {
+                            newState = State::OFF;
+                        }
+                    }
+                    else
+                    {
+                        newState = State::OFF;
+                    }
                 }
 
                 if (newState == State::ON)
@@ -542,6 +582,8 @@ void detectCpu(boost::asio::deadline_timer& pingTimer,
             keepPinging = true;
         }
 
+        close(file);
+
         if (debug)
         {
             std::cout << config.name << ", state: " << config.state << "\n";
-- 
2.17.1