Skip to content

Commit d49b4f0

Browse files
committed
thunderbolt: Add support for enhanced uni-directional TMU mode
This is new TMU mode introduced with the USB4 v2. This mode is simpler than the existing ones and allows all CL states as well. Enable this for all links where both side routers are v2 and keep the existing functionality for the v1 and earlier links. Currently only support the MedRes rate. We can add the HiFi rate later too if it turns out to be useful. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
1 parent 322ff70 commit d49b4f0

6 files changed

Lines changed: 614 additions & 173 deletions

File tree

drivers/thunderbolt/switch.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,22 @@ int tb_switch_configure(struct tb_switch *sw)
24662466
return tb_plug_events_active(sw, true);
24672467
}
24682468

2469+
/**
2470+
* tb_switch_configuration_valid() - Set the tunneling configuration to be valid
2471+
* @sw: Router to configure
2472+
*
2473+
* Needs to be called before any tunnels can be setup through the
2474+
* router. Can be called to any router.
2475+
*
2476+
* Returns %0 in success and negative errno otherwise.
2477+
*/
2478+
int tb_switch_configuration_valid(struct tb_switch *sw)
2479+
{
2480+
if (tb_switch_is_usb4(sw))
2481+
return usb4_switch_configuration_valid(sw);
2482+
return 0;
2483+
}
2484+
24692485
static int tb_switch_set_uuid(struct tb_switch *sw)
24702486
{
24712487
bool uid = false;

drivers/thunderbolt/tb.c

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,23 @@ static int tb_increase_switch_tmu_accuracy(struct device *dev, void *data)
297297
struct tb_switch *sw;
298298

299299
sw = tb_to_switch(dev);
300-
if (sw) {
301-
tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI,
302-
tb_switch_clx_is_enabled(sw, TB_CL1));
303-
if (tb_switch_tmu_enable(sw))
304-
tb_sw_warn(sw, "failed to increase TMU rate\n");
300+
if (!sw)
301+
return 0;
302+
303+
if (tb_switch_tmu_is_configured(sw, TB_SWITCH_TMU_MODE_LOWRES)) {
304+
enum tb_switch_tmu_mode mode;
305+
int ret;
306+
307+
if (tb_switch_clx_is_enabled(sw, TB_CL1))
308+
mode = TB_SWITCH_TMU_MODE_HIFI_UNI;
309+
else
310+
mode = TB_SWITCH_TMU_MODE_HIFI_BI;
311+
312+
ret = tb_switch_tmu_configure(sw, mode);
313+
if (ret)
314+
return ret;
315+
316+
return tb_switch_tmu_enable(sw);
305317
}
306318

307319
return 0;
@@ -319,6 +331,9 @@ static void tb_increase_tmu_accuracy(struct tb_tunnel *tunnel)
319331
* accuracy of first depth child routers (and the host router)
320332
* to the highest. This is needed for the DP tunneling to work
321333
* but also allows CL0s.
334+
*
335+
* If both routers are v2 then we don't need to do anything as
336+
* they are using enhanced TMU mode that allows all CLx.
322337
*/
323338
sw = tunnel->tb->root_switch;
324339
device_for_each_child(&sw->dev, NULL, tb_increase_switch_tmu_accuracy);
@@ -329,14 +344,22 @@ static int tb_enable_tmu(struct tb_switch *sw)
329344
int ret;
330345

331346
/*
332-
* If CL1 is enabled then we need to configure the TMU accuracy
333-
* level to normal. Otherwise we keep the TMU running at the
334-
* highest accuracy.
347+
* If both routers at the end of the link are v2 we simply
348+
* enable the enhanched uni-directional mode. That covers all
349+
* the CL states. For v1 and before we need to use the normal
350+
* rate to allow CL1 (when supported). Otherwise we keep the TMU
351+
* running at the highest accuracy.
335352
*/
336-
if (tb_switch_clx_is_enabled(sw, TB_CL1))
337-
ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true);
338-
else
339-
ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false);
353+
ret = tb_switch_tmu_configure(sw,
354+
TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI);
355+
if (ret == -EOPNOTSUPP) {
356+
if (tb_switch_clx_is_enabled(sw, TB_CL1))
357+
ret = tb_switch_tmu_configure(sw,
358+
TB_SWITCH_TMU_MODE_LOWRES);
359+
else
360+
ret = tb_switch_tmu_configure(sw,
361+
TB_SWITCH_TMU_MODE_HIFI_BI);
362+
}
340363
if (ret)
341364
return ret;
342365

@@ -963,6 +986,12 @@ static void tb_scan_port(struct tb_port *port)
963986
if (tb_enable_tmu(sw))
964987
tb_sw_warn(sw, "failed to enable TMU\n");
965988

