Call Hub FSI scan service prior to doing OCC bind

This is needed to make sure that the /dev/occ files are created
that are needed to communicate with OCC device. Also, calling to
this service is needed only when the first call to do OCC bind is
received.

Change-Id: I40466b8b74753b2f2366be385a8b066e912b32e4
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/configure.ac b/configure.ac
index 3091e67..098a0eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -97,6 +97,10 @@
 AS_IF([test "x$DEV_PATH" == "x"], [DEV_PATH="/sys/bus/platform/devices/"])
 AC_DEFINE_UNQUOTED([DEV_PATH], ["$DEV_PATH"], [The device path])
 
+AC_ARG_VAR(FSI_SCAN_FILE, [The File to write for initiating FSI rescan])
+AS_IF([test "x$FSI_SCAN_FILE" == "x"], [FSI_SCAN_FILE="/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/00:00:00:0a/fsi1/rescan"])
+AC_DEFINE_UNQUOTED([FSI_SCAN_FILE], ["$FSI_SCAN_FILE"], [The File to write for initiating FSI rescan])
+
 AC_ARG_VAR(PS_DERATING_FACTOR, [The power supply derating factor])
 AS_IF([test "x$PS_DERATING_FACTOR" == "x"], [PS_DERATING_FACTOR=90])
 AC_DEFINE_UNQUOTED([PS_DERATING_FACTOR], [$PS_DERATING_FACTOR], [The power supply derating factor])
diff --git a/occ_status.cpp b/occ_status.cpp
index f740dc7..7eafb66 100644
--- a/occ_status.cpp
+++ b/occ_status.cpp
@@ -7,6 +7,11 @@
 namespace occ
 {
 
+bool Status::hubFsiScanDone = false;
+
+// To initiate a FSI rescan
+constexpr auto fsiReScan = "1";
+
 // Handles updates to occActive property
 bool Status::occActive(bool value)
 {
@@ -14,16 +19,26 @@
     {
         if (value)
         {
+            if (!hubFsiScanDone)
+            {
+                // Need to do hub scan before we bind
+                this->scanHubFSI();
+            }
+
             // Bind the device
             device.bind();
 
             // And watch for errors
-            device.addErrorWatch();
+            // Commenting until we solve the occ error monitoring issue
+            // TODO: openbmc/openbmc#2126
+            // device.addErrorWatch();
         }
         else
         {
             // Stop watching for errors
-            device.removeErrorWatch();
+            // Commenting until we solve the occ error monitoring issue
+            // TODO: openbmc/openbmc#2126
+            // device.removeErrorWatch();
 
             // Do the unbind.
             device.unBind();
@@ -97,5 +112,18 @@
     return;
 }
 
+// Scans the secondary FSI hub to make sure /dev/occ files are populated
+// Write "1" to achieve that
+void Status::scanHubFSI()
+{
+    std::ofstream file(FSI_SCAN_FILE, std::ios::out);
+    file << fsiReScan;
+    file.close();
+
+    // Hub FSI scan has been done. No need to do this for all the OCCs
+    hubFsiScanDone = true;
+    return;
+}
+
 } // namespace occ
 } // namespace open_power
diff --git a/occ_status.hpp b/occ_status.hpp
index e07ca61..74839d0 100644
--- a/occ_status.hpp
+++ b/occ_status.hpp
@@ -109,6 +109,9 @@
          **/
         sdbusplus::bus::match_t hostControlSignal;
 
+        /** @brief Indicates whether a hub FSI scan has been attempted or not */
+        static bool hubFsiScanDone;
+
         /** @brief Callback handler when device errors are detected */
         void deviceErrorHandler();
 
@@ -121,6 +124,10 @@
         /** @brief Sends a message to host control command handler to reset OCC
          */
         void resetOCC();
+
+        /** @brief Initiates hub FSI scan so that /dev/occ files are created
+         */
+        void scanHubFSI();
 };
 
 } // namespace occ