diff mbox series

[14/15] pciutils-pcilmr: Add handling of situations when device reports its MaxOffset values equal to 0

Message ID 20231208091734.12225-15-n.proshkin@yadro.com (mailing list archive)
State Superseded
Headers show
Series pciutils: Add utility for Lane Margining | expand

Commit Message

Nikita Proshkin Dec. 8, 2023, 9:17 a.m. UTC
According to spec, for the MaxTimingOffset and MaxVoltageOffset parameters
'A 0 value may be reported if the vendor chooses not to report the offset'.

Use max possible Offset value in such situations and report to the user.

Reviewed-by: Sergei Miroshnichenko <s.miroshnichenko@yadro.com>
Signed-off-by: Nikita Proshkin <n.proshkin@yadro.com>
---
 lmr_lib/margin.c         |  9 +++++++--
 lmr_lib/margin.h         |  3 +++
 lmr_lib/margin_log.c     | 11 +++++++++++
 lmr_lib/margin_results.c | 12 ++++++++++++
 4 files changed, 33 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lmr_lib/margin.c b/lmr_lib/margin.c
index ac20e82..cb9a9da 100644
--- a/lmr_lib/margin.c
+++ b/lmr_lib/margin.c
@@ -271,8 +271,13 @@  bool margin_receiver(struct margin_recv *recv, struct margin_args *args, struct
       recv->parallel_lanes = recv->max_lanes + 1;
     margin_apply_hw_quirks(recv);
 
-    results->tim_coef = (double)recv->timing_offset / (double)recv->timing_steps;
-    results->volt_coef = (double)recv->volt_offset / (double)recv->volt_steps * 10.0;
+    results->tim_off_reported = recv->timing_offset != 0;
+    results->volt_off_reported = recv->volt_offset != 0;
+    double tim_offset = results->tim_off_reported ? (double)recv->timing_offset : 50.0;
+    double volt_offset = results->volt_off_reported ? (double)recv->volt_offset : 50.0;
+
+    results->tim_coef = tim_offset / (double)recv->timing_steps;
+    results->volt_coef = volt_offset / (double)recv->volt_steps * 10.0;
 
     results->ind_left_right_tim = recv->ind_left_right_tim;
     results->volt_support = recv->volt_support;
diff --git a/lmr_lib/margin.h b/lmr_lib/margin.h
index 8f3506b..8f82f30 100644
--- a/lmr_lib/margin.h
+++ b/lmr_lib/margin.h
@@ -129,6 +129,9 @@  struct margin_results {
   double tim_coef;
   double volt_coef;
 
+  bool tim_off_reported;
+  bool volt_off_reported;
+
   uint8_t lanes_n;
   struct margin_res_lane *lanes;
 };
diff --git a/lmr_lib/margin_log.c b/lmr_lib/margin_log.c
index e57bd79..83652f1 100644
--- a/lmr_lib/margin_log.c
+++ b/lmr_lib/margin_log.c
@@ -49,6 +49,17 @@  void margin_log_print_caps(struct margin_recv *recv)
     margin_log("\nWarning: device uses Lane Reversal.\n");
     margin_log("However, utility uses logical lane numbers in arguments and for logging.\n");
   }
+
+  if (recv->timing_offset == 0)
+  {
+    margin_log("\nWarning: Vendor chose not to report the Max Timing Offset.\n"
+               "Utility will use its max possible value - 50 (50%% UI).\n");
+  }
+  if (recv->volt_support && recv->volt_offset == 0)
+  {
+    margin_log("\nWarning: Vendor chose not to report the Max Voltage Offset.\n"
+               "Utility will use its max possible value - 50 (500 mV).\n");
+  }
 }
 
 void margin_log_link(struct margin_dev *down, struct margin_dev *up)
diff --git a/lmr_lib/margin_results.c b/lmr_lib/margin_results.c
index cc6132f..656f1fe 100644
--- a/lmr_lib/margin_results.c
+++ b/lmr_lib/margin_results.c
@@ -87,6 +87,18 @@  void margin_results_print_brief(struct margin_results *results, uint8_t recvs_n)
 
     if (recv->lane_reversal)
       printf("Rx(%X) - Lane Reversal\n", 10 + recv->recvn - 1);
+
+    if (!recv->tim_off_reported)
+      printf("Rx(%X) - Attention: Vendor chose not to report the Max Timing Offset.\n"
+             "Utility used its max possible value (50%% UI) for calculations of %% UI and ps.\n"
+             "Keep in mind that for timing results of this receiver only steps values are reliable.\n\n",
+             10 + recv->recvn - 1);
+    if (recv->volt_support && !recv->volt_off_reported)
+      printf("Rx(%X) - Attention: Vendor chose not to report the Max Voltage Offset.\n"
+             "Utility used its max possible value (500 mV) for calculations of mV.\n"
+             "Keep in mind that for voltage results of this receiver only steps values are reliable.\n\n",
+             10 + recv->recvn - 1);
+
     if (check_recv_weird(recv, MARGIN_TIM_MIN, MARGIN_VOLT_MIN))
       lane_rating = WEIRD;
     else