Lines Matching refs:tb

42 static inline struct tb *tcm_to_tb(struct tb_cm *tcm)  in tcm_to_tb()
44 return ((void *)tcm - sizeof(struct tb)); in tcm_to_tb()
49 struct tb *tb; member
62 group->tb = tcm_to_tb(tcm); in tb_init_bandwidth_groups()
163 static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug) in tb_queue_hotplug() argument
171 ev->tb = tb; in tb_queue_hotplug()
176 queue_work(tb->wq, &ev->work); in tb_queue_hotplug()
183 struct tb_cm *tcm = tb_priv(sw->tb); in tb_add_dp_resources()
200 struct tb_cm *tcm = tb_priv(sw->tb); in tb_remove_dp_resources()
217 static void tb_discover_dp_resource(struct tb *tb, struct tb_port *port) in tb_discover_dp_resource() argument
219 struct tb_cm *tcm = tb_priv(tb); in tb_discover_dp_resource()
232 static void tb_discover_dp_resources(struct tb *tb) in tb_discover_dp_resources() argument
234 struct tb_cm *tcm = tb_priv(tb); in tb_discover_dp_resources()
239 tb_discover_dp_resource(tb, tunnel->dst_port); in tb_discover_dp_resources()
246 struct tb_cm *tcm = tb_priv(sw->tb); in tb_enable_clx()
341 sw = tunnel->tb->root_switch; in tb_increase_tmu_accuracy()
388 struct tb *tb = sw->tb; in tb_switch_discover_tunnels() local
396 tunnel = tb_tunnel_discover_dp(tb, port, alloc_hopids); in tb_switch_discover_tunnels()
401 tunnel = tb_tunnel_discover_pci(tb, port, alloc_hopids); in tb_switch_discover_tunnels()
405 tunnel = tb_tunnel_discover_usb3(tb, port, alloc_hopids); in tb_switch_discover_tunnels()
424 static void tb_discover_tunnels(struct tb *tb) in tb_discover_tunnels() argument
426 struct tb_cm *tcm = tb_priv(tb); in tb_discover_tunnels()
429 tb_switch_discover_tunnels(tb->root_switch, &tcm->tunnel_list, true); in tb_discover_tunnels()
472 struct tb *tb = sw->tb; in tb_scan_xdomain() local
480 xd = tb_xdomain_find_by_route(tb, route); in tb_scan_xdomain()
486 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid, in tb_scan_xdomain()
530 static struct tb_tunnel *tb_find_tunnel(struct tb *tb, enum tb_tunnel_type type, in tb_find_tunnel() argument
534 struct tb_cm *tcm = tb_priv(tb); in tb_find_tunnel()
548 static struct tb_tunnel *tb_find_first_usb3_tunnel(struct tb *tb, in tb_find_first_usb3_tunnel() argument
562 if (sw == tb->root_switch) in tb_find_first_usb3_tunnel()
566 port = tb_port_at(tb_route(sw), tb->root_switch); in tb_find_first_usb3_tunnel()
568 usb3_down = usb4_switch_map_usb3_down(tb->root_switch, port); in tb_find_first_usb3_tunnel()
572 return tb_find_tunnel(tb, TB_TUNNEL_USB3, usb3_down, NULL); in tb_find_first_usb3_tunnel()
575 static int tb_available_bandwidth(struct tb *tb, struct tb_port *src_port, in tb_available_bandwidth() argument
579 struct tb_cm *tcm = tb_priv(tb); in tb_available_bandwidth()
583 tb_dbg(tb, "calculating available bandwidth between %llx:%u <-> %llx:%u\n", in tb_available_bandwidth()
587 tunnel = tb_find_first_usb3_tunnel(tb, src_port, dst_port); in tb_available_bandwidth()
712 static int tb_release_unused_usb3_bandwidth(struct tb *tb, in tb_release_unused_usb3_bandwidth() argument
718 tunnel = tb_find_first_usb3_tunnel(tb, src_port, dst_port); in tb_release_unused_usb3_bandwidth()
722 static void tb_reclaim_usb3_bandwidth(struct tb *tb, struct tb_port *src_port, in tb_reclaim_usb3_bandwidth() argument
728 tunnel = tb_find_first_usb3_tunnel(tb, src_port, dst_port); in tb_reclaim_usb3_bandwidth()
732 tb_dbg(tb, "reclaiming unused bandwidth for USB3\n"); in tb_reclaim_usb3_bandwidth()
738 ret = tb_available_bandwidth(tb, tunnel->src_port, tunnel->dst_port, in tb_reclaim_usb3_bandwidth()
741 tb_warn(tb, "failed to calculate available bandwidth\n"); in tb_reclaim_usb3_bandwidth()
745 tb_dbg(tb, "available bandwidth for USB3 %d/%d Mb/s\n", in tb_reclaim_usb3_bandwidth()
751 static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw) in tb_tunnel_usb3() argument
756 struct tb_cm *tcm = tb_priv(tb); in tb_tunnel_usb3()
760 tb_dbg(tb, "USB3 tunneling disabled, not creating tunnel\n"); in tb_tunnel_usb3()
792 ret = tb_release_unused_usb3_bandwidth(tb, down, up); in tb_tunnel_usb3()
797 ret = tb_available_bandwidth(tb, down, up, &available_up, in tb_tunnel_usb3()
805 tunnel = tb_tunnel_alloc_usb3(tb, up, down, available_up, in tb_tunnel_usb3()
821 tb_reclaim_usb3_bandwidth(tb, down, up); in tb_tunnel_usb3()
829 tb_reclaim_usb3_bandwidth(tb, down, up); in tb_tunnel_usb3()
843 ret = tb_tunnel_usb3(sw->tb, sw); in tb_create_usb3_tunnels()
882 struct tb_cm *tcm = tb_priv(port->sw->tb); in tb_scan_port()
893 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port, in tb_scan_port()
918 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev, in tb_scan_port()
1007 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw)) in tb_scan_port()
1023 struct tb *tb; in tb_deactivate_and_free_tunnel() local
1031 tb = tunnel->tb; in tb_deactivate_and_free_tunnel()
1051 tb_reclaim_usb3_bandwidth(tb, src_port, dst_port); in tb_deactivate_and_free_tunnel()
1068 static void tb_free_invalid_tunnels(struct tb *tb) in tb_free_invalid_tunnels() argument
1070 struct tb_cm *tcm = tb_priv(tb); in tb_free_invalid_tunnels()
1159 struct tb *tb = group->tb; in tb_recalc_estimated_bandwidth_for_group() local
1163 tb_dbg(tb, "re-calculating bandwidth estimation for group %u\n", in tb_recalc_estimated_bandwidth_for_group()
1175 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, NULL); in tb_recalc_estimated_bandwidth_for_group()
1188 ret = tb_release_unused_usb3_bandwidth(tb, in tb_recalc_estimated_bandwidth_for_group()
1198 ret = tb_available_bandwidth(tb, in, out, &estimated_up, in tb_recalc_estimated_bandwidth_for_group()
1225 tb_reclaim_usb3_bandwidth(tb, first_tunnel->src_port, in tb_recalc_estimated_bandwidth_for_group()
1228 tb_dbg(tb, "bandwidth estimation for group %u done\n", group->index); in tb_recalc_estimated_bandwidth_for_group()
1231 static void tb_recalc_estimated_bandwidth(struct tb *tb) in tb_recalc_estimated_bandwidth() argument
1233 struct tb_cm *tcm = tb_priv(tb); in tb_recalc_estimated_bandwidth()
1236 tb_dbg(tb, "bandwidth consumption changed, re-calculating estimated bandwidth\n"); in tb_recalc_estimated_bandwidth()
1245 tb_dbg(tb, "bandwidth re-calculation done\n"); in tb_recalc_estimated_bandwidth()
1248 static struct tb_port *tb_find_dp_out(struct tb *tb, struct tb_port *in) in tb_find_dp_out() argument
1251 struct tb_cm *tcm = tb_priv(tb); in tb_find_dp_out()
1254 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL; in tb_find_dp_out()
1274 p = tb_port_at(tb_route(port->sw), tb->root_switch); in tb_find_dp_out()
1285 static void tb_tunnel_dp(struct tb *tb) in tb_tunnel_dp() argument
1288 struct tb_cm *tcm = tb_priv(tb); in tb_tunnel_dp()
1293 tb_dbg(tb, "DP tunneling disabled, not creating tunnel\n"); in tb_tunnel_dp()
1301 tb_dbg(tb, "looking for DP IN <-> DP OUT pairs:\n"); in tb_tunnel_dp()
1316 out = tb_find_dp_out(tb, port); in tb_tunnel_dp()
1324 tb_dbg(tb, "no suitable DP IN adapter available, not tunneling\n"); in tb_tunnel_dp()
1328 tb_dbg(tb, "no suitable DP OUT adapter available, not tunneling\n"); in tb_tunnel_dp()
1366 ret = tb_release_unused_usb3_bandwidth(tb, in, out); in tb_tunnel_dp()
1368 tb_warn(tb, "failed to release unused bandwidth\n"); in tb_tunnel_dp()
1372 ret = tb_available_bandwidth(tb, in, out, &available_up, &available_down); in tb_tunnel_dp()
1376 tb_dbg(tb, "available bandwidth for new DP tunnel %u/%u Mb/s\n", in tb_tunnel_dp()
1379 tunnel = tb_tunnel_alloc_dp(tb, in, out, link_nr, available_up, in tb_tunnel_dp()
1392 tb_reclaim_usb3_bandwidth(tb, in, out); in tb_tunnel_dp()
1395 tb_recalc_estimated_bandwidth(tb); in tb_tunnel_dp()
1407 tb_reclaim_usb3_bandwidth(tb, in, out); in tb_tunnel_dp()
1462 static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port) in tb_dp_resource_unavailable() argument
1477 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, out); in tb_dp_resource_unavailable()
1488 tb_recalc_estimated_bandwidth(tb); in tb_dp_resource_unavailable()
1489 tb_tunnel_dp(tb); in tb_dp_resource_unavailable()
1492 static void tb_dp_resource_available(struct tb *tb, struct tb_port *port) in tb_dp_resource_available() argument
1494 struct tb_cm *tcm = tb_priv(tb); in tb_dp_resource_available()
1511 tb_tunnel_dp(tb); in tb_dp_resource_available()
1514 static void tb_disconnect_and_release_dp(struct tb *tb) in tb_disconnect_and_release_dp() argument
1516 struct tb_cm *tcm = tb_priv(tb); in tb_disconnect_and_release_dp()
1537 static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) in tb_disconnect_pci() argument
1546 tunnel = tb_find_tunnel(tb, TB_TUNNEL_PCI, NULL, up); in tb_disconnect_pci()
1558 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) in tb_tunnel_pci() argument
1561 struct tb_cm *tcm = tb_priv(tb); in tb_tunnel_pci()
1577 tunnel = tb_tunnel_alloc_pci(tb, up, down); in tb_tunnel_pci()
1602 static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_approve_xdomain_paths() argument
1606 struct tb_cm *tcm = tb_priv(tb); in tb_approve_xdomain_paths()
1614 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); in tb_approve_xdomain_paths()
1616 mutex_lock(&tb->lock); in tb_approve_xdomain_paths()
1624 tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, transmit_path, in tb_approve_xdomain_paths()
1639 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
1646 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
1651 static void __tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in __tb_disconnect_xdomain_paths() argument
1655 struct tb_cm *tcm = tb_priv(tb); in __tb_disconnect_xdomain_paths()
1662 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); in __tb_disconnect_xdomain_paths()
1683 static int tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_disconnect_xdomain_paths() argument
1688 mutex_lock(&tb->lock); in tb_disconnect_xdomain_paths()
1689 __tb_disconnect_xdomain_paths(tb, xd, transmit_path, in tb_disconnect_xdomain_paths()
1692 mutex_unlock(&tb->lock); in tb_disconnect_xdomain_paths()
1707 struct tb *tb = ev->tb; in tb_handle_hotplug() local
1708 struct tb_cm *tcm = tb_priv(tb); in tb_handle_hotplug()
1713 pm_runtime_get_sync(&tb->dev); in tb_handle_hotplug()
1715 mutex_lock(&tb->lock); in tb_handle_hotplug()
1719 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_hotplug()
1721 tb_warn(tb, in tb_handle_hotplug()
1727 tb_warn(tb, in tb_handle_hotplug()
1734 tb_dbg(tb, "hotplug event for upstream port %llx:%x (unplug: %d)\n", in tb_handle_hotplug()
1747 tb_free_invalid_tunnels(tb); in tb_handle_hotplug()
1757 tb_recalc_estimated_bandwidth(tb); in tb_handle_hotplug()
1758 tb_tunnel_dp(tb); in tb_handle_hotplug()
1773 __tb_disconnect_xdomain_paths(tb, xd, -1, -1, -1, -1); in tb_handle_hotplug()
1777 tb_dp_resource_unavailable(tb, port); in tb_handle_hotplug()
1797 tb_dp_resource_available(tb, port); in tb_handle_hotplug()
1807 mutex_unlock(&tb->lock); in tb_handle_hotplug()
1809 pm_runtime_mark_last_busy(&tb->dev); in tb_handle_hotplug()
1810 pm_runtime_put_autosuspend(&tb->dev); in tb_handle_hotplug()
1821 struct tb *tb = tunnel->tb; in tb_alloc_dp_bandwidth() local
1902 ret = tb_release_unused_usb3_bandwidth(tb, in, out); in tb_alloc_dp_bandwidth()
1911 ret = tb_available_bandwidth(tb, in, out, &available_up, &available_down); in tb_alloc_dp_bandwidth()
1927 tb_reclaim_usb3_bandwidth(tb, in, out); in tb_alloc_dp_bandwidth()
1937 struct tb *tb = ev->tb; in tb_handle_dp_bandwidth_request() local
1938 struct tb_cm *tcm = tb_priv(tb); in tb_handle_dp_bandwidth_request()
1941 pm_runtime_get_sync(&tb->dev); in tb_handle_dp_bandwidth_request()
1943 mutex_lock(&tb->lock); in tb_handle_dp_bandwidth_request()
1947 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_dp_bandwidth_request()
1949 tb_warn(tb, "bandwidth request from non-existent router %llx\n", in tb_handle_dp_bandwidth_request()
1979 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, NULL); in tb_handle_dp_bandwidth_request()
2006 tb_recalc_estimated_bandwidth(tb); in tb_handle_dp_bandwidth_request()
2012 mutex_unlock(&tb->lock); in tb_handle_dp_bandwidth_request()
2014 pm_runtime_mark_last_busy(&tb->dev); in tb_handle_dp_bandwidth_request()
2015 pm_runtime_put_autosuspend(&tb->dev); in tb_handle_dp_bandwidth_request()
2020 static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port) in tb_queue_dp_bandwidth_request() argument
2028 ev->tb = tb; in tb_queue_dp_bandwidth_request()
2032 queue_work(tb->wq, &ev->work); in tb_queue_dp_bandwidth_request()
2035 static void tb_handle_notification(struct tb *tb, u64 route, in tb_handle_notification() argument
2043 if (tb_cfg_ack_notification(tb->ctl, route, error)) in tb_handle_notification()
2044 tb_warn(tb, "could not ack notification on %llx\n", in tb_handle_notification()
2049 if (tb_cfg_ack_notification(tb->ctl, route, error)) in tb_handle_notification()
2050 tb_warn(tb, "could not ack notification on %llx\n", in tb_handle_notification()
2052 tb_queue_dp_bandwidth_request(tb, route, error->port); in tb_handle_notification()
2066 static void tb_handle_event(struct tb *tb, enum tb_cfg_pkg_type type, in tb_handle_event() argument
2074 tb_handle_notification(tb, route, (const struct cfg_error_pkg *)buf); in tb_handle_event()
2079 tb_warn(tb, "unexpected event %#x, ignoring\n", type); in tb_handle_event()
2083 if (tb_cfg_ack_plug(tb->ctl, route, pkg->port, pkg->unplug)) { in tb_handle_event()
2084 tb_warn(tb, "could not ack plug event on %llx:%x\n", route, in tb_handle_event()
2088 tb_queue_hotplug(tb, route, pkg->port, pkg->unplug); in tb_handle_event()
2091 static void tb_stop(struct tb *tb) in tb_stop() argument
2093 struct tb_cm *tcm = tb_priv(tb); in tb_stop()
2109 tb_switch_remove(tb->root_switch); in tb_stop()
2134 static int tb_start(struct tb *tb, bool reset) in tb_start() argument
2136 struct tb_cm *tcm = tb_priv(tb); in tb_start()
2139 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); in tb_start()
2140 if (IS_ERR(tb->root_switch)) in tb_start()
2141 return PTR_ERR(tb->root_switch); in tb_start()
2151 tb->root_switch->no_nvm_upgrade = !tb_switch_is_usb4(tb->root_switch); in tb_start()
2153 tb->root_switch->rpm = tb_switch_is_usb4(tb->root_switch); in tb_start()
2155 ret = tb_switch_configure(tb->root_switch); in tb_start()
2157 tb_switch_put(tb->root_switch); in tb_start()
2162 ret = tb_switch_add(tb->root_switch); in tb_start()
2164 tb_switch_put(tb->root_switch); in tb_start()
2172 tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_MODE_LOWRES); in tb_start()
2174 tb_switch_tmu_enable(tb->root_switch); in tb_start()
2182 if (reset && usb4_switch_version(tb->root_switch) == 1) { in tb_start()
2183 tb_switch_reset(tb->root_switch); in tb_start()
2186 tb_scan_switch(tb->root_switch); in tb_start()
2188 tb_discover_tunnels(tb); in tb_start()
2190 tb_discover_dp_resources(tb); in tb_start()
2197 tb_create_usb3_tunnels(tb->root_switch); in tb_start()
2199 tb_add_dp_resources(tb->root_switch); in tb_start()
2201 device_for_each_child(&tb->root_switch->dev, NULL, in tb_start()
2209 static int tb_suspend_noirq(struct tb *tb) in tb_suspend_noirq() argument
2211 struct tb_cm *tcm = tb_priv(tb); in tb_suspend_noirq()
2213 tb_dbg(tb, "suspending...\n"); in tb_suspend_noirq()
2214 tb_disconnect_and_release_dp(tb); in tb_suspend_noirq()
2215 tb_switch_suspend(tb->root_switch, false); in tb_suspend_noirq()
2217 tb_dbg(tb, "suspend finished\n"); in tb_suspend_noirq()
2253 static int tb_resume_noirq(struct tb *tb) in tb_resume_noirq() argument
2255 struct tb_cm *tcm = tb_priv(tb); in tb_resume_noirq()
2260 tb_dbg(tb, "resuming...\n"); in tb_resume_noirq()
2266 if (!tb_switch_is_usb4(tb->root_switch)) in tb_resume_noirq()
2267 tb_switch_reset(tb->root_switch); in tb_resume_noirq()
2269 tb_switch_resume(tb->root_switch, false); in tb_resume_noirq()
2270 tb_free_invalid_tunnels(tb); in tb_resume_noirq()
2271 tb_free_unplugged_children(tb->root_switch); in tb_resume_noirq()
2272 tb_restore_children(tb->root_switch); in tb_resume_noirq()
2280 tb_switch_discover_tunnels(tb->root_switch, &tunnels, false); in tb_resume_noirq()
2303 tb_dbg(tb, "tunnels restarted, sleeping for 100ms\n"); in tb_resume_noirq()
2308 tb_dbg(tb, "resume finished\n"); in tb_resume_noirq()
2335 static int tb_freeze_noirq(struct tb *tb) in tb_freeze_noirq() argument
2337 struct tb_cm *tcm = tb_priv(tb); in tb_freeze_noirq()
2343 static int tb_thaw_noirq(struct tb *tb) in tb_thaw_noirq() argument
2345 struct tb_cm *tcm = tb_priv(tb); in tb_thaw_noirq()
2351 static void tb_complete(struct tb *tb) in tb_complete() argument
2358 mutex_lock(&tb->lock); in tb_complete()
2359 if (tb_free_unplugged_xdomains(tb->root_switch)) in tb_complete()
2360 tb_scan_switch(tb->root_switch); in tb_complete()
2361 mutex_unlock(&tb->lock); in tb_complete()
2364 static int tb_runtime_suspend(struct tb *tb) in tb_runtime_suspend() argument
2366 struct tb_cm *tcm = tb_priv(tb); in tb_runtime_suspend()
2368 mutex_lock(&tb->lock); in tb_runtime_suspend()
2369 tb_switch_suspend(tb->root_switch, true); in tb_runtime_suspend()
2371 mutex_unlock(&tb->lock); in tb_runtime_suspend()
2379 struct tb *tb = tcm_to_tb(tcm); in tb_remove_work() local
2381 mutex_lock(&tb->lock); in tb_remove_work()
2382 if (tb->root_switch) { in tb_remove_work()
2383 tb_free_unplugged_children(tb->root_switch); in tb_remove_work()
2384 tb_free_unplugged_xdomains(tb->root_switch); in tb_remove_work()
2386 mutex_unlock(&tb->lock); in tb_remove_work()
2389 static int tb_runtime_resume(struct tb *tb) in tb_runtime_resume() argument
2391 struct tb_cm *tcm = tb_priv(tb); in tb_runtime_resume()
2394 mutex_lock(&tb->lock); in tb_runtime_resume()
2395 tb_switch_resume(tb->root_switch, true); in tb_runtime_resume()
2396 tb_free_invalid_tunnels(tb); in tb_runtime_resume()
2397 tb_restore_children(tb->root_switch); in tb_runtime_resume()
2401 mutex_unlock(&tb->lock); in tb_runtime_resume()
2408 queue_delayed_work(tb->wq, &tcm->remove_work, msecs_to_jiffies(50)); in tb_runtime_resume()
2497 struct tb *tb_probe(struct tb_nhi *nhi) in tb_probe()
2500 struct tb *tb; in tb_probe() local
2502 tb = tb_domain_alloc(nhi, TB_TIMEOUT, sizeof(*tcm)); in tb_probe()
2503 if (!tb) in tb_probe()
2507 tb->security_level = TB_SECURITY_USER; in tb_probe()
2509 tb->security_level = TB_SECURITY_NOPCIE; in tb_probe()
2511 tb->cm_ops = &tb_cm_ops; in tb_probe()
2513 tcm = tb_priv(tb); in tb_probe()
2519 tb_dbg(tb, "using software connection manager\n"); in tb_probe()
2527 tb_warn(tb, "device links to tunneled native ports are missing!\n"); in tb_probe()
2529 return tb; in tb_probe()