989+
/*
990+
* Configuration valid needs to be set after the TMU has been
991+
* enabled for the upstream port of the router so we do it here.
992+
*/
993+
tb_switch_configuration_valid(sw);
994+
966995
/* Scan upstream retimers */
967996
tb_retimer_scan(upstream_port, true);
968997

@@ -2086,8 +2115,7 @@ static int tb_start(struct tb *tb)
20862115
* To support highest CLx state, we set host router's TMU to
20872116
* Normal mode.
20882117
*/
2089-
tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_RATE_NORMAL,
2090-
false);
2118+
tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_MODE_LOWRES);
20912119
/* Enable TMU if it is off */
20922120
tb_switch_tmu_enable(tb->root_switch);
20932121
/* Full scan to discover devices added before the driver was loaded. */
@@ -2139,6 +2167,8 @@ static void tb_restore_children(struct tb_switch *sw)
21392167
if (tb_enable_tmu(sw))
21402168
tb_sw_warn(sw, "failed to restore TMU configuration\n");
21412169

2170+
tb_switch_configuration_valid(sw);
2171+
21422172
tb_switch_for_each_port(sw, port) {
21432173
if (!tb_port_has_remote(port) && !port->xdomain)
21442174
continue;

drivers/thunderbolt/tb.h

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,44 +73,37 @@ enum tb_nvm_write_ops {
7373
#define USB4_SWITCH_MAX_DEPTH 5
7474

7575
/**
76-
* enum tb_switch_tmu_rate - TMU refresh rate
77-
* @TB_SWITCH_TMU_RATE_OFF: %0 (Disable Time Sync handshake)
78-
* @TB_SWITCH_TMU_RATE_HIFI: %16 us time interval between successive
79-
* transmission of the Delay Request TSNOS
80-
* (Time Sync Notification Ordered Set) on a Link
81-
* @TB_SWITCH_TMU_RATE_NORMAL: %1 ms time interval between successive
82-
* transmission of the Delay Request TSNOS on
83-
* a Link
76+
* enum tb_switch_tmu_mode - TMU mode
77+
* @TB_SWITCH_TMU_MODE_OFF: TMU is off
78+
* @TB_SWITCH_TMU_MODE_LOWRES: Uni-directional, normal mode
79+
* @TB_SWITCH_TMU_MODE_HIFI_UNI: Uni-directional, HiFi mode
80+
* @TB_SWITCH_TMU_MODE_HIFI_BI: Bi-directional, HiFi mode
81+
* @TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI: Enhanced Uni-directional, MedRes mode
82+
*
83+
* Ordering is based on TMU accuracy level (highest last).
8484
*/
85-
enum tb_switch_tmu_rate {
86-
TB_SWITCH_TMU_RATE_OFF = 0,
87-
TB_SWITCH_TMU_RATE_HIFI = 16,
88-
TB_SWITCH_TMU_RATE_NORMAL = 1000,
85+
enum tb_switch_tmu_mode {
86+
TB_SWITCH_TMU_MODE_OFF,
87+
TB_SWITCH_TMU_MODE_LOWRES,
88+
TB_SWITCH_TMU_MODE_HIFI_UNI,
89+
TB_SWITCH_TMU_MODE_HIFI_BI,
90+
TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI,
8991
};
9092

9193
/**
92-
* struct tb_switch_tmu - Structure holding switch TMU configuration
94+
* struct tb_switch_tmu - Structure holding router TMU configuration
9395
* @cap: Offset to the TMU capability (%0 if not found)
9496
* @has_ucap: Does the switch support uni-directional mode
95-
* @rate: TMU refresh rate related to upstream switch. In case of root
96-
* switch this holds the domain rate. Reflects the HW setting.
97-
* @unidirectional: Is the TMU in uni-directional or bi-directional mode
98-
* related to upstream switch. Don't care for root switch.
99-
* Reflects the HW setting.
100-
* @unidirectional_request: Is the new TMU mode: uni-directional or bi-directional
101-
* that is requested to be set. Related to upstream switch.
102-
* Don't care for root switch.
103-
* @rate_request: TMU new refresh rate related to upstream switch that is
104-
* requested to be set. In case of root switch, this holds
105-
* the new domain rate that is requested to be set.
97+
* @mode: TMU mode related to the upstream router. Reflects the HW
98+
* setting. Don't care for host router.
99+
* @mode_request: TMU mode requested to set. Related to upstream router.
100+
* Don't care for host router.
106101
*/
107102
struct tb_switch_tmu {
108103
int cap;
109104
bool has_ucap;
110-
enum tb_switch_tmu_rate rate;
111-
bool unidirectional;
112-
bool unidirectional_request;
113-
enum tb_switch_tmu_rate rate_request;
105+
enum tb_switch_tmu_mode mode;
106+
enum tb_switch_tmu_mode mode_request;
114107
};
115108

116109
/**
@@ -801,6 +794,7 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent,
801794
struct tb_switch *tb_switch_alloc_safe_mode(struct tb *tb,
802795
struct device *parent, u64 route);
803796
int tb_switch_configure(struct tb_switch *sw);
797+
int tb_switch_configuration_valid(struct tb_switch *sw);
804798
int tb_switch_add(struct tb_switch *sw);
805799
void tb_switch_remove(struct tb_switch *sw);
806800
void tb_switch_suspend(struct tb_switch *sw, bool runtime);
@@ -975,19 +969,33 @@ int tb_switch_tmu_init(struct tb_switch *sw);
975969
int tb_switch_tmu_post_time(struct tb_switch *sw);
976970
int tb_switch_tmu_disable(struct tb_switch *sw);
977971
int tb_switch_tmu_enable(struct tb_switch *sw);
978-
int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_rate rate,
979-
bool unidirectional);
972+
int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode);
973+
974+
/**
975+
* tb_switch_tmu_is_configured() - Is given TMU mode configured
976+
* @sw: Router whose mode to check
977+
* @mode: Mode to check
978+
*
979+
* Checks if given router TMU mode is configured to @mode. Note the
980+
* router TMU might not be enabled to this mode.
981+
*/
982+
static inline bool tb_switch_tmu_is_configured(const struct tb_switch *sw,
983+
enum tb_switch_tmu_mode mode)
984+
{
985+
return sw->tmu.mode_request == mode;
986+
}
987+
980988
/**
981989
* tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
982990
* @sw: Router whose TMU mode to check
983991
*
984992
* Return true if hardware TMU configuration matches the requested
985-
* configuration.
993+
* configuration (and is not %TB_SWITCH_TMU_MODE_OFF).
986994
*/
987995
static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw)
988996
{
989-
return sw->tmu.rate == sw->tmu.rate_request &&
990-
sw->tmu.unidirectional == sw->tmu.unidirectional_request;
997+
return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF &&
998+
sw->tmu.mode == sw->tmu.mode_request;
991999
}
9921000

9931001
bool tb_port_clx_is_enabled(struct tb_port *port, unsigned int clx);
@@ -1211,6 +1219,7 @@ static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
12111219
}
12121220

12131221
int usb4_switch_setup(struct tb_switch *sw);
1222+
int usb4_switch_configuration_valid(struct tb_switch *sw);
12141223
int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid);
12151224
int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf,
12161225
size_t size);

