Skip to content

Commit aa673d6

Browse files
Gil Finewesteri
authored andcommitted
thunderbolt: Make is_gen4_link() available to the rest of the driver
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>
1 parent 4d24db0 commit aa673d6

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

drivers/thunderbolt/switch.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,32 @@ int tb_port_get_link_speed(struct tb_port *port)
915915
}
916916
}
917917

918+
/**
919+
* tb_port_get_link_generation() - Returns link generation
920+
* @port: Lane adapter
921+
*
922+
* Returns link generation as number or negative errno in case of
923+
* failure. Does not distinguish between Thunderbolt 1 and Thunderbolt 2
924+
* links so for those always returns 2.
925+
*/
926+
int tb_port_get_link_generation(struct tb_port *port)
927+
{
928+
int ret;
929+
930+
ret = tb_port_get_link_speed(port);
931+
if (ret < 0)
932+
return ret;
933+
934+
switch (ret) {
935+
case 40:
936+
return 4;
937+
case 20:
938+
return 3;
939+
default:
940+
return 2;
941+
}
942+
}
943+
918944
/**
919945
* tb_port_get_link_width() - Get current link width
920946
* @port: Port to check (USB4 or CIO)
@@ -960,11 +986,6 @@ static bool tb_port_is_width_supported(struct tb_port *port,
960986
return widths & width_mask;
961987
}
962988

963-
static bool is_gen4_link(struct tb_port *port)
964-
{
965-
return tb_port_get_link_speed(port) > 20;
966-
}
967-
968989
/**
969990
* tb_port_set_link_width() - Set target link width of the lane adapter
970991
* @port: Lane adapter
@@ -992,7 +1013,7 @@ int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width)
9921013
switch (width) {
9931014
case TB_LINK_WIDTH_SINGLE:
9941015
/* Gen 4 link cannot be single */
995-
if (is_gen4_link(port))
1016+
if (tb_port_get_link_generation(port) >= 4)
9961017
return -EOPNOTSUPP;
9971018
val |= LANE_ADP_CS_1_TARGET_WIDTH_SINGLE <<
9981019
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,
11411162
int ret;
11421163

11431164
/* Gen 4 link does not support single lane */
1144-
if ((width_mask & TB_LINK_WIDTH_SINGLE) && is_gen4_link(port))
1165+
if ((width_mask & TB_LINK_WIDTH_SINGLE) &&
1166+
tb_port_get_link_generation(port) >= 4)
11451167
return -EOPNOTSUPP;
11461168

11471169
do {

drivers/thunderbolt/tb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ static inline bool tb_port_use_credit_allocation(const struct tb_port *port)
10571057
(p) = tb_next_port_on_path((src), (dst), (p)))
10581058

10591059
int tb_port_get_link_speed(struct tb_port *port);
1060+
int tb_port_get_link_generation(struct tb_port *port);
10601061
int tb_port_get_link_width(struct tb_port *port);
10611062
int tb_port_set_link_width(struct tb_port *port, enum tb_link_width width);
10621063
int tb_port_lane_bonding_enable(struct tb_port *port);

0 commit comments

Comments
 (0)