thunderbolt: Make is_gen4_link() available to the rest of the driver
authorGil Fine <gil.fine@linux.intel.com>
Mon, 31 Jul 2023 02:25:39 +0000 (05:25 +0300)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Fri, 20 Oct 2023 15:18:01 +0000 (18:18 +0300)
Rework the function to return the link generation, update the name to
tb_port_get_link_generation(), and make available to the rest of the
driver. This is needed in the subsequent patches.

Signed-off-by: Gil Fine <gil.fine@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/switch.c
drivers/thunderbolt/tb.h

index d63ead24c349de51d5bc04a52bc6118fdbdfe967..9bd13ea87c9cfdac99b6b4f3ed8421a17927bfa8 100644 (file)
@@ -915,6 +915,32 @@ int tb_port_get_link_speed(struct tb_port *port)
        }
 }
 
+/**
+ * tb_port_get_link_generation() - Returns link generation
+ * @port: Lane adapter
+ *
+ * Returns link generation as number or negative errno in case of
+ * failure. Does not distinguish between Thunderbolt 1 and Thunderbolt 2
+ * links so for those always returns 2.
+ */
+int tb_port_get_link_generation(struct tb_port *port)
+{
+       int ret;
+
+       ret = tb_port_get_link_speed(port);
+       if (ret < 0)
+               return ret;
+
+       switch (ret) {
+       case 40:
+               return 4;
+       case 20:
+               return 3;
+       default:
+               return 2;
+       }
+}
+
 /**
  * tb_port_get_link_width() - Get current link width
  * @port: Port to check (USB4 or CIO)
@@ -960,11 +986,6 @@ static bool tb_port_is_width_supported(struct tb_port *port,
        return widths & width_mask;
 }
 
-static bool is_gen4_link(struct tb_port *port)
-{
-       return tb_port_get_link_speed(port) > 20;
-}
-
 /**
  * tb_port_set_link_width() - Set target link width of the lane adapter
  * @port: Lane adapter
@@ -992,7 +1013,7 @@ int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width)
        switch (width) {
        case TB_LINK_WIDTH_SINGLE:
                /* Gen 4 link cannot be single */
-               if (is_gen4_link(port))
+               if (tb_port_get_link_generation(port) >= 4)
                        return -EOPNOTSUPP;
                val |= LANE_ADP_CS_1_TARGET_WIDTH_SINGLE <<
                        LANE_ADP_CS_1_TARGET_WIDTH_SHIFT;
@@ -1141,7 +1162,8 @@ int tb_port_wait_for_link_width(struct tb_port *port, unsigned int width_mask,
        int ret;
 
        /* Gen 4 link does not support single lane */
-       if ((width_mask & TB_LINK_WIDTH_SINGLE) && is_gen4_link(port))
+       if ((width_mask & TB_LINK_WIDTH_SINGLE) &&
+           tb_port_get_link_generation(port) >= 4)
                return -EOPNOTSUPP;
 
        do {
index 6f15b3a3e990b03e12e1244541ff58c30ded25a9..f29bbafb977f9d277283aa8e9cff859eb347ee9e 100644 (file)
@@ -1057,6 +1057,7 @@ static inline bool tb_port_use_credit_allocation(const struct tb_port *port)
             (p) = tb_next_port_on_path((src), (dst), (p)))
 
 int tb_port_get_link_speed(struct tb_port *port);
+int tb_port_get_link_generation(struct tb_port *port);
 int tb_port_get_link_width(struct tb_port *port);
 int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width);
 int tb_port_lane_bonding_enable(struct tb_port *port);