Merge tag 'usb-6.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[platform/kernel/linux-rpi.git] / drivers / thunderbolt / tb.c
index 9a27707..4628458 100644 (file)
@@ -105,6 +105,32 @@ static void tb_remove_dp_resources(struct tb_switch *sw)
        }
 }
 
+static void tb_discover_dp_resource(struct tb *tb, struct tb_port *port)
+{
+       struct tb_cm *tcm = tb_priv(tb);
+       struct tb_port *p;
+
+       list_for_each_entry(p, &tcm->dp_resources, list) {
+               if (p == port)
+                       return;
+       }
+
+       tb_port_dbg(port, "DP %s resource available discovered\n",
+                   tb_port_is_dpin(port) ? "IN" : "OUT");
+       list_add_tail(&port->list, &tcm->dp_resources);
+}
+
+static void tb_discover_dp_resources(struct tb *tb)
+{
+       struct tb_cm *tcm = tb_priv(tb);
+       struct tb_tunnel *tunnel;
+
+       list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
+               if (tb_tunnel_is_dp(tunnel))
+                       tb_discover_dp_resource(tb, tunnel->dst_port);
+       }
+}
+
 static void tb_switch_discover_tunnels(struct tb_switch *sw,
                                       struct list_head *list,
                                       bool alloc_hopids)
@@ -1416,8 +1442,11 @@ static int tb_start(struct tb *tb)
         * ICM firmware upgrade needs running firmware and in native
         * mode that is not available so disable firmware upgrade of the
         * root switch.
+        *
+        * However, USB4 routers support NVM firmware upgrade if they
+        * implement the necessary router operations.
         */
-       tb->root_switch->no_nvm_upgrade = true;
+       tb->root_switch->no_nvm_upgrade = !tb_switch_is_usb4(tb->root_switch);
        /* All USB4 routers support runtime PM */
        tb->root_switch->rpm = tb_switch_is_usb4(tb->root_switch);
 
@@ -1446,6 +1475,8 @@ static int tb_start(struct tb *tb)
        tb_scan_switch(tb->root_switch);
        /* Find out tunnels created by the boot firmware */
        tb_discover_tunnels(tb);
+       /* Add DP resources from the DP tunnels created by the boot firmware */
+       tb_discover_dp_resources(tb);
        /*
         * If the boot firmware did not create USB 3.x tunnels create them
         * now for the whole topology.