drivers/thunderbolt/tb_regs.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,13 @@ enum usb4_switch_op {
252252
#define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0)
253253
#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16)
254254
#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16
255-
#define TMU_RTR_CS_15 0xf
255+
#define TMU_RTR_CS_15 0x0f
256256
#define TMU_RTR_CS_15_FREQ_AVG_MASK GENMASK(5, 0)
257257
#define TMU_RTR_CS_15_DELAY_AVG_MASK GENMASK(11, 6)
258258
#define TMU_RTR_CS_15_OFFSET_AVG_MASK GENMASK(17, 12)
259259
#define TMU_RTR_CS_15_ERROR_AVG_MASK GENMASK(23, 18)
260+
#define TMU_RTR_CS_18 0x12
261+
#define TMU_RTR_CS_18_DELTA_AVG_CONST_MASK GENMASK(23, 16)
260262
#define TMU_RTR_CS_22 0x16
261263
#define TMU_RTR_CS_24 0x18
262264
#define TMU_RTR_CS_25 0x19
@@ -322,6 +324,14 @@ struct tb_regs_port_header {
322324
#define TMU_ADP_CS_3_UDM BIT(29)
323325
#define TMU_ADP_CS_6 0x06
324326
#define TMU_ADP_CS_6_DTS BIT(1)
327+
#define TMU_ADP_CS_8 0x08
328+
#define TMU_ADP_CS_8_REPL_TIMEOUT_MASK GENMASK(14, 0)
329+
#define TMU_ADP_CS_8_EUDM BIT(15)
330+
#define TMU_ADP_CS_8_REPL_THRESHOLD_MASK GENMASK(25, 16)
331+
#define TMU_ADP_CS_9 0x09
332+
#define TMU_ADP_CS_9_REPL_N_MASK GENMASK(7, 0)
333+
#define TMU_ADP_CS_9_DIRSWITCH_N_MASK GENMASK(15, 8)
334+
#define TMU_ADP_CS_9_ADP_TS_INTERVAL_MASK GENMASK(31, 16)
325335

326336
/* Lane adapter registers */
327337
#define LANE_ADP_CS_0 0x00

0 commit comments

Comments
 (0)