]> mj.ucw.cz Git - pciutils.git/blobdiff - pcilmr.c
README: Update copyright year and mention pcilmr
[pciutils.git] / pcilmr.c
index 43e791dd68edbf103f8bb29fadd2bc9cd68fb598..cb8bd77a04fded0a3d8c3c811aa040d538778717 100644 (file)
--- a/pcilmr.c
+++ b/pcilmr.c
@@ -8,10 +8,10 @@
  *     SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#include <getopt.h>
 #include <memory.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "lmr/lmr.h"
 
@@ -20,7 +20,8 @@ const char program_name[] = "pcilmr";
 enum mode { MARGIN, FULL, SCAN };
 
 static const char usage_msg[]
-  = "Usage:\n"
+  = "! Utility requires preliminary preparation of the system. Refer to the pcilmr man page !\n\n"
+    "Usage:\n"
     "pcilmr [--margin] [<margining options>] <downstream component> ...\n"
     "pcilmr --full [<margining options>]\n"
     "pcilmr --scan\n\n"
@@ -52,16 +53,19 @@ static const char usage_msg[]
     "-v <steps>\t\tSpecify maximum number of steps for Voltage Margining.\n"
     "Use only one of -T/-t options at the same time (same for -V/-v).\n"
     "Without these options utility will use MaxSteps from Device\n"
-    "capabilities as test limit.\n\n";
+    "capabilities as test limit.\n\n"
+    "Margining Log settings:\n"
+    "-o <directory>\t\tSave margining results in csv form into the\n"
+    "\t\t\tspecified directory. Utility will generate file with the\n"
+    "\t\t\tname in form of 'lmr_<downstream component>_Rx#_<timestamp>.csv'\n"
+    "\t\t\tfor each successfully tested receiver.\n";
 
 static struct pci_dev *
 dev_for_filter(struct pci_access *pacc, char *filter)
 {
   struct pci_filter pci_filter;
-  char dev[17] = { 0 };
-  strncpy(dev, filter, sizeof(dev) - 1);
   pci_filter_init(pacc, &pci_filter);
-  if (pci_filter_parse_slot(&pci_filter, dev))
+  if (pci_filter_parse_slot(&pci_filter, filter))
     die("Invalid device ID: %s\n", filter);
 
   if (pci_filter.bus == -1 || pci_filter.slot == -1 || pci_filter.func == -1)
@@ -197,6 +201,9 @@ main(int argc, char **argv)
 
   bool run_margin = true;
 
+  char *dir_for_csv = NULL;
+  bool save_csv = false;
+
   u64 total_steps = 0;
 
   pacc = pci_alloc();
@@ -246,7 +253,7 @@ main(int argc, char **argv)
         break;
     }
 
-  while ((c = getopt(argc, argv, ":r:e:l:cp:t:v:VT")) != -1)
+  while ((c = getopt(argc, argv, ":r:e:l:cp:t:v:VTo:")) != -1)
     {
       switch (c)
         {
@@ -277,6 +284,10 @@ main(int argc, char **argv)
           case 'r':
             recvs_n = parse_csv_arg(optarg, recvs_arg);
             break;
+          case 'o':
+            dir_for_csv = optarg;
+            save_csv = true;
+            break;
           default:
             die("Invalid arguments\n\n%s", usage_msg);
         }
@@ -449,6 +460,8 @@ main(int argc, char **argv)
           margin_log_bdfs(down_ports[i], up_ports[i]);
           printf(":\n\n");
           margin_results_print_brief(results[i], results_n[i]);
+          if (save_csv)
+            margin_results_save_csv(results[i], results_n[i], dir_for_csv, up_ports[i]);
           printf("\n");
         }
     }