Skip to contentSkip to conversation

thunderbolt: Additional minor improvements

PATCH In review Mika Westerberg 1 participant 8 messages Sep 9, 2020 – Sep 16, 2020

Subsystems (2)
lore
Share & tools
lore
#2 lore raw

PATCH 3/7 thunderbolt: Use "if USB4" instead of "depends on" in Kconfig

In reply to Mika Westerberg

This groups the USB4 options more nicely, and also does not require that every config option lists explicit depends on USB4.

---
 drivers/thunderbolt/Kconfig | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/thunderbolt/Kconfig +4 -2
index afa3551633aa..7fc058f81d00 100644
@@ -16,9 +16,10 @@ menuconfig USB4
 	  To compile this driver a module, choose M here. The module will be
 	  called thunderbolt.
 
+if USB4
+
 config USB4_DEBUGFS_WRITE
 	bool "Enable write by debugfs to configuration spaces (DANGEROUS)"
-	depends on USB4
 	help
 	  Enables writing to device configuration registers through
 	  debugfs interface.
@@ -28,5 +29,6 @@ config USB4_DEBUGFS_WRITE
 
 config USB4_KUNIT_TEST
 	bool "KUnit tests"
-	depends on USB4
 	depends on KUNIT=y
+
+endif # USB4
Signature · 1 line
2.28.0
#3 lore raw

PATCH 4/7 thunderbolt: Handle ERR_LOCK notification

In reply to Mika Westerberg

If the USB4 router downstream port is locked, sending configuration packet to a router below it causes ERR_LOCK to be sent. Instead of warn splat about unknown error we log the error (just warning level) and return -EACCESS instead. The idea is that we may want to do something when such error code is received, like perform unlock.

---
 drivers/thunderbolt/ctl.c     | 7 +++++++
 drivers/thunderbolt/tb_msgs.h | 1 +
 2 files changed, 8 insertions(+)
