>From 77a06e581391e4c060f26656a0c95891c1877b08 Mon Sep 17 00:00:00 2001
From: Eitan Zahavi <eitan@sw094.lab.mtl.com>
Date: Mon, 9 Mar 2009 15:34:16 +0200
Subject: [PATCH] Provide a new flag -u/--updn to ibdiagnet and ibdmchk that

explicitly selects the Up/Down based credit loop check
algorithm. Otherwise the generic credit loop check is
invoked.

Based on Dale Purdy's <purdy@sgi.com> patch

Signed-off-by: Oren Kladnitsky <orenk@dev.mellanox.co.il>
---
 ibdiag/doc/ibdiagnet.pod  |   11 ++++++-
 ibdiag/doc/ibdiagui.pod   |    2 +-
 ibdiag/src/ibdebug.tcl    |   11 ++++--
 ibdiag/src/ibdebug_if.tcl |   10 ++++--
 ibdm/doc/ibdmchk.pod      |    8 ++++-
 ibdm/src/osm_check.cpp    |   73 +++++++++++++++++++++-----------------------
 6 files changed, 66 insertions(+), 49 deletions(-)

diff --git a/ibdiag/doc/ibdiagnet.pod b/ibdiag/doc/ibdiagnet.pod
index d2cf460..cdc78ed 100644
--- a/ibdiag/doc/ibdiagnet.pod
+++ b/ibdiag/doc/ibdiagnet.pod
@@ -4,7 +4,7 @@ B<ibdiagnet - IB diagnostic net>
 
 =head1 SYNOPSYS
 
-ibdiagnet [-c <count>] [-v] [-r] [-o <out-dir>]
+ibdiagnet [-c <count>] [-v] [-r] [-u] [-o <out-dir>]
   [-t <topo-file>] [-s <sys-name>] [-i <dev-index>] [-p <port-num>] [-wt]
   [-pm] [-pc] [-P <<PM>=<Value>>]
   [-lw <1x|4x|12x>] [-ls <2.5|5|10>]
@@ -135,6 +135,15 @@ Provides a report of the fabric qualities
 
 =back
 
+=item B<-u>              :
+
+=over
+
+=item
+Credit loop check based on UpDown rules
+
+=back
+
 =item B<-t <topo-file>>  :
 
 =over
diff --git a/ibdiag/doc/ibdiagui.pod b/ibdiag/doc/ibdiagui.pod
index 4e0250f..86a2df9 100644
--- a/ibdiag/doc/ibdiagui.pod
+++ b/ibdiag/doc/ibdiagui.pod
@@ -4,7 +4,7 @@ B<ibdiagui - IB Diagnostic GUI>
 
 =head1 SYNOPSYS
 
-ibdiagui [-c <count>] [-v] [-r] [-o <out-dir>]
+ibdiagui [-c <count>] [-v] [-r] [-u] [-o <out-dir>]
      [-t <topo-file>] [-s <sys-name>] [-i <dev-index>] [-p <port-num>]
      [-pm] [-pc] [-P <PM counter>=<Trash Limit>]
      [-lw <1x|4x|12x>] [-ls <2.5|5|10>]
