From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>,
Michael Jamet <michael.jamet@intel.com>,
Lukas Wunner <lukas@wunner.de>,
Andreas Noever <andreas.noever@gmail.com>,
Aapo Vienamo <aapo.vienamo@iki.fi>,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 5/8] thunderbolt: debugfs: Replace margining lane numbers with an enum
Date: Wed, 23 Oct 2024 13:11:08 +0300 [thread overview]
Message-ID: <20241023101111.3418311-6-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20241023101111.3418311-1-mika.westerberg@linux.intel.com>
From: Aapo Vienamo <aapo.vienamo@iki.fi>
Replace the raw values and macros with an enum and use it consistently.
No functional changes.
Signed-off-by: Aapo Vienamo <aapo.vienamo@iki.fi>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/thunderbolt/debugfs.c | 46 +++++++++++++++++++----------------
drivers/thunderbolt/sb_regs.h | 3 ---
drivers/thunderbolt/tb.h | 10 ++++++--
3 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/drivers/thunderbolt/debugfs.c b/drivers/thunderbolt/debugfs.c
index 5f9f8babeae2..3404237d167b 100644
--- a/drivers/thunderbolt/debugfs.c
+++ b/drivers/thunderbolt/debugfs.c
@@ -447,7 +447,7 @@ struct tb_margining {
unsigned int gen;
u32 caps[3];
u32 results[2];
- unsigned int lanes;
+ enum usb4_margining_lane lanes;
unsigned int min_ber_level;
unsigned int max_ber_level;
unsigned int ber_level;
@@ -757,13 +757,13 @@ margining_lanes_write(struct file *file, const char __user *user_buf,
}
if (!strcmp(buf, "0")) {
- margining->lanes = 0;
+ margining->lanes = USB4_MARGINING_LANE_RX0;
} else if (!strcmp(buf, "1")) {
- margining->lanes = 1;
+ margining->lanes = USB4_MARGINING_LANE_RX1;
} else if (!strcmp(buf, "all")) {
/* Needs to be supported */
if (all_lanes(margining))
- margining->lanes = 7;
+ margining->lanes = USB4_MARGINING_LANE_ALL;
else
ret = -EINVAL;
} else {
@@ -781,21 +781,21 @@ static int margining_lanes_show(struct seq_file *s, void *not_used)
{
struct tb_margining *margining = s->private;
struct tb *tb = margining->port->sw->tb;
- unsigned int lanes;
+ enum usb4_margining_lane lanes;
if (mutex_lock_interruptible(&tb->lock))
return -ERESTARTSYS;
lanes = margining->lanes;
if (all_lanes(margining)) {
- if (!lanes)
+ if (lanes == USB4_MARGINING_LANE_RX0)
seq_puts(s, "[0] 1 all\n");
- else if (lanes == 1)
+ else if (lanes == USB4_MARGINING_LANE_RX1)
seq_puts(s, "0 [1] all\n");
else
seq_puts(s, "0 1 [all]\n");
} else {
- if (!lanes)
+ if (lanes == USB4_MARGINING_LANE_RX0)
seq_puts(s, "[0] 1\n");
else
seq_puts(s, "0 [1]\n");
@@ -1089,13 +1089,13 @@ static int margining_run_sw(struct tb_margining *margining,
if (ret)
break;
- if (margining->lanes == USB4_MARGIN_SW_LANE_0)
+ if (margining->lanes == USB4_MARGINING_LANE_RX0)
errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_0_MASK,
margining->results[1]);
- else if (margining->lanes == USB4_MARGIN_SW_LANE_1)
+ else if (margining->lanes == USB4_MARGINING_LANE_RX1)
errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_1_MASK,
margining->results[1]);
- else if (margining->lanes == USB4_MARGIN_SW_ALL_LANES)
+ else if (margining->lanes == USB4_MARGINING_LANE_ALL)
errors = margining->results[1];
/* Any errors stop the test */
@@ -1225,7 +1225,7 @@ static ssize_t margining_results_write(struct file *file,
if (margining->software) {
/* Clear the error counters */
margining_modify_error_counter(margining,
- USB4_MARGIN_SW_ALL_LANES,
+ USB4_MARGINING_LANE_ALL,
USB4_MARGIN_SW_ERROR_COUNTER_CLEAR);
}
@@ -1278,7 +1278,8 @@ static int margining_results_show(struct seq_file *s, void *not_used)
seq_printf(s, "0x%08x\n", margining->results[1]);
if (margining->time) {
- if (!margining->lanes || margining->lanes == 7) {
+ if (margining->lanes == USB4_MARGINING_LANE_RX0 ||
+ margining->lanes == USB4_MARGINING_LANE_ALL) {
val = margining->results[1];
seq_puts(s, "# lane 0 right time margin: ");
time_margin_show(s, margining, val);
@@ -1287,7 +1288,8 @@ static int margining_results_show(struct seq_file *s, void *not_used)
seq_puts(s, "# lane 0 left time margin: ");
time_margin_show(s, margining, val);
}
- if (margining->lanes == 1 || margining->lanes == 7) {
+ if (margining->lanes == USB4_MARGINING_LANE_RX1 ||
+ margining->lanes == USB4_MARGINING_LANE_ALL) {
val = margining->results[1] >>
USB4_MARGIN_HW_RES_1_L1_RH_MARGIN_SHIFT;
seq_puts(s, "# lane 1 right time margin: ");
@@ -1298,7 +1300,8 @@ static int margining_results_show(struct seq_file *s, void *not_used)
time_margin_show(s, margining, val);
}
} else {
- if (!margining->lanes || margining->lanes == 7) {
+ if (margining->lanes == USB4_MARGINING_LANE_RX0 ||
+ margining->lanes == USB4_MARGINING_LANE_ALL) {
val = margining->results[1];
seq_puts(s, "# lane 0 high voltage margin: ");
voltage_margin_show(s, margining, val);
@@ -1307,7 +1310,8 @@ static int margining_results_show(struct seq_file *s, void *not_used)
seq_puts(s, "# lane 0 low voltage margin: ");
voltage_margin_show(s, margining, val);
}
- if (margining->lanes == 1 || margining->lanes == 7) {
+ if (margining->lanes == USB4_MARGINING_LANE_RX1 ||
+ margining->lanes == USB4_MARGINING_LANE_ALL) {
val = margining->results[1] >>
USB4_MARGIN_HW_RES_1_L1_RH_MARGIN_SHIFT;
seq_puts(s, "# lane 1 high voltage margin: ");
@@ -1322,16 +1326,16 @@ static int margining_results_show(struct seq_file *s, void *not_used)
u32 lane_errors, result;
seq_printf(s, "0x%08x\n", margining->results[1]);
- result = FIELD_GET(USB4_MARGIN_SW_LANES_MASK, margining->results[0]);
- if (result == USB4_MARGIN_SW_LANE_0 ||
- result == USB4_MARGIN_SW_ALL_LANES) {
+ result = FIELD_GET(USB4_MARGIN_SW_LANES_MASK, margining->results[0]);
+ if (result == USB4_MARGINING_LANE_RX0 ||
+ result == USB4_MARGINING_LANE_ALL) {
lane_errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_0_MASK,
margining->results[1]);
seq_printf(s, "# lane 0 errors: %u\n", lane_errors);
}
- if (result == USB4_MARGIN_SW_LANE_1 ||
- result == USB4_MARGIN_SW_ALL_LANES) {
+ if (result == USB4_MARGINING_LANE_RX1 ||
+ result == USB4_MARGINING_LANE_ALL) {
lane_errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_1_MASK,
margining->results[1]);
seq_printf(s, "# lane 1 errors: %u\n", lane_errors);
diff --git a/drivers/thunderbolt/sb_regs.h b/drivers/thunderbolt/sb_regs.h
index a3652b9cb246..91c6333d08c8 100644
--- a/drivers/thunderbolt/sb_regs.h
+++ b/drivers/thunderbolt/sb_regs.h
@@ -98,9 +98,6 @@ enum usb4_sb_opcode {
/* USB4_SB_OPCODE_RUN_SW_LANE_MARGINING */
#define USB4_MARGIN_SW_LANES_MASK GENMASK(2, 0)
-#define USB4_MARGIN_SW_LANE_0 0x0
-#define USB4_MARGIN_SW_LANE_1 0x1
-#define USB4_MARGIN_SW_ALL_LANES 0x7
#define USB4_MARGIN_SW_TIME BIT(3)
#define USB4_MARGIN_SW_RH BIT(4)
#define USB4_MARGIN_SW_OPT_VOLTAGE BIT(5)
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index ced9be271620..fb2e1f089169 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -1367,11 +1367,17 @@ enum usb4_margin_sw_error_counter {
USB4_MARGIN_SW_ERROR_COUNTER_STOP,
};
+enum usb4_margining_lane {
+ USB4_MARGINING_LANE_RX0 = 0,
+ USB4_MARGINING_LANE_RX1 = 1,
+ USB4_MARGINING_LANE_ALL = 7,
+};
+
/**
* struct usb4_port_margining_params - USB4 margining parameters
* @error_counter: Error counter operation for software margining
* @ber_level: Current BER level contour value
- * @lanes: %0, %1 or %7 (all)
+ * @lanes: Lanes to enable for the margining operation
* @voltage_time_offset: Offset for voltage / time for software margining
* @optional_voltage_offset_range: Enable optional extended voltage range
* @right_high: %false if left/low margin test is performed, %true if right/high
@@ -1380,7 +1386,7 @@ enum usb4_margin_sw_error_counter {
struct usb4_port_margining_params {
enum usb4_margin_sw_error_counter error_counter;
u32 ber_level;
- u32 lanes;
+ enum usb4_margining_lane lanes;
u32 voltage_time_offset;
bool optional_voltage_offset_range;
bool right_high;
--
2.45.2
next prev parent reply other threads:[~2024-10-23 10:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 10:11 [PATCH 0/8] thunderbolt: Add support for USB4 v2 Gen 4 lane margining Mika Westerberg
2024-10-23 10:11 ` [PATCH 1/8] thunderbolt: Don't hardcode margining capabilities size Mika Westerberg
2024-10-23 10:11 ` [PATCH 2/8] thunderbolt: debugfs: Add USB4 Gen 4 margining capabilities Mika Westerberg
2024-10-23 10:11 ` [PATCH 3/8] thunderbolt: debugfs: Implement Gen 4 margining eye selection Mika Westerberg
2024-10-23 10:11 ` [PATCH 4/8] thunderbolt: debugfs: Replace "both lanes" with "all lanes" Mika Westerberg
2024-10-23 10:11 ` Mika Westerberg [this message]
2024-10-23 10:11 ` [PATCH 6/8] thunderbolt: debugfs: Refactor hardware margining result parsing Mika Westerberg
2024-10-23 10:11 ` [PATCH 7/8] thunderbolt: debugfs: Don't hardcode margining results size Mika Westerberg
2024-10-23 10:11 ` [PATCH 8/8] thunderbolt: debugfs: Implement asymmetric lane margining Mika Westerberg
2024-11-01 6:00 ` [PATCH 0/8] thunderbolt: Add support for USB4 v2 Gen 4 " Mika Westerberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241023101111.3418311-6-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=aapo.vienamo@iki.fi \
--cc=andreas.noever@gmail.com \
--cc=linux-usb@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=michael.jamet@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).