Attn: Cleanup trace messages

Cleanup attention handler debug trace messages.

Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I2d5cc50e88c42278a37742ee361aec557ee15b28
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index f8d0a21..db82ef5 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -45,6 +45,10 @@
  */
 int handleSpecial(Attention* i_attention);
 
+/** @brief Determine if attention is active and not masked */
+bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn,
+                uint32_t i_proc);
+
 /**
  * @brief The main attention handler logic
  *
@@ -68,13 +72,9 @@
         {
             proc = pdbg_target_index(target); // get processor number
 
-            std::stringstream ss; // log message stream
-            ss << "checking processor " << proc;
-            trace<level::INFO>(ss.str().c_str());
-
             // The processor FSI target is required for CFAM read
             char path[16];
-            sprintf(path, "/proc%d/fsi", (int)proc);
+            sprintf(path, "/proc%d/fsi", proc);
             pdbg_target* attnTarget = pdbg_target_from_path(nullptr, path);
 
             if (PDBG_TARGET_ENABLED == pdbg_target_probe(attnTarget))
@@ -82,59 +82,42 @@
                 // get active attentions on processor
                 if (RC_SUCCESS != fsi_read(attnTarget, 0x1007, &isr_val))
                 {
-                    // event
-                    eventAttentionFail(RC_CFAM_ERROR);
-
-                    // trace
+                    // log cfam read error
                     trace<level::INFO>("Error! cfam read 0x1007 FAILED");
+                    eventAttentionFail(RC_CFAM_ERROR);
                 }
                 else
                 {
-                    ss.str(std::string()); // clear stream
-                    ss << "cfam 0x1007 = 0x";
-                    ss << std::hex << std::setw(8) << std::setfill('0');
-                    ss << isr_val;
-                    trace<level::INFO>(ss.str().c_str());
-
                     // get interrupt enabled special attentions mask
                     if (RC_SUCCESS != fsi_read(attnTarget, 0x100d, &isr_mask))
                     {
-                        // event
-                        eventAttentionFail(RC_CFAM_ERROR);
-
-                        // trace
+                        // log cfam read error
                         trace<level::INFO>("Error! cfam read 0x100d FAILED");
+                        eventAttentionFail(RC_CFAM_ERROR);
                     }
                     else
                     {
-                        // CFAM 0x100d is expected to have bits set
-                        // corresponding to attentions that can generate an
-                        // attention interrupt.
-
-                        ss.str(std::string()); // clear stream
-                        ss << "cfam 0x100d = 0x";
-                        ss << std::hex << std::setw(8) << std::setfill('0');
-                        ss << isr_mask;
-                        trace<level::INFO>(ss.str().c_str());
-
-                        // bit 0 on "left": bit 30 = SBE vital attention
-                        if (isr_val & isr_mask & 0x00000002)
+                        // SBE vital attention active and not masked?
+                        if (true ==
+                            activeAttn(isr_val, isr_mask, SBE_ATTN, proc))
                         {
                             active_attentions.emplace_back(Attention::Vital,
                                                            handleVital, target,
                                                            i_config);
                         }
 
-                        // bit 0 on "left": bit 1 = checkstop
-                        if (isr_val & isr_mask & 0x40000000)
+                        // Checkstop attention active and not masked?
+                        if (true ==
+                            activeAttn(isr_val, isr_mask, CHECKSTOP_ATTN, proc))
                         {
                             active_attentions.emplace_back(Attention::Checkstop,
                                                            handleCheckstop,
                                                            target, i_config);
                         }
 
-                        // bit 0 on "left": bit 2 = special attention
-                        if (isr_val & isr_mask & 0x20000000)
+                        // Special attention active and not masked?
+                        if (true ==
+                            activeAttn(isr_val, isr_mask, SPECIAL_ATTN, proc))
                         {
                             active_attentions.emplace_back(Attention::Special,
                                                            handleSpecial,
@@ -240,7 +223,7 @@
 {
     int rc = RC_SUCCESS; // assume special attention handled
 
-    // The TI infor chipop will give us a pointer to the TI info data
+    // The TI info chipop will give us a pointer to the TI info data
     uint8_t* tiInfo       = nullptr;                  // ptr to TI info data
     uint32_t tiInfoLen    = 0;                        // length of TI info data
     pdbg_target* attnProc = i_attention->getTarget(); // proc with attention
@@ -256,7 +239,6 @@
         {
             if (PDBG_TARGET_ENABLED == pdbg_target_probe(tiInfoTarget))
             {
-                trace<level::INFO>("calling sbe_mpipl_get_ti_info");
                 sbe_mpipl_get_ti_info(tiInfoTarget, &tiInfo, &tiInfoLen);
                 if (tiInfo == nullptr)
                 {
@@ -269,8 +251,6 @@
     // If TI area exists and is marked valid we can assume TI occurred
     if ((nullptr != tiInfo) && (0 != tiInfo[0]))
     {
-        trace<level::INFO>("TI info data present and valid");
-
         TiDataArea* tiDataArea = (TiDataArea*)tiInfo;
 
         // trace a few known TI data area values
@@ -296,8 +276,6 @@
 
         if (true == (i_attention->getConfig()->getFlag(enTerminate)))
         {
-            trace<level::INFO>("TI (terminate immediately)");
-
             // Call TI special attention handler
             rc = tiHandler(tiDataArea);
         }
@@ -310,12 +288,8 @@
         // if configured to handle breakpoint as default special attention
         if (i_attention->getConfig()->getFlag(dfltBreakpoint))
         {
-            trace<level::INFO>("assuming breakpoint");
-
             if (true == (i_attention->getConfig()->getFlag(enBreakpoints)))
             {
-                trace<level::INFO>("breakpoint");
-
                 // Call the breakpoint special attention handler
                 bpHandler();
             }
@@ -327,8 +301,6 @@
 
             if (true == (i_attention->getConfig()->getFlag(enTerminate)))
             {
-                trace<level::INFO>("TI (terminate immediately)");
-
                 // Call TI special attention handler
                 rc = tiHandler(nullptr);
             }
@@ -349,4 +321,80 @@
     return rc;
 }
 
+/**
+ * @brief Determine if attention is active and not masked
+ *
+ * Determine whether an attention needs to be handled and trace details of
+ * attention type and whether it is masked or not.
+ *
+ * @param i_val attention status register
+ * @param i_mask attention true mask register
+ * @param i_attn attention type
+ * @param i_proc processor associated with registers
+ *
+ * @return true if attention is active and not masked, otherwise false
+ */
+bool activeAttn(uint32_t i_val, uint32_t i_mask, uint32_t i_attn,
+                uint32_t i_proc)
+{
+    bool rc        = false; // assume attn masked and/or inactive
+    bool validAttn = true;  // known attention type
+
+    // if attention active
+    if (0 != (i_val & i_attn))
+    {
+        // trace proc with attn
+        std::stringstream ss;
+        ss << "Attn: proc " << i_proc;
+        trace<level::INFO>(ss.str().c_str());
+
+        // trace isr
+        ss.str(std::string());           // clear stream
+        ss << std::hex << std::showbase; // trace as hex vals
+        ss << "cfam 0x1007 = " << std::setw(8) << std::setfill('0') << i_val;
+        trace<level::INFO>(ss.str().c_str());
+
+        // trace true-mask
+        ss.str(std::string());           // clear stream
+        ss << std::hex << std::showbase; // trace as hex vals
+        ss << "cfam 0x100d = " << std::setw(8) << std::setfill('0') << i_mask;
+        trace<level::INFO>(ss.str().c_str());
+
+        ss.str(std::string()); // clear stream
+
+        switch (i_attn)
+        {
+            case SBE_ATTN:
+                ss << "SBE attn";
+                break;
+            case CHECKSTOP_ATTN:
+                ss << "Checkstop attn";
+                break;
+            case SPECIAL_ATTN:
+                ss << "Special attn";
+                break;
+            default:
+                ss << "Unknown attn";
+                validAttn = false;
+        }
+
+        // see if attention is masked
+        if (true == validAttn)
+        {
+            if (0 != (i_mask & i_attn))
+            {
+                rc = true; // attention active and not masked
+            }
+            else
+            {
+                ss << " masked";
+            }
+        }
+
+        trace<level::INFO>(ss.str().c_str()); // commit trace stream
+    }
+
+    return rc;
+}
+
 } // namespace attn
