thunderbolt: Identify USB4 v2 routers
authorGil Fine <gil.fine@intel.com>
Thu, 22 Sep 2022 22:30:43 +0000 (01:30 +0300)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Fri, 16 Jun 2023 06:53:27 +0000 (09:53 +0300)
Add a new function usb4_switch_version() that can be used to figure out
the spec version of the router and make tb_switch_is_usb4() to use it as
well. 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
drivers/thunderbolt/tb.h
drivers/thunderbolt/tb_regs.h

index 47961afdcc735d7517c1d3f69edd95a029da5eb1..3a1fc3e053f6fedef1557f8f99941c152be8601e 100644 (file)
@@ -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;
        }
 
index 58df106aaa5edbfc0838c206c8bf8526e9f8bee8..bc91fcf5f430e8b70b44a202f1096be079d990f5 100644 (file)
@@ -947,17 +947,6 @@ static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw)
        return false;
 }
 
-/**
- * tb_switch_is_usb4() - Is the switch USB4 compliant
- * @sw: Switch to check
- *
- * Returns true if the @sw is USB4 compliant router, false otherwise.
- */
-static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
-{
-       return sw->config.thunderbolt_version == USB4_VERSION_1_0;
-}
-
 /**
  * tb_switch_is_icm() - Is the switch handled by ICM firmware
  * @sw: Switch to check
@@ -1198,6 +1187,29 @@ 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);
+}
+
+/**
+ * tb_switch_is_usb4() - Is the switch USB4 compliant
+ * @sw: Switch to check
+ *
+ * Returns true if the @sw is USB4 compliant router, false otherwise.
+ */
+static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
+{
+       return usb4_switch_version(sw) > 0;
+}
+
 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,
index 2636423748cdd7e163acc59d3400b8a80fda55ef..0716d6b7701a10824ab9f4ed072913b10e0c1987 100644 (file)
@@ -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