drivers/thunderbolt/ctl.c +7 -0
index 2364efa23991..88b40b3b3ad7 100644
@@ -282,6 +282,10 @@ static void tb_cfg_print_error(struct tb_ctl *ctl,
 		tb_ctl_WARN(ctl, "CFG_ERROR(%llx:%x): Route contains a loop\n",
 			res->response_route, res->response_port);
 		return;
+	case TB_CFG_ERROR_LOCK:
+		tb_ctl_warn(ctl, "%llx:%x: downstream port is locked\n",
+			    res->response_route, res->response_port);
+		return;
 	default:
 		/* 5,6,7,9 and 11 are also valid error codes */
 		tb_ctl_WARN(ctl, "CFG_ERROR(%llx:%x): Unknown error\n",
@@ -950,6 +954,9 @@ static int tb_cfg_get_error(struct tb_ctl *ctl, enum tb_cfg_space space,
 		return -ENODEV;
 
 	tb_cfg_print_error(ctl, res);
+
+	if (res->tb_error == TB_CFG_ERROR_LOCK)
+		return -EACCES;
 	return -EIO;
 }
 
drivers/thunderbolt/tb_msgs.h +1 -0
index fc208c567953..0e01dbc63e72 100644
@@ -28,6 +28,7 @@ enum tb_cfg_error {
 	TB_CFG_ERROR_LOOP = 8,
 	TB_CFG_ERROR_HEC_ERROR_DETECTED = 12,
 	TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13,
+	TB_CFG_ERROR_LOCK = 15,
 };
 
 /* common header */
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/7 thunderbolt: Allow KUnit tests to be built also when CONFIG_USB4=m

In reply to Mika Westerberg

This adds a bit more build coverage for the tests even though these are not expected to be enabled by normal users and distros. In order to make this working we need to open-code kunit_test_suite() and call the relevant functions directly in the driver init/exit hook.

---
 drivers/thunderbolt/Kconfig  |  2 +-
 drivers/thunderbolt/Makefile |  3 +--
 drivers/thunderbolt/domain.c |  4 ++++
 drivers/thunderbolt/tb.h     |  8 ++++++++
 drivers/thunderbolt/test.c   | 13 ++++++++++++-
 5 files changed, 26 insertions(+), 4 deletions(-)
drivers/thunderbolt/Kconfig +1 -1
index 2257c22f8ab3..afa3551633aa 100644
@@ -28,5 +28,5 @@ config USB4_DEBUGFS_WRITE
 
 config USB4_KUNIT_TEST
 	bool "KUnit tests"
+	depends on USB4
 	depends on KUNIT=y
-	depends on USB4=y
drivers/thunderbolt/Makefile +1 -2
index 61d5dff445b6..571537371072 100644
@@ -6,5 +6,4 @@ thunderbolt-objs += nvm.o retimer.o quirks.o
 
 thunderbolt-${CONFIG_ACPI} += acpi.o
 thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o
-
-obj-${CONFIG_USB4_KUNIT_TEST} += test.o
+thunderbolt-${CONFIG_USB4_KUNIT_TEST} += test.o
drivers/thunderbolt/domain.c +4 -0
index a0182bf5a5f8..f0de94f7acbf 100644
@@ -827,6 +827,8 @@ int tb_domain_init(void)
 {
 	int ret;
 
+	tb_test_init();
+
 	tb_debugfs_init();
 	ret = tb_xdomain_init();
 	if (ret)
@@ -841,6 +843,7 @@ int tb_domain_init(void)
 	tb_xdomain_exit();
 err_debugfs:
 	tb_debugfs_exit();
+	tb_test_exit();
 
 	return ret;
 }
@@ -852,4 +855,5 @@ void tb_domain_exit(void)
 	tb_nvm_exit();
 	tb_xdomain_exit();
 	tb_debugfs_exit();
+	tb_test_exit();
 }
drivers/thunderbolt/tb.h +8 -0
index 8b04a9deffc7..5687bcf38a9e 100644
@@ -1030,4 +1030,12 @@ static inline void tb_switch_debugfs_init(struct tb_switch *sw) { }
 static inline void tb_switch_debugfs_remove(struct tb_switch *sw) { }
 #endif
 
+#ifdef CONFIG_USB4_KUNIT_TEST
+int tb_test_init(void);
+void tb_test_exit(void);
+#else
+static inline int tb_test_init(void) { return 0; }
+static inline void tb_test_exit(void) { }
+#endif
+
 #endif
drivers/thunderbolt/test.c +12 -1
index a4d78811f7e2..464c2d37b992 100644
@@ -1623,4 +1623,15 @@ static struct kunit_suite tb_test_suite = {
 	.name = "thunderbolt",
 	.test_cases = tb_test_cases,
 };
-kunit_test_suite(tb_test_suite);
+
+static struct kunit_suite *tb_test_suites[] = { &tb_test_suite, NULL };
+
+int tb_test_init(void)
+{
+	return __kunit_test_suites_init(tb_test_suites);
+}
+
+void tb_test_exit(void)
+{
+	return __kunit_test_suites_exit(tb_test_suites);
+}
Signature · 1 line
2.28.0
#5 lore raw

PATCH 6/7 thunderbolt: Correct tb_check_quirks() kernel-doc

In reply to Mika Westerberg

Remove extra white space and make the sentence end with a period.

---
 drivers/thunderbolt/quirks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/quirks.c +1 -1
index 7eac3e0f90a2..57e2978a3c21 100644
@@ -27,7 +27,7 @@ static const struct tb_quirk tb_quirks[] = {
  * tb_check_quirks() - Check for quirks to apply
  * @sw: Thunderbolt switch
  *
- *  Apply any quirks for the Thunderbolt controller
+ * Apply any quirks for the Thunderbolt controller.
  */
 void tb_check_quirks(struct tb_switch *sw)
 {
Signature · 1 line
2.28.0
#4 lore raw

PATCH 5/7 thunderbolt: Log correct zeroX entries in decode_error()

In reply to Mika Westerberg

There was copy & paste error so it always printed value of pkg->zero1. Also use tb_ctl_warn() here, no need to print backtrace.

---
 drivers/thunderbolt/ctl.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/thunderbolt/ctl.c +8 -3
index 88b40b3b3ad7..9894b8f63064 100644
@@ -219,6 +219,7 @@ static int check_config_address(struct tb_cfg_address addr,
 static struct tb_cfg_result decode_error(const struct ctl_pkg *response)
 {
 	struct cfg_error_pkg *pkg = response->buffer;
+	struct tb_ctl *ctl = response->ctl;
 	struct tb_cfg_result res = { 0 };
 	res.response_route = tb_cfg_get_route(&pkg->header);
 	res.response_port = 0;
@@ -227,9 +228,13 @@ static struct tb_cfg_result decode_error(const struct ctl_pkg *response)
 	if (res.err)
 		return res;
 
-	WARN(pkg->zero1, "pkg->zero1 is %#x\n", pkg->zero1);
-	WARN(pkg->zero2, "pkg->zero1 is %#x\n", pkg->zero1);
-	WARN(pkg->zero3, "pkg->zero1 is %#x\n", pkg->zero1);
+	if (pkg->zero1)
+		tb_ctl_warn(ctl, "pkg->zero1 is %#x\n", pkg->zero1);
+	if (pkg->zero2)
+		tb_ctl_warn(ctl, "pkg->zero2 is %#x\n", pkg->zero2);
+	if (pkg->zero3)
+		tb_ctl_warn(ctl, "pkg->zero3 is %#x\n", pkg->zero3);
+
 	res.err = 1;
 	res.tb_error = pkg->error;
 	res.response_port = pkg->port;
Signature · 1 line
2.28.0
#6 lore raw

PATCH 7/7 thunderbolt: Capitalize comment on top of QUIRK_FORCE_POWER_LINK_CONTROLLER

In reply to Mika Westerberg

To keep it consistent with the other single line comments in the driver.

---
 drivers/thunderbolt/tb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tb.h +1 -1
index 5687bcf38a9e..7754b0b2ea66 100644
@@ -1007,7 +1007,7 @@ int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,
 				     int *downstream_bw);
 
-/* keep link controller awake during update */
+/* Keep link controller awake during update */
 #define QUIRK_FORCE_POWER_LINK_CONTROLLER		BIT(0)
 
 void tb_check_quirks(struct tb_switch *sw);
Signature · 1 line
2.28.0
#0 lore raw

cover thunderbolt: Additional minor improvements

Hi all,

This series has some additional minor improvements and cleanups from my internal development tree. All of this is v5.10 material and apply on top of thunderbolt.git/next.

Mika Westerberg (7):
thunderbolt: Only stop control channel when entering freeze
thunderbolt: Allow KUnit tests to be built also when CONFIG_USB4=m
thunderbolt: Use "if USB4" instead of "depends on" in Kconfig
thunderbolt: Handle ERR_LOCK notification
thunderbolt: Log correct zeroX entries in decode_error()
thunderbolt: Correct tb_check_quirks() kernel-doc
thunderbolt: Capitalize comment on top of QUIRK_FORCE_POWER_LINK_CONTROLLER

 drivers/thunderbolt/Kconfig   |  6 ++++--
 drivers/thunderbolt/Makefile  |  3 +--
 drivers/thunderbolt/ctl.c     | 18 +++++++++++++++---
 drivers/thunderbolt/domain.c  | 31 +++++++++++++++++++++++++++++++
 drivers/thunderbolt/nhi.c     | 21 ++++++++++++++++++---
 drivers/thunderbolt/quirks.c  |  2 +-
 drivers/thunderbolt/tb.c      | 18 ++++++++++++++++++
 drivers/thunderbolt/tb.h      | 16 +++++++++++++++-
 drivers/thunderbolt/tb_msgs.h |  1 +
 drivers/thunderbolt/test.c    | 13 ++++++++++++-
 10 files changed, 116 insertions(+), 13 deletions(-)
Signature · 1 line
2.28.0
#7 lore raw
Quoted 15 lines · Mika Westerberg

Hi all,

This series has some additional minor improvements and cleanups from my internal development tree. All of this is v5.10 material and apply on top of thunderbolt.git/next.

Mika Westerberg (7):
thunderbolt: Only stop control channel when entering freeze
thunderbolt: Allow KUnit tests to be built also when CONFIG_USB4=m
thunderbolt: Use "if USB4" instead of "depends on" in Kconfig
thunderbolt: Handle ERR_LOCK notification
thunderbolt: Log correct zeroX entries in decode_error()
thunderbolt: Correct tb_check_quirks() kernel-doc
thunderbolt: Capitalize comment on top of QUIRK_FORCE_POWER_LINK_CONTROLLER

Quoted 11 lines
 drivers/thunderbolt/Kconfig   |  6 ++++--
 drivers/thunderbolt/Makefile  |  3 +--
 drivers/thunderbolt/ctl.c     | 18 +++++++++++++++---
 drivers/thunderbolt/domain.c  | 31 +++++++++++++++++++++++++++++++
 drivers/thunderbolt/nhi.c     | 21 ++++++++++++++++++---
 drivers/thunderbolt/quirks.c  |  2 +-
 drivers/thunderbolt/tb.c      | 18 ++++++++++++++++++
 drivers/thunderbolt/tb.h      | 16 +++++++++++++++-
 drivers/thunderbolt/tb_msgs.h |  1 +
 drivers/thunderbolt/test.c    | 13 ++++++++++++-
 10 files changed, 116 insertions(+), 13 deletions(-)

All applied to thunderbolt.git/next.