diff --git a/attn/attn_handler.hpp b/attn/attn_handler.hpp
index 1500d39..d2b6764 100644
--- a/attn/attn_handler.hpp
+++ b/attn/attn_handler.hpp
@@ -14,6 +14,11 @@
     RC_CFAM_ERROR
 };
 
+/** @brief Attention global status bits */
+constexpr uint32_t SBE_ATTN       = 0x00000002;
+constexpr uint32_t CHECKSTOP_ATTN = 0x40000000;
+constexpr uint32_t SPECIAL_ATTN   = 0x20000000;
+
 /**
  * @brief The main attention handler logic
  *
diff --git a/attn/attn_monitor.cpp b/attn/attn_monitor.cpp
index 6f4d108..c114bdf 100644
--- a/attn/attn_monitor.cpp
+++ b/attn/attn_monitor.cpp
@@ -24,8 +24,6 @@
             }
             else
             {
-                trace<level::INFO>(
-                    "Attention monitor detected active attention");
                 handleGPIOEvent(); // gpio trigger detected
             }
             return;
@@ -50,8 +48,6 @@
         {
             // active attention when gpio == 0
             case 0:
-                logMessage = "Attention monitor calling attention handler";
-                trace<level::INFO>(logMessage.c_str());
                 attnHandler(iv_config);
                 break;
 
diff --git a/attn/ti_handler.cpp b/attn/ti_handler.cpp
index 6c3f26c..a8daedb 100644
--- a/attn/ti_handler.cpp
+++ b/attn/ti_handler.cpp
@@ -69,7 +69,6 @@
     method.append(i_target);  // target unit to start
     method.append("replace"); // mode = replace conflicting queued jobs
 
-    trace<level::INFO>("transitioning host");
     trace<level::INFO>(i_target);
 
     bus.call_noreply(method); // start the service