Commit d49b4f04 authored by Mika Westerberg's avatar Mika Westerberg
Browse files

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: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent 322ff701
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -2466,6 +2466,22 @@ int tb_switch_configure(struct tb_switch *sw)
	return tb_plug_events_active(sw, true);
}

/**
 * tb_switch_configuration_valid() - Set the tunneling configuration to be valid
 * @sw: Router to configure
 *
 * Needs to be called before any tunnels can be setup through the
 * router. Can be called to any router.
 *
 * Returns %0 in success and negative errno otherwise.
 */
int tb_switch_configuration_valid(struct tb_switch *sw)
{
	if (tb_switch_is_usb4(sw))
		return usb4_switch_configuration_valid(sw);
	return 0;
}

static int tb_switch_set_uuid(struct tb_switch *sw)
{
	bool uid = false;
+44 −14
Original line number Diff line number Diff line
@@ -297,11 +297,23 @@ static int tb_increase_switch_tmu_accuracy(struct device *dev, void *data)
	struct tb_switch *sw;

	sw = tb_to_switch(dev);
	if (sw) {
		tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI,
					tb_switch_clx_is_enabled(sw, TB_CL1));
		if (tb_switch_tmu_enable(sw))
			tb_sw_warn(sw, "failed to increase TMU rate\n");
	if (!sw)
		return 0;

	if (tb_switch_tmu_is_configured(sw, TB_SWITCH_TMU_MODE_LOWRES)) {
		enum tb_switch_tmu_mode mode;
		int ret;

		if (tb_switch_clx_is_enabled(sw, TB_CL1))
			mode = TB_SWITCH_TMU_MODE_HIFI_UNI;
		else
			mode = TB_SWITCH_TMU_MODE_HIFI_BI;

		ret = tb_switch_tmu_configure(sw, mode);
		if (ret)
			return ret;

		return tb_switch_tmu_enable(sw);
	}

	return 0;
@@ -319,6 +331,9 @@ static void tb_increase_tmu_accuracy(struct tb_tunnel *tunnel)
	 * accuracy of first depth child routers (and the host router)
	 * to the highest. This is needed for the DP tunneling to work
	 * but also allows CL0s.
	 *
	 * If both routers are v2 then we don't need to do anything as
	 * they are using enhanced TMU mode that allows all CLx.
	 */
	sw = tunnel->tb->root_switch;
	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)
	int ret;

	/*
	 * If CL1 is enabled then we need to configure the TMU accuracy
	 * level to normal. Otherwise we keep the TMU running at the
	 * highest accuracy.
	 * If both routers at the end of the link are v2 we simply
	 * enable the enhanched uni-directional mode. That covers all
	 * the CL states. For v1 and before we need to use the normal
	 * rate to allow CL1 (when supported). Otherwise we keep the TMU
	 * running at the highest accuracy.
	 */
	ret = tb_switch_tmu_configure(sw,
			TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI);
	if (ret == -EOPNOTSUPP) {
		if (tb_switch_clx_is_enabled(sw, TB_CL1))
		ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true);
			ret = tb_switch_tmu_configure(sw,
					TB_SWITCH_TMU_MODE_LOWRES);
		else
		ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false);
			ret = tb_switch_tmu_configure(sw,
					TB_SWITCH_TMU_MODE_HIFI_BI);
	}
	if (ret)
		return ret;

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

	/*
	 * Configuration valid needs to be set after the TMU has been
	 * enabled for the upstream port of the router so we do it here.
	 */
	tb_switch_configuration_valid(sw);

	/* Scan upstream retimers */
	tb_retimer_scan(upstream_port, true);

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

	tb_switch_configuration_valid(sw);

	tb_switch_for_each_port(sw, port) {
		if (!tb_port_has_remote(port) && !port->xdomain)
			continue;
+42 −33
Original line number Diff line number Diff line
@@ -73,44 +73,37 @@ enum tb_nvm_write_ops {
#define USB4_SWITCH_MAX_DEPTH		5

/**
 * enum tb_switch_tmu_rate - TMU refresh rate
 * @TB_SWITCH_TMU_RATE_OFF: %0 (Disable Time Sync handshake)
 * @TB_SWITCH_TMU_RATE_HIFI: %16 us time interval between successive
 *			     transmission of the Delay Request TSNOS
 *			     (Time Sync Notification Ordered Set) on a Link
 * @TB_SWITCH_TMU_RATE_NORMAL: %1 ms time interval between successive
 *			       transmission of the Delay Request TSNOS on
 *			       a Link
 * enum tb_switch_tmu_mode - TMU mode
 * @TB_SWITCH_TMU_MODE_OFF: TMU is off
 * @TB_SWITCH_TMU_MODE_LOWRES: Uni-directional, normal mode
 * @TB_SWITCH_TMU_MODE_HIFI_UNI: Uni-directional, HiFi mode
 * @TB_SWITCH_TMU_MODE_HIFI_BI: Bi-directional, HiFi mode
 * @TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI: Enhanced Uni-directional, MedRes mode
 *
 * Ordering is based on TMU accuracy level (highest last).
 */
enum tb_switch_tmu_rate {
	TB_SWITCH_TMU_RATE_OFF = 0,
	TB_SWITCH_TMU_RATE_HIFI = 16,
	TB_SWITCH_TMU_RATE_NORMAL = 1000,
enum tb_switch_tmu_mode {
	TB_SWITCH_TMU_MODE_OFF,
	TB_SWITCH_TMU_MODE_LOWRES,
	TB_SWITCH_TMU_MODE_HIFI_UNI,
	TB_SWITCH_TMU_MODE_HIFI_BI,
	TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI,
};

/**
 * struct tb_switch_tmu - Structure holding switch TMU configuration
 * struct tb_switch_tmu - Structure holding router TMU configuration
 * @cap: Offset to the TMU capability (%0 if not found)
 * @has_ucap: Does the switch support uni-directional mode
 * @rate: TMU refresh rate related to upstream switch. In case of root
 *	  switch this holds the domain rate. Reflects the HW setting.
 * @unidirectional: Is the TMU in uni-directional or bi-directional mode
 *		    related to upstream switch. Don't care for root switch.
 *		    Reflects the HW setting.
 * @unidirectional_request: Is the new TMU mode: uni-directional or bi-directional
 *			    that is requested to be set. Related to upstream switch.
 *			    Don't care for root switch.
 * @rate_request: TMU new refresh rate related to upstream switch that is
 *		  requested to be set. In case of root switch, this holds
 *		  the new domain rate that is requested to be set.
 * @mode: TMU mode related to the upstream router. Reflects the HW
 *	  setting. Don't care for host router.
 * @mode_request: TMU mode requested to set. Related to upstream router.
 *		   Don't care for host router.
 */
struct tb_switch_tmu {
	int cap;
	bool has_ucap;
	enum tb_switch_tmu_rate rate;
	bool unidirectional;
	bool unidirectional_request;
	enum tb_switch_tmu_rate rate_request;
	enum tb_switch_tmu_mode mode;
	enum tb_switch_tmu_mode mode_request;
};

/**
@@ -801,6 +794,7 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent,
struct tb_switch *tb_switch_alloc_safe_mode(struct tb *tb,
			struct device *parent, u64 route);
int tb_switch_configure(struct tb_switch *sw);
int tb_switch_configuration_valid(struct tb_switch *sw);
int tb_switch_add(struct tb_switch *sw);
void tb_switch_remove(struct tb_switch *sw);
void tb_switch_suspend(struct tb_switch *sw, bool runtime);
@@ -975,19 +969,33 @@ int tb_switch_tmu_init(struct tb_switch *sw);
int tb_switch_tmu_post_time(struct tb_switch *sw);
int tb_switch_tmu_disable(struct tb_switch *sw);
int tb_switch_tmu_enable(struct tb_switch *sw);
int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_rate rate,
			    bool unidirectional);
int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode);

/**
 * tb_switch_tmu_is_configured() - Is given TMU mode configured
 * @sw: Router whose mode to check
 * @mode: Mode to check
 *
 * Checks if given router TMU mode is configured to @mode. Note the
 * router TMU might not be enabled to this mode.
 */
static inline bool tb_switch_tmu_is_configured(const struct tb_switch *sw,
					       enum tb_switch_tmu_mode mode)
{
	return sw->tmu.mode_request == mode;
}

/**
 * tb_switch_tmu_is_enabled() - Checks if the specified TMU mode is enabled
 * @sw: Router whose TMU mode to check
 *
 * Return true if hardware TMU configuration matches the requested
 * configuration.
 * configuration (and is not %TB_SWITCH_TMU_MODE_OFF).
 */
static inline bool tb_switch_tmu_is_enabled(const struct tb_switch *sw)
{
	return sw->tmu.rate == sw->tmu.rate_request &&
	       sw->tmu.unidirectional == sw->tmu.unidirectional_request;
	return sw->tmu.mode != TB_SWITCH_TMU_MODE_OFF &&
	       sw->tmu.mode == sw->tmu.mode_request;
}

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)
}

int usb4_switch_setup(struct tb_switch *sw);
int usb4_switch_configuration_valid(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,
			  size_t size);
+11 −1
Original line number Diff line number Diff line
@@ -252,11 +252,13 @@ enum usb4_switch_op {
#define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK		GENMASK(15, 0)
#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK	GENMASK(31, 16)
#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT	16
#define TMU_RTR_CS_15				0xf
#define TMU_RTR_CS_15				0x0f
#define TMU_RTR_CS_15_FREQ_AVG_MASK		GENMASK(5, 0)
#define TMU_RTR_CS_15_DELAY_AVG_MASK		GENMASK(11, 6)
#define TMU_RTR_CS_15_OFFSET_AVG_MASK		GENMASK(17, 12)
#define TMU_RTR_CS_15_ERROR_AVG_MASK		GENMASK(23, 18)
#define TMU_RTR_CS_18				0x12
#define TMU_RTR_CS_18_DELTA_AVG_CONST_MASK	GENMASK(23, 16)
#define TMU_RTR_CS_22				0x16
#define TMU_RTR_CS_24				0x18
#define TMU_RTR_CS_25				0x19
@@ -322,6 +324,14 @@ struct tb_regs_port_header {
#define TMU_ADP_CS_3_UDM			BIT(29)
#define TMU_ADP_CS_6				0x06
#define TMU_ADP_CS_6_DTS			BIT(1)
#define TMU_ADP_CS_8				0x08
#define TMU_ADP_CS_8_REPL_TIMEOUT_MASK		GENMASK(14, 0)
#define TMU_ADP_CS_8_EUDM			BIT(15)
#define TMU_ADP_CS_8_REPL_THRESHOLD_MASK	GENMASK(25, 16)
#define TMU_ADP_CS_9				0x09
#define TMU_ADP_CS_9_REPL_N_MASK		GENMASK(7, 0)
#define TMU_ADP_CS_9_DIRSWITCH_N_MASK		GENMASK(15, 8)
#define TMU_ADP_CS_9_ADP_TS_INTERVAL_MASK	GENMASK(31, 16)

/* Lane adapter registers */
#define LANE_ADP_CS_0				0x00
+471 −124

File changed.

Preview size limit exceeded, changes collapsed.

Loading