Commit 7ce54221 authored by Gil Fine's avatar Gil Fine Committed by Mika Westerberg
Browse files

thunderbolt: Introduce tb_switch_downstream_port()



Introduce tb_switch_downstream_port() helper function that returns the
downstream port of a parent switch that is connected to the upstream
port of specified switch. From now on, we use it all across the driver
where applicable.

While there fix a whitespace in comment and rename 'downstream' to
'down' to be consistent with the rest of the driver.

Signed-off-by: default avatarGil Fine <gil.fine@intel.com>
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent ef65afa0
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -296,16 +296,15 @@ static bool tb_acpi_bus_match(struct device *dev)

static struct acpi_device *tb_acpi_switch_find_companion(struct tb_switch *sw)
{
	struct tb_switch *parent_sw = tb_switch_parent(sw);
	struct acpi_device *adev = NULL;
	struct tb_switch *parent_sw;

	/*
	 * Device routers exists under the downstream facing USB4 port
	 * of the parent router. Their _ADR is always 0.
	 */
	parent_sw = tb_switch_parent(sw);
	if (parent_sw) {
		struct tb_port *port = tb_port_at(tb_route(sw), parent_sw);
		struct tb_port *port = tb_switch_downstream_port(sw);
		struct acpi_device *port_adev;

		port_adev = acpi_find_child_by_adr(ACPI_COMPANION(&parent_sw->dev),
+10 −14
Original line number Diff line number Diff line
@@ -644,12 +644,13 @@ static int add_switch(struct tb_switch *parent_sw, struct tb_switch *sw)
	return ret;
}

static void update_switch(struct tb_switch *parent_sw, struct tb_switch *sw,
			  u64 route, u8 connection_id, u8 connection_key,
			  u8 link, u8 depth, bool boot)
static void update_switch(struct tb_switch *sw, u64 route, u8 connection_id,
			  u8 connection_key, u8 link, u8 depth, bool boot)
{
	struct tb_switch *parent_sw = tb_switch_parent(sw);

	/* Disconnect from parent */
	tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
	tb_switch_downstream_port(sw)->remote = NULL;
	/* Re-connect via updated port */
	tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw);

@@ -671,10 +672,7 @@ static void update_switch(struct tb_switch *parent_sw, struct tb_switch *sw,

static void remove_switch(struct tb_switch *sw)
{
	struct tb_switch *parent_sw;

	parent_sw = tb_to_switch(sw->dev.parent);
	tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
	tb_switch_downstream_port(sw)->remote = NULL;
	tb_switch_remove(sw);
}

@@ -755,7 +753,6 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
	if (sw) {
		u8 phy_port, sw_phy_port;

		parent_sw = tb_to_switch(sw->dev.parent);
		sw_phy_port = tb_phy_port_from_link(sw->link);
		phy_port = tb_phy_port_from_link(link);

@@ -785,7 +782,7 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
				route = tb_route(sw);
			}

			update_switch(parent_sw, sw, route, pkg->connection_id,
			update_switch(sw, route, pkg->connection_id,
				      pkg->connection_key, link, depth, boot);
			tb_switch_put(sw);
			return;
@@ -1236,9 +1233,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr,
	if (sw) {
		/* Update the switch if it is still in the same place */
		if (tb_route(sw) == route && !!sw->authorized == authorized) {
			parent_sw = tb_to_switch(sw->dev.parent);
			update_switch(parent_sw, sw, route, pkg->connection_id,
				      0, 0, 0, boot);
			update_switch(sw, route, pkg->connection_id, 0, 0, 0,
				      boot);
			tb_switch_put(sw);
			return;
		}
+7 −12
Original line number Diff line number Diff line
@@ -2754,7 +2754,6 @@ static int tb_switch_update_link_attributes(struct tb_switch *sw)
 */
int tb_switch_lane_bonding_enable(struct tb_switch *sw)
{
	struct tb_switch *parent = tb_to_switch(sw->dev.parent);
	struct tb_port *up, *down;
	u64 route = tb_route(sw);
	int ret;
@@ -2766,7 +2765,7 @@ int tb_switch_lane_bonding_enable(struct tb_switch *sw)
		return 0;

	up = tb_upstream_port(sw);
	down = tb_port_at(route, parent);
	down = tb_switch_downstream_port(sw);

	if (!tb_port_is_width_supported(up, 2) ||
	    !tb_port_is_width_supported(down, 2))
@@ -2808,7 +2807,6 @@ int tb_switch_lane_bonding_enable(struct tb_switch *sw)
 */
void tb_switch_lane_bonding_disable(struct tb_switch *sw)
{
	struct tb_switch *parent = tb_to_switch(sw->dev.parent);
	struct tb_port *up, *down;

	if (!tb_route(sw))
@@ -2818,7 +2816,7 @@ void tb_switch_lane_bonding_disable(struct tb_switch *sw)
	if (!up->bonded)
		return;

	down = tb_port_at(tb_route(sw), parent);
	down = tb_switch_downstream_port(sw);

	tb_port_lane_bonding_disable(up);
	tb_port_lane_bonding_disable(down);
@@ -3476,7 +3474,6 @@ struct tb_port *tb_switch_find_port(struct tb_switch *sw,

static int tb_switch_pm_secondary_resolve(struct tb_switch *sw)
{
	struct tb_switch *parent = tb_switch_parent(sw);
	struct tb_port *up, *down;
	int ret;

@@ -3484,7 +3481,7 @@ static int tb_switch_pm_secondary_resolve(struct tb_switch *sw)
		return 0;

	up = tb_upstream_port(sw);
	down = tb_port_at(tb_route(sw), parent);
	down = tb_switch_downstream_port(sw);
	ret = tb_port_pm_secondary_enable(up);
	if (ret)
		return ret;
@@ -3494,7 +3491,6 @@ static int tb_switch_pm_secondary_resolve(struct tb_switch *sw)

static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)
{
	struct tb_switch *parent = tb_switch_parent(sw);
	bool up_clx_support, down_clx_support;
	struct tb_port *up, *down;
	int ret;
@@ -3510,7 +3506,7 @@ static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)
		return 0;

	/* Enable CLx only for first hop router (depth = 1) */
	if (tb_route(parent))
	if (tb_route(tb_switch_parent(sw)))
		return 0;

	ret = tb_switch_pm_secondary_resolve(sw);
@@ -3518,7 +3514,7 @@ static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)
		return ret;

	up = tb_upstream_port(sw);
	down = tb_port_at(tb_route(sw), parent);
	down = tb_switch_downstream_port(sw);

	up_clx_support = tb_port_clx_supported(up, clx);
	down_clx_support = tb_port_clx_supported(down, clx);
@@ -3594,7 +3590,6 @@ int tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx)

static int __tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx)
{
	struct tb_switch *parent = tb_switch_parent(sw);
	struct tb_port *up, *down;
	int ret;

@@ -3609,11 +3604,11 @@ static int __tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx)
		return 0;

	/* Disable CLx only for first hop router (depth = 1) */
	if (tb_route(parent))
	if (tb_route(tb_switch_parent(sw)))
		return 0;

	up = tb_upstream_port(sw);
	down = tb_port_at(tb_route(sw), parent);
	down = tb_switch_downstream_port(sw);
	ret = tb_port_clx_disable(up, clx);
	if (ret)
		return ret;
+3 −5
Original line number Diff line number Diff line
@@ -628,7 +628,7 @@ static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw)
	 * Look up available down port. Since we are chaining it should
	 * be found right above this switch.
	 */
	port = tb_port_at(tb_route(sw), parent);
	port = tb_switch_downstream_port(sw);
	down = tb_find_usb3_down(parent, port);
	if (!down)
		return 0;
@@ -1378,7 +1378,6 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
{
	struct tb_port *up, *down, *port;
	struct tb_cm *tcm = tb_priv(tb);
	struct tb_switch *parent_sw;
	struct tb_tunnel *tunnel;

	up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
@@ -1389,9 +1388,8 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
	 * Look up available down port. Since we are chaining it should
	 * be found right above this switch.
	 */
	parent_sw = tb_to_switch(sw->dev.parent);
	port = tb_port_at(tb_route(sw), parent_sw);
	down = tb_find_pcie_down(parent_sw, port);
	port = tb_switch_downstream_port(sw);
	down = tb_find_pcie_down(tb_switch_parent(sw), port);
	if (!down)
		return 0;

+14 −0
Original line number Diff line number Diff line
@@ -857,6 +857,20 @@ static inline struct tb_switch *tb_switch_parent(struct tb_switch *sw)
	return tb_to_switch(sw->dev.parent);
}

/**
 * tb_switch_downstream_port() - Return downstream facing port of parent router
 * @sw: Device router pointer
 *
 * Only call for device routers. Returns the downstream facing port of
 * the parent router.
 */
static inline struct tb_port *tb_switch_downstream_port(struct tb_switch *sw)
{
	if (WARN_ON(!tb_route(sw)))
		return NULL;
	return tb_port_at(tb_route(sw), tb_switch_parent(sw));
}

static inline bool tb_switch_is_light_ridge(const struct tb_switch *sw)
{
	return sw->config.vendor_id == PCI_VENDOR_ID_INTEL &&
Loading