diff mbox series

[03/20] thunderbolt: Identify USB4 v2 routers

Message ID 20230531090645.5573-4-mika.westerberg@linux.intel.com (mailing list archive)
State Superseded
Headers show
Series thunderbolt: Initial USB4 v2 support | expand

Commit Message

Mika Westerberg May 31, 2023, 9:06 a.m. UTC
From: Gil Fine <gil.fine@intel.com>

Update tb_switch_is_usb4() to support version 2 routers and add a new
function usb4_switch_version() that can be used to figure out the spec
version of the router. Update the uevent accordingly.

Signed-off-by: Gil Fine <gil.fine@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/switch.c  |  5 +++--
 drivers/thunderbolt/tb.h      | 15 ++++++++++++++-
 drivers/thunderbolt/tb_regs.h |  4 ++--
 3 files changed, 19 insertions(+), 5 deletions(-)

Comments

Yehezkel Bernat May 31, 2023, noon UTC | #1
On Wed, May 31, 2023 at 12:06 PM Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
>
> diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
> index 2bda2816ff47..e27fcdf50581 100644
> --- a/drivers/thunderbolt/tb.h
> +++ b/drivers/thunderbolt/tb.h
> @@ -955,7 +955,8 @@ static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw)
>   */
>  static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
>  {
> -       return sw->config.thunderbolt_version == USB4_VERSION_1_0;
> +       return FIELD_GET(USB4_VERSION_MAJOR_MASK,
> +                        sw->config.thunderbolt_version) > 0;

Does it make sense to reuse the function below i.e. `return
usb4_switch_version(sw) > 0;`?
Mika Westerberg June 2, 2023, 8:18 a.m. UTC | #2
On Wed, May 31, 2023 at 03:00:22PM +0300, Yehezkel Bernat wrote:
> On Wed, May 31, 2023 at 12:06 PM Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> >
> > diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
> > index 2bda2816ff47..e27fcdf50581 100644
> > --- a/drivers/thunderbolt/tb.h
> > +++ b/drivers/thunderbolt/tb.h
> > @@ -955,7 +955,8 @@ static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw)
> >   */
> >  static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
> >  {
> > -       return sw->config.thunderbolt_version == USB4_VERSION_1_0;
> > +       return FIELD_GET(USB4_VERSION_MAJOR_MASK,
> > +                        sw->config.thunderbolt_version) > 0;
> 
> Does it make sense to reuse the function below i.e. `return
> usb4_switch_version(sw) > 0;`?

Yes, I think it does. I'll change this.
diff mbox series

Patch

diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 47961afdcc73..3a1fc3e053f6 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -2056,8 +2056,9 @@  static int tb_switch_uevent(const struct device *dev, struct kobj_uevent_env *en
 	const struct tb_switch *sw = tb_to_switch(dev);
 	const char *type;
 
-	if (sw->config.thunderbolt_version == USB4_VERSION_1_0) {
-		if (add_uevent_var(env, "USB4_VERSION=1.0"))
+	if (tb_switch_is_usb4(sw)) {
+		if (add_uevent_var(env, "USB4_VERSION=%u.0",
+				   usb4_switch_version(sw)))
 			return -ENOMEM;
 	}
 
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index 2bda2816ff47..e27fcdf50581 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -955,7 +955,8 @@  static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw)
  */
 static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
 {
-	return sw->config.thunderbolt_version == USB4_VERSION_1_0;
+	return FIELD_GET(USB4_VERSION_MAJOR_MASK,
+			 sw->config.thunderbolt_version) > 0;
 }
 
 /**
@@ -1198,6 +1199,18 @@  static inline struct tb_retimer *tb_to_retimer(struct device *dev)
 	return NULL;
 }
 
+/**
+ * usb4_switch_version() - Returns USB4 version of the router
+ * @sw: Router to check
+ *
+ * Returns major version of USB4 router (%1 for v1, %2 for v2 and so
+ * on). Can be called to pre-USB4 router too and in that case returns %0.
+ */
+static inline unsigned int usb4_switch_version(const struct tb_switch *sw)
+{
+	return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version);
+}
+
 int usb4_switch_setup(struct tb_switch *sw);
 int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid);
 int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf,
diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h
index 2636423748cd..0716d6b7701a 100644
--- a/drivers/thunderbolt/tb_regs.h
+++ b/drivers/thunderbolt/tb_regs.h
@@ -190,8 +190,8 @@  struct tb_regs_switch_header {
 	u32 thunderbolt_version:8;
 } __packed;
 
-/* USB4 version 1.0 */
-#define USB4_VERSION_1_0			0x20
+/* Used with the router thunderbolt_version */
+#define USB4_VERSION_MAJOR_MASK			GENMASK(7, 5)
 
 #define ROUTER_CS_1				0x01
 #define ROUTER_CS_4				0x04