thunderbolt: Make is_gen4_link() available to the rest of the driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Gil Fine <gil.fine@xxxxxxxxxxxxxxx>

[ Upstream commit aa673d606078da36ebc379f041c794228ac08cb5 ]

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@xxxxxxxxxxxxxxx>
Signed-off-by: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>
Signed-off-by: Qin Wan <qin.wan@xxxxxx>
Signed-off-by: Alexandru Gagniuc <alexandru.gagniuc@xxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/thunderbolt/switch.c |   36 +++++++++++++++++++++++++++++-------
 drivers/thunderbolt/tb.h     |    1 +
 2 files changed, 30 insertions(+), 7 deletions(-)

--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -922,6 +922,32 @@ int tb_port_get_link_speed(struct tb_por
 }
 
 /**
+ * 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)
  *
@@ -966,11 +992,6 @@ static bool tb_port_is_width_supported(s
 	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
@@ -998,7 +1019,7 @@ int tb_port_set_link_width(struct tb_por
 	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;
@@ -1147,7 +1168,8 @@ int tb_port_wait_for_link_width(struct t
 	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 {
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -1062,6 +1062,7 @@ static inline bool tb_port_use_credit_al
 	     (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);


Patches currently in stable-queue which might be from alexandru.gagniuc@xxxxxx are

queue-6.6/thunderbolt-introduce-tb_switch_depth.patch
queue-6.6/thunderbolt-fix-debug-log-when-displayport-adapter-not-available-for-pairing.patch
queue-6.6/thunderbolt-change-bandwidth-reservations-to-comply-usb4-v2.patch
queue-6.6/thunderbolt-configure-asymmetric-link-if-needed-and-bandwidth-allows.patch
queue-6.6/thunderbolt-make-is_gen4_link-available-to-the-rest-of-the-driver.patch
queue-6.6/thunderbolt-add-support-for-asymmetric-link.patch
queue-6.6/thunderbolt-introduce-tb_for_each_upstream_port_on_path.patch
queue-6.6/thunderbolt-improve-displayport-tunnel-setup-process-to-be-more-robust.patch
queue-6.6/thunderbolt-expose-tb_tunnel_xxx-log-macros-to-the-rest-of-the-driver.patch
queue-6.6/thunderbolt-use-constants-for-path-weight-and-priority.patch
queue-6.6/thunderbolt-introduce-tb_port_path_direction_downstream.patch
queue-6.6/thunderbolt-use-weight-constants-in-tb_usb3_consumed_bandwidth.patch
queue-6.6/thunderbolt-create-multiple-displayport-tunnels-if-there-are-more-dp-in-out-pairs.patch
queue-6.6/thunderbolt-use-tb_tunnel_dbg-where-possible-to-make-logging-more-consistent.patch




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux