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()
1419 static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port) in tb_dp_resource_unavailable() argument
1434 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, out); in tb_dp_resource_unavailable()
1442 tb_recalc_estimated_bandwidth(tb); in tb_dp_resource_unavailable()
1443 tb_tunnel_dp(tb); in tb_dp_resource_unavailable()
1446 static void tb_dp_resource_available(struct tb *tb, struct tb_port *port) in tb_dp_resource_available() argument
1448 struct tb_cm *tcm = tb_priv(tb); in tb_dp_resource_available()
1464 tb_tunnel_dp(tb); in tb_dp_resource_available()
1467 static void tb_disconnect_and_release_dp(struct tb *tb) in tb_disconnect_and_release_dp() argument
1469 struct tb_cm *tcm = tb_priv(tb); in tb_disconnect_and_release_dp()
1490 static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) in tb_disconnect_pci() argument
1499 tunnel = tb_find_tunnel(tb, TB_TUNNEL_PCI, NULL, up); in tb_disconnect_pci()
1511 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) in tb_tunnel_pci() argument
1514 struct tb_cm *tcm = tb_priv(tb); in tb_tunnel_pci()
1530 tunnel = tb_tunnel_alloc_pci(tb, up, down); in tb_tunnel_pci()
1555 static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_approve_xdomain_paths() argument
1559 struct tb_cm *tcm = tb_priv(tb); in tb_approve_xdomain_paths()
1567 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); in tb_approve_xdomain_paths()
1569 mutex_lock(&tb->lock); in tb_approve_xdomain_paths()
1577 tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, transmit_path, in tb_approve_xdomain_paths()
1592 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
1599 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
1604 static void __tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in __tb_disconnect_xdomain_paths() argument
1608 struct tb_cm *tcm = tb_priv(tb); in __tb_disconnect_xdomain_paths()
1615 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); in __tb_disconnect_xdomain_paths()
1636 static int tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, in tb_disconnect_xdomain_paths() argument
1641 mutex_lock(&tb->lock); in tb_disconnect_xdomain_paths()
1642 __tb_disconnect_xdomain_paths(tb, xd, transmit_path, in tb_disconnect_xdomain_paths()
1645 mutex_unlock(&tb->lock); in tb_disconnect_xdomain_paths()
1660 struct tb *tb = ev->tb; in tb_handle_hotplug() local
1661 struct tb_cm *tcm = tb_priv(tb); in tb_handle_hotplug()
1666 pm_runtime_get_sync(&tb->dev); in tb_handle_hotplug()
1668 mutex_lock(&tb->lock); in tb_handle_hotplug()
1672 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_hotplug()
1674 tb_warn(tb, in tb_handle_hotplug()
1680 tb_warn(tb, in tb_handle_hotplug()
1687 tb_dbg(tb, "hotplug event for upstream port %llx:%x (unplug: %d)\n", in tb_handle_hotplug()
1700 tb_free_invalid_tunnels(tb); in tb_handle_hotplug()
1710 tb_recalc_estimated_bandwidth(tb); in tb_handle_hotplug()
1711 tb_tunnel_dp(tb); in tb_handle_hotplug()
1726 __tb_disconnect_xdomain_paths(tb, xd, -1, -1, -1, -1); in tb_handle_hotplug()
1730 tb_dp_resource_unavailable(tb, port); in tb_handle_hotplug()
1750 tb_dp_resource_available(tb, port); in tb_handle_hotplug()
1760 mutex_unlock(&tb->lock); in tb_handle_hotplug()
1762 pm_runtime_mark_last_busy(&tb->dev); in tb_handle_hotplug()
1763 pm_runtime_put_autosuspend(&tb->dev); in tb_handle_hotplug()
1774 struct tb *tb = tunnel->tb; in tb_alloc_dp_bandwidth() local
1855 ret = tb_release_unused_usb3_bandwidth(tb, in, out); in tb_alloc_dp_bandwidth()
1864 ret = tb_available_bandwidth(tb, in, out, &available_up, &available_down); in tb_alloc_dp_bandwidth()
1880 tb_reclaim_usb3_bandwidth(tb, in, out); in tb_alloc_dp_bandwidth()
1890 struct tb *tb = ev->tb; in tb_handle_dp_bandwidth_request() local
1891 struct tb_cm *tcm = tb_priv(tb); in tb_handle_dp_bandwidth_request()
1894 pm_runtime_get_sync(&tb->dev); in tb_handle_dp_bandwidth_request()
1896 mutex_lock(&tb->lock); in tb_handle_dp_bandwidth_request()
1900 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_dp_bandwidth_request()
1902 tb_warn(tb, "bandwidth request from non-existent router %llx\n", in tb_handle_dp_bandwidth_request()
1932 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, NULL); in tb_handle_dp_bandwidth_request()
1959 tb_recalc_estimated_bandwidth(tb); in tb_handle_dp_bandwidth_request()
1965 mutex_unlock(&tb->lock); in tb_handle_dp_bandwidth_request()
1967 pm_runtime_mark_last_busy(&tb->dev); in tb_handle_dp_bandwidth_request()
1968 pm_runtime_put_autosuspend(&tb->dev); in tb_handle_dp_bandwidth_request()
1973 static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port) in tb_queue_dp_bandwidth_request() argument
1981 ev->tb = tb; in tb_queue_dp_bandwidth_request()
1985 queue_work(tb->wq, &ev->work); in tb_queue_dp_bandwidth_request()
1988 static void tb_handle_notification(struct tb *tb, u64 route, in tb_handle_notification() argument
1996 if (tb_cfg_ack_notification(tb->ctl, route, error)) in tb_handle_notification()
1997 tb_warn(tb, "could not ack notification on %llx\n", in tb_handle_notification()
2002 if (tb_cfg_ack_notification(tb->ctl, route, error)) in tb_handle_notification()
2003 tb_warn(tb, "could not ack notification on %llx\n", in tb_handle_notification()
2005 tb_queue_dp_bandwidth_request(tb, route, error->port); in tb_handle_notification()
2019 static void tb_handle_event(struct tb *tb, enum tb_cfg_pkg_type type, in tb_handle_event() argument
2027 tb_handle_notification(tb, route, (const struct cfg_error_pkg *)buf); in tb_handle_event()
2032 tb_warn(tb, "unexpected event %#x, ignoring\n", type); in tb_handle_event()
2036 if (tb_cfg_ack_plug(tb->ctl, route, pkg->port, pkg->unplug)) { in tb_handle_event()
2037 tb_warn(tb, "could not ack plug event on %llx:%x\n", route, in tb_handle_event()
2041 tb_queue_hotplug(tb, route, pkg->port, pkg->unplug); in tb_handle_event()
2044 static void tb_stop(struct tb *tb) in tb_stop() argument
2046 struct tb_cm *tcm = tb_priv(tb); in tb_stop()
2062 tb_switch_remove(tb->root_switch); in tb_stop()
2087 static int tb_start(struct tb *tb) in tb_start() argument
2089 struct tb_cm *tcm = tb_priv(tb); in tb_start()
2092 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); in tb_start()
2093 if (IS_ERR(tb->root_switch)) in tb_start()
2094 return PTR_ERR(tb->root_switch); in tb_start()
2104 tb->root_switch->no_nvm_upgrade = !tb_switch_is_usb4(tb->root_switch); in tb_start()
2106 tb->root_switch->rpm = tb_switch_is_usb4(tb->root_switch); in tb_start()
2108 ret = tb_switch_configure(tb->root_switch); in tb_start()
2110 tb_switch_put(tb->root_switch); in tb_start()
2115 ret = tb_switch_add(tb->root_switch); in tb_start()
2117 tb_switch_put(tb->root_switch); in tb_start()
2125 tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_MODE_LOWRES); in tb_start()
2127 tb_switch_tmu_enable(tb->root_switch); in tb_start()
2129 tb_scan_switch(tb->root_switch); in tb_start()
2131 tb_discover_tunnels(tb); in tb_start()
2133 tb_discover_dp_resources(tb); in tb_start()
2138 tb_create_usb3_tunnels(tb->root_switch); in tb_start()
2140 tb_add_dp_resources(tb->root_switch); in tb_start()
2142 device_for_each_child(&tb->root_switch->dev, NULL, in tb_start()
2150 static int tb_suspend_noirq(struct tb *tb) in tb_suspend_noirq() argument
2152 struct tb_cm *tcm = tb_priv(tb); in tb_suspend_noirq()
2154 tb_dbg(tb, "suspending...\n"); in tb_suspend_noirq()
2155 tb_disconnect_and_release_dp(tb); in tb_suspend_noirq()
2156 tb_switch_suspend(tb->root_switch, false); in tb_suspend_noirq()
2158 tb_dbg(tb, "suspend finished\n"); in tb_suspend_noirq()
2194 static int tb_resume_noirq(struct tb *tb) in tb_resume_noirq() argument
2196 struct tb_cm *tcm = tb_priv(tb); in tb_resume_noirq()
2201 tb_dbg(tb, "resuming...\n"); in tb_resume_noirq()
2204 tb_switch_reset(tb->root_switch); in tb_resume_noirq()
2206 tb_switch_resume(tb->root_switch); in tb_resume_noirq()
2207 tb_free_invalid_tunnels(tb); in tb_resume_noirq()
2208 tb_free_unplugged_children(tb->root_switch); in tb_resume_noirq()
2209 tb_restore_children(tb->root_switch); in tb_resume_noirq()
2217 tb_switch_discover_tunnels(tb->root_switch, &tunnels, false); in tb_resume_noirq()
2240 tb_dbg(tb, "tunnels restarted, sleeping for 100ms\n"); in tb_resume_noirq()
2245 tb_dbg(tb, "resume finished\n"); in tb_resume_noirq()
2272 static int tb_freeze_noirq(struct tb *tb) in tb_freeze_noirq() argument
2274 struct tb_cm *tcm = tb_priv(tb); in tb_freeze_noirq()
2280 static int tb_thaw_noirq(struct tb *tb) in tb_thaw_noirq() argument
2282 struct tb_cm *tcm = tb_priv(tb); in tb_thaw_noirq()
2288 static void tb_complete(struct tb *tb) in tb_complete() argument
2295 mutex_lock(&tb->lock); in tb_complete()
2296 if (tb_free_unplugged_xdomains(tb->root_switch)) in tb_complete()
2297 tb_scan_switch(tb->root_switch); in tb_complete()
2298 mutex_unlock(&tb->lock); in tb_complete()
2301 static int tb_runtime_suspend(struct tb *tb) in tb_runtime_suspend() argument
2303 struct tb_cm *tcm = tb_priv(tb); in tb_runtime_suspend()
2305 mutex_lock(&tb->lock); in tb_runtime_suspend()
2306 tb_switch_suspend(tb->root_switch, true); in tb_runtime_suspend()
2308 mutex_unlock(&tb->lock); in tb_runtime_suspend()
2316 struct tb *tb = tcm_to_tb(tcm); in tb_remove_work() local
2318 mutex_lock(&tb->lock); in tb_remove_work()
2319 if (tb->root_switch) { in tb_remove_work()
2320 tb_free_unplugged_children(tb->root_switch); in tb_remove_work()
2321 tb_free_unplugged_xdomains(tb->root_switch); in tb_remove_work()
2323 mutex_unlock(&tb->lock); in tb_remove_work()
2326 static int tb_runtime_resume(struct tb *tb) in tb_runtime_resume() argument
2328 struct tb_cm *tcm = tb_priv(tb); in tb_runtime_resume()
2331 mutex_lock(&tb->lock); in tb_runtime_resume()
2332 tb_switch_resume(tb->root_switch); in tb_runtime_resume()
2333 tb_free_invalid_tunnels(tb); in tb_runtime_resume()
2334 tb_restore_children(tb->root_switch); in tb_runtime_resume()
2338 mutex_unlock(&tb->lock); in tb_runtime_resume()
2345 queue_delayed_work(tb->wq, &tcm->remove_work, msecs_to_jiffies(50)); in tb_runtime_resume()
2434 struct tb *tb_probe(struct tb_nhi *nhi) in tb_probe()
2437 struct tb *tb; in tb_probe() local
2439 tb = tb_domain_alloc(nhi, TB_TIMEOUT, sizeof(*tcm)); in tb_probe()
2440 if (!tb) in tb_probe()
2444 tb->security_level = TB_SECURITY_USER; in tb_probe()
2446 tb->security_level = TB_SECURITY_NOPCIE; in tb_probe()
2448 tb->cm_ops = &tb_cm_ops; in tb_probe()
2450 tcm = tb_priv(tb); in tb_probe()
2456 tb_dbg(tb, "using software connection manager\n"); in tb_probe()
2464 tb_warn(tb, "device links to tunneled native ports are missing!\n"); in tb_probe()
2466 return tb; in tb_probe()