diff --git a/ibdiag/src/ibdebug.tcl b/ibdiag/src/ibdebug.tcl
index 3a464f2..04a8566 100644
--- a/ibdiag/src/ibdebug.tcl
+++ b/ibdiag/src/ibdebug.tcl
@@ -4391,10 +4391,13 @@ proc DumpFabQualities {} {
     inform "-I-ibdiagnet:check.credit.loops.header"
 
     # report credit loops
-    ibdmCalcMinHopTables $fabric
-    set roots [ibdmFindRootNodesByMinHop $fabric]
-    # just flush out any logs
-    set report [ibdmGetAndClearInternalLog]
+    set roots ""
+    if { [info exists G(argv:updown)] } {
+	ibdmCalcMinHopTables $fabric
+	set roots [ibdmFindRootNodesByMinHop $fabric]
+	# just flush out any logs
+	set report [ibdmGetAndClearInternalLog]
+    }
     if {[llength $roots]} {
 	inform "-I-reporting:found.roots" $roots
 	ibdmReportNonUpDownCa2CaPaths $fabric $roots
diff --git a/ibdiag/src/ibdebug_if.tcl b/ibdiag/src/ibdebug_if.tcl
index 21afc45..d9807dc 100644
--- a/ibdiag/src/ibdebug_if.tcl
+++ b/ibdiag/src/ibdebug_if.tcl
@@ -163,6 +163,10 @@ proc SetInfoArgv {} {
 	-t,param "topo-file"
 	-t,desc  "Specifies the topology file name"
 
+	-u,name  "updown"
+	-u,desc  "Indicates that UpDown credit loop checking should be done against automaticly determined roots"
+	-u,arglen   0
+
 	-v,name  "verbose"
 	-v,desc  "Instructs the tool to run in verbose mode"
 	-v,arglen   0
@@ -322,8 +326,8 @@ proc SetToolsFlags {} {
     array set TOOLS_FLAGS {
 	ibping     "(n|l|d) . c w v o     . t s i p "
 	ibdiagpath "(n|l|d) . c   v o smp . t s i p    . pm pc P . lw ls sl ."
-	ibdiagui   "          c   v r o   . t s i p    . pm pc P . lw ls ."
-	ibdiagnet  "          c   v r o   . t s i p wt . pm pc P . lw ls    . skip load_db csv"
+	ibdiagui   "          c   v r u o   . t s i p    . pm pc P . lw ls ."
+	ibdiagnet  "          c   v r u o   . t s i p wt . pm pc P . lw ls    . skip load_db csv"
 	ibcfg    "(n|l|d) (c|q)       . t s i p o"
 	ibmad    "(m) (a) (n|l|d)     . t s i p o ; (q) a"
 	ibsac    "(m) (a) k           . t s i p o ; (q) a"
@@ -2535,7 +2539,7 @@ proc showHelpPage { args } {
             Hop-count information:
             maximal hop-count, an example path, and a hop-count histogram
             All CA-to-CA paths traced
-            Credit loop report
+            Credit loop report (based on UpDown if -u option is provided)
             mgid-mlid-HCAs matching table
             Note: In case the IB fabric includes only one CA, then CA-to-CA paths are not
             reported.
diff --git a/ibdm/doc/ibdmchk.pod b/ibdm/doc/ibdmchk.pod
index 21d4a14..ae4cffe 100644
--- a/ibdm/doc/ibdmchk.pod
+++ b/ibdm/doc/ibdmchk.pod
@@ -15,7 +15,7 @@ ibdmchk [-v][-h][-u][-a <roots file>] -t <topology file> -n <SM Node>
 VERIFICATION:
 
 ibdmchk [-v][-h][-r <roots file>] [-s <subnet file>] [-f <fdb file>]
-  [-l <lmc>]
+  [-l <lmc>][-u]
 
 =head1 DESIGN MODE DESCRIPTION
 
@@ -55,7 +55,7 @@ Use enhanced routing algorithm when LMC > 0 and report the resulting paths corre
 
 =item -u|--updn
 
-Use up/down routing algorithm instead of OpenSM min-hop.
+Use up/down routing algorithm instead of OpenSM min-hop. Also use Up/Down based credit loop check.
 
 =item -r|--roots <roots file>
 A file with all the roots node names (one on each line).
@@ -98,6 +98,10 @@ OpenSM dump of Multicast LFDB. Use -D 0x41 to generate it (default is /var/log/o
 
 A file holding all root nodes guids (one per line).
 
+=item -u|--updn
+
+Use Up/Down based credit loop check algorithm instead of the generic one.
+
 =head1 AUTHOR
 
 Eitan Zahavi, Mellanox Technologies LTD, eitan@mellanox.co.il
diff --git a/ibdm/src/osm_check.cpp b/ibdm/src/osm_check.cpp
index 1c18c1c..9b0cb26 100644
--- a/ibdm/src/osm_check.cpp
+++ b/ibdm/src/osm_check.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
+ * Copyright (c) 2004-2009 Mellanox Technologies LTD. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -78,6 +78,7 @@ show_help() {
     << "  -e|--enh = use enhanced routing algorithm when LMC > 0 and report the resulting paths\n"
     << "       correlation (using same system/node) histogram\n"
     << "  -u|--updn = use up/down routing algorithm instead of OpenSM min-hop.\n"
+	 << "       Also selects Up/Down credit loop check algorithm.\n"
     << "  -r|--roots <roots file> = a file with all the roots node names (one on each line).\n"
     << "\n"
     << "  CLUSTER VERIFICATION:\n"
@@ -110,6 +111,7 @@ show_help() {
     << "  -c|--psl <file> = CAxCA->SL mapping. \n"
     << "  -d|--slvl <file> = SL2VL mapping. \n"
     << "  -r|--roots <roots file> = a file holding all root nodes guids (one per line).\n"
+    << "  -u|--updn = selects Up/Down credit loop check algorithm rather than the generic one.\n"
     << "\n"
     << "Author: Eitan Zahavi, Mellanox Technologies LTD.\n"
     << endl;
@@ -406,42 +408,42 @@ int main (int argc, char **argv) {
     if (UseUpDown) {
       list <IBNode *> rootNodes;
       if (RootsFileName.size()) {
-	rootNodes = ParseRootNodeNamesFile(&fabric, RootsFileName);
+        rootNodes = ParseRootNodeNamesFile(&fabric, RootsFileName);
       }
       else {
-	rootNodes = SubnMgtFindRootNodesByMinHop(&fabric);
+        rootNodes = SubnMgtFindRootNodesByMinHop(&fabric);
       }
 
       if (!rootNodes.empty()) {
-	cout << "-I- Recognized " << rootNodes.size() << " root nodes:" << endl;
-	for (list <IBNode *>::iterator nI = rootNodes.begin();
-	     nI != rootNodes.end(); nI++) {
-	  cout << " " << (*nI)->name << endl;
-	}
-	cout << "---------------------------------------------------------------------------\n" << endl;
-
-	map_pnode_int nodesRank;
-	SubnRankFabricNodesByRootNodes(&fabric, rootNodes, nodesRank);
-
-	if (SubnMgtCalcUpDnMinHopTbls(&fabric, nodesRank)) {
-	  cout << "-E- Fail to update Min Hops Tables." << endl;
-	  exit(1);
-	}
+        cout << "-I- Recognized " << rootNodes.size() << " root nodes:" << endl;
+        for (list <IBNode *>::iterator nI = rootNodes.begin();
+             nI != rootNodes.end(); nI++) {
+          cout << " " << (*nI)->name << endl;
+        }
+        cout << "---------------------------------------------------------------------------\n" << endl;
+
+        map_pnode_int nodesRank;
+        SubnRankFabricNodesByRootNodes(&fabric, rootNodes, nodesRank);
+
+        if (SubnMgtCalcUpDnMinHopTbls(&fabric, nodesRank)) {
+          cout << "-E- Fail to update Min Hops Tables." << endl;
+          exit(1);
+        }
       } else {
-	cout << "-E- Fail to recognize any root nodes. Up/Down is not active!" << endl;
+        cout << "-E- Fail to recognize any root nodes. Up/Down is not active!" << endl;
       }
     }
 
     if (!EnhancedRouting) {
 
       if (SubnMgtOsmRoute(&fabric)) {
-	cout << "-E- Fail to update LFT Tables." << endl;
-	exit(1);
+        cout << "-E- Fail to update LFT Tables." << endl;
+        exit(1);
       }
     } else {
       if (SubnMgtOsmEnhancedRoute(&fabric)) {
-	cout << "-E- Fail to update LFT Tables." << endl;
-	exit(1);
+        cout << "-E- Fail to update LFT Tables." << endl;
+        exit(1);
       }
     }
 
@@ -551,22 +553,17 @@ int main (int argc, char **argv) {
 
   list <IBNode *> rootNodes;
   int anyErr = 0;
-
-  if (RootsFileName.size())
-    {
-      if (TopoFile.size())
-	{
-	  rootNodes = ParseRootNodeNamesFile(&fabric, RootsFileName);
-	}
-      else
-	{
-	  rootNodes = ParseRootNodeGuidsFile(&fabric, RootsFileName);
-	}
-    }
-  else
-    {
-      rootNodes = SubnMgtFindRootNodesByMinHop(&fabric);
-    }
+  if (UseUpDown) {
+	 if (RootsFileName.size()) {
+		if (TopoFile.size()) {
+		  rootNodes = ParseRootNodeNamesFile(&fabric, RootsFileName);
+		} else {
+		  rootNodes = ParseRootNodeGuidsFile(&fabric, RootsFileName);
+		}
+	 } else {
+		rootNodes = SubnMgtFindRootNodesByMinHop(&fabric);
+	 }
+  }
 
   if (!rootNodes.empty()) {
     cout << "-I- Recognized " << rootNodes.size() << " root nodes:" << endl;
-- 
1.5.3

