switch.c (341d45188a7800ae3bc18558d62020787b78397e) switch.c (b2911a593a705e54adde6d06d4657c1ff2f16583)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Thunderbolt driver - switch/port utility functions
4 *
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6 * Copyright (C) 2018, Intel Corporation
7 */
8

--- 2021 unchanged lines hidden (view full) ---

2030{
2031 struct tb *tb = sw->tb;
2032 u64 route;
2033 int ret;
2034
2035 route = tb_route(sw);
2036
2037 tb_dbg(tb, "%s Switch at %#llx (depth: %d, up port: %d)\n",
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Thunderbolt driver - switch/port utility functions
4 *
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6 * Copyright (C) 2018, Intel Corporation
7 */
8

--- 2021 unchanged lines hidden (view full) ---

2030{
2031 struct tb *tb = sw->tb;
2032 u64 route;
2033 int ret;
2034
2035 route = tb_route(sw);
2036
2037 tb_dbg(tb, "%s Switch at %#llx (depth: %d, up port: %d)\n",
2038 sw->config.enabled ? "restoring " : "initializing", route,
2038 sw->config.enabled ? "restoring" : "initializing", route,
2039 tb_route_length(route), sw->config.upstream_port_number);
2040
2041 sw->config.enabled = 1;
2042
2043 if (tb_switch_is_usb4(sw)) {
2044 /*
2045 * For USB4 devices, we need to program the CM version
2046 * accordingly so that it knows to expose all the

--- 449 unchanged lines hidden (view full) ---

2496
2497 ret = tb_switch_nvm_add(sw);
2498 if (ret) {
2499 dev_err(&sw->dev, "failed to add NVM devices\n");
2500 device_del(&sw->dev);
2501 return ret;
2502 }
2503
2039 tb_route_length(route), sw->config.upstream_port_number);
2040
2041 sw->config.enabled = 1;
2042
2043 if (tb_switch_is_usb4(sw)) {
2044 /*
2045 * For USB4 devices, we need to program the CM version
2046 * accordingly so that it knows to expose all the

--- 449 unchanged lines hidden (view full) ---

2496
2497 ret = tb_switch_nvm_add(sw);
2498 if (ret) {
2499 dev_err(&sw->dev, "failed to add NVM devices\n");
2500 device_del(&sw->dev);
2501 return ret;
2502 }
2503
2504 /*
2505 * Thunderbolt routers do not generate wakeups themselves but
2506 * they forward wakeups from tunneled protocols, so enable it
2507 * here.
2508 */
2509 device_init_wakeup(&sw->dev, true);
2510
2504 pm_runtime_set_active(&sw->dev);
2505 if (sw->rpm) {
2506 pm_runtime_set_autosuspend_delay(&sw->dev, TB_AUTOSUSPEND_DELAY);
2507 pm_runtime_use_autosuspend(&sw->dev);
2508 pm_runtime_mark_last_busy(&sw->dev);
2509 pm_runtime_enable(&sw->dev);
2510 pm_request_autosuspend(&sw->dev);
2511 }

--- 61 unchanged lines hidden (view full) ---

2573 tb_switch_for_each_port(sw, port) {
2574 if (tb_port_has_remote(port))
2575 tb_sw_set_unplugged(port->remote->sw);
2576 else if (port->xdomain)
2577 port->xdomain->is_unplugged = true;
2578 }
2579}
2580
2511 pm_runtime_set_active(&sw->dev);
2512 if (sw->rpm) {
2513 pm_runtime_set_autosuspend_delay(&sw->dev, TB_AUTOSUSPEND_DELAY);
2514 pm_runtime_use_autosuspend(&sw->dev);
2515 pm_runtime_mark_last_busy(&sw->dev);
2516 pm_runtime_enable(&sw->dev);
2517 pm_request_autosuspend(&sw->dev);
2518 }

--- 61 unchanged lines hidden (view full) ---

2580 tb_switch_for_each_port(sw, port) {
2581 if (tb_port_has_remote(port))
2582 tb_sw_set_unplugged(port->remote->sw);
2583 else if (port->xdomain)
2584 port->xdomain->is_unplugged = true;
2585 }
2586}
2587
2588static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags)
2589{
2590 if (flags)
2591 tb_sw_dbg(sw, "enabling wakeup: %#x\n", flags);
2592 else
2593 tb_sw_dbg(sw, "disabling wakeup\n");
2594
2595 if (tb_switch_is_usb4(sw))
2596 return usb4_switch_set_wake(sw, flags);
2597 return tb_lc_set_wake(sw, flags);
2598}
2599
2581int tb_switch_resume(struct tb_switch *sw)
2582{
2583 struct tb_port *port;
2584 int err;
2585
2586 tb_sw_dbg(sw, "resuming switch\n");
2587
2588 /*

--- 29 unchanged lines hidden (view full) ---

2618 return -ENODEV;
2619 }
2620 }
2621
2622 err = tb_switch_configure(sw);
2623 if (err)
2624 return err;
2625
2600int tb_switch_resume(struct tb_switch *sw)
2601{
2602 struct tb_port *port;
2603 int err;
2604
2605 tb_sw_dbg(sw, "resuming switch\n");
2606
2607 /*

--- 29 unchanged lines hidden (view full) ---

2637 return -ENODEV;
2638 }
2639 }
2640
2641 err = tb_switch_configure(sw);
2642 if (err)
2643 return err;
2644
2645 /* Disable wakes */
2646 tb_switch_set_wake(sw, 0);
2647
2626 err = tb_switch_tmu_init(sw);
2627 if (err)
2628 return err;
2629
2630 /* check for surviving downstream switches */
2631 tb_switch_for_each_port(sw, port) {
2632 if (!tb_port_has_remote(port) && !port->xdomain)
2633 continue;

--- 19 unchanged lines hidden (view full) ---

2653 }
2654 }
2655 }
2656 return 0;
2657}
2658
2659void tb_switch_suspend(struct tb_switch *sw)
2660{
2648 err = tb_switch_tmu_init(sw);
2649 if (err)
2650 return err;
2651
2652 /* check for surviving downstream switches */
2653 tb_switch_for_each_port(sw, port) {
2654 if (!tb_port_has_remote(port) && !port->xdomain)
2655 continue;

--- 19 unchanged lines hidden (view full) ---

2675 }
2676 }
2677 }
2678 return 0;
2679}
2680
2681void tb_switch_suspend(struct tb_switch *sw)
2682{
2683 unsigned int flags = 0;
2661 struct tb_port *port;
2662 int err;
2663
2664 err = tb_plug_events_active(sw, false);
2665 if (err)
2666 return;
2667
2668 tb_switch_for_each_port(sw, port) {
2669 if (tb_port_has_remote(port))
2670 tb_switch_suspend(port->remote->sw);
2671 }
2672
2684 struct tb_port *port;
2685 int err;
2686
2687 err = tb_plug_events_active(sw, false);
2688 if (err)
2689 return;
2690
2691 tb_switch_for_each_port(sw, port) {
2692 if (tb_port_has_remote(port))
2693 tb_switch_suspend(port->remote->sw);
2694 }
2695
2696 if (device_may_wakeup(&sw->dev))
2697 flags = TB_WAKE_ON_USB4 | TB_WAKE_ON_USB3 | TB_WAKE_ON_PCIE;
2698
2699 tb_switch_set_wake(sw, flags);
2700
2673 if (tb_switch_is_usb4(sw))
2674 usb4_switch_set_sleep(sw);
2675 else
2676 tb_lc_set_sleep(sw);
2677}
2678
2679/**
2680 * tb_switch_query_dp_resource() - Query availability of DP resource

--- 178 unchanged lines hidden ---
2701 if (tb_switch_is_usb4(sw))
2702 usb4_switch_set_sleep(sw);
2703 else
2704 tb_lc_set_sleep(sw);
2705}
2706
2707/**
2708 * tb_switch_query_dp_resource() - Query availability of DP resource

--- 178 unchanged lines hidden ---