thunderbolt: Disable lane 1 for XDomain connection
authorMika Westerberg <mika.westerberg@linux.intel.com>
Fri, 21 Feb 2020 10:11:54 +0000 (12:11 +0200)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 3 Sep 2020 09:06:41 +0000 (12:06 +0300)
USB4 spec mandates that the lane 1 should be disabled if lanes are not
bonded. For host-to-host connections (XDomain) we don't support lane
bonding so in order to be compatible with the spec, disable lane 1 when
another host is connected.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/switch.c
drivers/thunderbolt/tb.c
drivers/thunderbolt/tb.h
drivers/thunderbolt/tb_regs.h

index 50d2af5..37a8120 100644 (file)
@@ -673,6 +673,50 @@ int tb_port_unlock(struct tb_port *port)
        return 0;
 }
 
+static int __tb_port_enable(struct tb_port *port, bool enable)
+{
+       int ret;
+       u32 phy;
+
+       if (!tb_port_is_null(port))
+               return -EINVAL;
+
+       ret = tb_port_read(port, &phy, TB_CFG_PORT,
+                          port->cap_phy + LANE_ADP_CS_1, 1);
+       if (ret)
+               return ret;
+
+       if (enable)
+               phy &= ~LANE_ADP_CS_1_LD;
+       else
+               phy |= LANE_ADP_CS_1_LD;
+
+       return tb_port_write(port, &phy, TB_CFG_PORT,
+                            port->cap_phy + LANE_ADP_CS_1, 1);
+}
+
+/**
+ * tb_port_enable() - Enable lane adapter
+ * @port: Port to enable (can be %NULL)
+ *
+ * This is used for lane 0 and 1 adapters to enable it.
+ */
+int tb_port_enable(struct tb_port *port)
+{
+       return __tb_port_enable(port, true);
+}
+
+/**
+ * tb_port_disable() - Disable lane adapter
+ * @port: Port to disable (can be %NULL)
+ *
+ * This is used for lane 0 and 1 adapters to disable it.
+ */
+int tb_port_disable(struct tb_port *port)
+{
+       return __tb_port_enable(port, false);
+}
+
 /**
  * tb_init_port() - initialize a port
  *
index 602e00e..214e476 100644 (file)
@@ -142,6 +142,12 @@ static void tb_discover_tunnels(struct tb_switch *sw)
 
 static int tb_port_configure_xdomain(struct tb_port *port)
 {
+       /*
+        * XDomain paths currently only support single lane so we must
+        * disable the other lane according to USB4 spec.
+        */
+       tb_port_disable(port->dual_link_port);
+
        if (tb_switch_is_usb4(port->sw))
                return usb4_port_configure_xdomain(port);
        return tb_lc_configure_xdomain(port);
@@ -153,6 +159,8 @@ static void tb_port_unconfigure_xdomain(struct tb_port *port)
                usb4_port_unconfigure_xdomain(port);
        else
                tb_lc_unconfigure_xdomain(port);
+
+       tb_port_enable(port->dual_link_port);
 }
 
 static void tb_scan_xdomain(struct tb_port *port)
index c80b11d..e8593cf 100644 (file)
@@ -790,6 +790,8 @@ int tb_port_add_nfc_credits(struct tb_port *port, int credits);
 int tb_port_set_initial_credits(struct tb_port *port, u32 credits);
 int tb_port_clear_counter(struct tb_port *port, int counter);
 int tb_port_unlock(struct tb_port *port);
+int tb_port_enable(struct tb_port *port);
+int tb_port_disable(struct tb_port *port);
 int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
 void tb_port_release_in_hopid(struct tb_port *port, int hopid);
 int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
index a553be2..d1a40ba 100644 (file)
@@ -279,6 +279,7 @@ struct tb_regs_port_header {
 #define LANE_ADP_CS_1_TARGET_WIDTH_SHIFT       4
 #define LANE_ADP_CS_1_TARGET_WIDTH_SINGLE      0x1
 #define LANE_ADP_CS_1_TARGET_WIDTH_DUAL                0x3
+#define LANE_ADP_CS_1_LD                       BIT(14)
 #define LANE_ADP_CS_1_LB                       BIT(15)
 #define LANE_ADP_CS_1_CURRENT_SPEED_MASK       GENMASK(19, 16)
 #define LANE_ADP_CS_1_CURRENT_SPEED_SHIFT      16