thunderbolt: Set sleep bit when suspending switch
authorMika Westerberg <mika.westerberg@linux.intel.com>
Wed, 9 Jan 2019 15:25:43 +0000 (17:25 +0200)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 18 Apr 2019 08:18:52 +0000 (11:18 +0300)
Thunderbolt 2 devices and beyond link controller needs to be notified
when a switch is going to be suspended by setting bit 31 in LC_SX_CTRL
register. Add this functionality to the software connection manager.

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

index a5dddf1765464e408eb362ff192086e3d8eaf2c7..ae1e92611c3e0dfcf030203f6aed44e201d3b725 100644 (file)
@@ -133,3 +133,47 @@ void tb_lc_unconfigure_link(struct tb_switch *sw)
        tb_lc_configure_lane(up, false);
        tb_lc_configure_lane(down, false);
 }
+
+/**
+ * tb_lc_set_sleep() - Inform LC that the switch is going to sleep
+ * @sw: Switch to set sleep
+ *
+ * Let the switch link controllers know that the switch is going to
+ * sleep.
+ */
+int tb_lc_set_sleep(struct tb_switch *sw)
+{
+       int start, size, nlc, ret, i;
+       u32 desc;
+
+       if (sw->generation < 2)
+               return 0;
+
+       ret = read_lc_desc(sw, &desc);
+       if (ret)
+               return ret;
+
+       /* Figure out number of link controllers */
+       nlc = desc & TB_LC_DESC_NLC_MASK;
+       start = (desc & TB_LC_DESC_SIZE_MASK) >> TB_LC_DESC_SIZE_SHIFT;
+       size = (desc & TB_LC_DESC_PORT_SIZE_MASK) >> TB_LC_DESC_PORT_SIZE_SHIFT;
+
+       /* For each link controller set sleep bit */
+       for (i = 0; i < nlc; i++) {
+               unsigned int offset = sw->cap_lc + start + i * size;
+               u32 ctrl;
+
+               ret = tb_sw_read(sw, &ctrl, TB_CFG_SWITCH,
+                                offset + TB_LC_SX_CTRL, 1);
+               if (ret)
+                       return ret;
+
+               ctrl |= TB_LC_SX_CTRL_SLP;
+               ret = tb_sw_write(sw, &ctrl, TB_CFG_SWITCH,
+                                 offset + TB_LC_SX_CTRL, 1);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
index dd218dc4781b3f539d56255edb0debda808741e1..b3f93ebe6e3962c202a0e9fd695cf8e259c647d4 100644 (file)
@@ -1586,10 +1586,8 @@ void tb_switch_suspend(struct tb_switch *sw)
                if (!tb_is_upstream_port(&sw->ports[i]) && sw->ports[i].remote)
                        tb_switch_suspend(sw->ports[i].remote->sw);
        }
-       /*
-        * TODO: invoke tb_cfg_prepare_to_sleep here? does not seem to have any
-        * effect?
-        */
+
+       tb_lc_set_sleep(sw);
 }
 
 struct tb_sw_lookup {
index 69e0534224d870ae7ca6bb2c014f0cc48fe60841..985a48a67a437e12a24b055b18c45a9c6ba888dc 100644 (file)
@@ -467,6 +467,7 @@ int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid);
 int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid);
 int tb_lc_configure_link(struct tb_switch *sw);
 void tb_lc_unconfigure_link(struct tb_switch *sw);
+int tb_lc_set_sleep(struct tb_switch *sw);
 
 static inline int tb_route_length(u64 route)
 {
index e0f867dad5cf1ea7e0c92303bd94d6c4eacf9bd7..1ab6e0fb31c0f8d18fe73460deecca6424fbcb11 100644 (file)
@@ -239,6 +239,7 @@ struct tb_regs_hop {
 
 /* Common link controller registers */
 #define TB_LC_DESC                     0x02
+#define TB_LC_DESC_NLC_MASK            GENMASK(3, 0)
 #define TB_LC_DESC_SIZE_SHIFT          8
 #define TB_LC_DESC_SIZE_MASK           GENMASK(15, 8)
 #define TB_LC_DESC_PORT_SIZE_SHIFT     16
@@ -250,5 +251,6 @@ struct tb_regs_hop {
 #define TB_LC_SX_CTRL_L1C              BIT(16)
 #define TB_LC_SX_CTRL_L2C              BIT(20)
 #define TB_LC_SX_CTRL_UPSTREAM         BIT(30)
+#define TB_LC_SX_CTRL_SLP              BIT(31)
 
 #endif