Lines Matching refs:sw
69 static void tb_add_dp_resources(struct tb_switch *sw)
71 struct tb_cm *tcm = tb_priv(sw->tb);
74 tb_switch_for_each_port(sw, port) {
78 if (!tb_switch_query_dp_resource(sw, port))
86 static void tb_remove_dp_resources(struct tb_switch *sw)
88 struct tb_cm *tcm = tb_priv(sw->tb);
92 tb_switch_for_each_port(sw, port) {
94 tb_remove_dp_resources(port->remote->sw);
98 if (port->sw == sw) {
105 static void tb_discover_tunnels(struct tb_switch *sw)
107 struct tb *tb = sw->tb;
111 tb_switch_for_each_port(sw, port) {
135 struct tb_switch *parent = tunnel->dst_port->sw;
137 while (parent != tunnel->src_port->sw) {
143 pm_runtime_get_sync(&tunnel->src_port->sw->dev);
144 pm_runtime_get_sync(&tunnel->dst_port->sw->dev);
150 tb_switch_for_each_port(sw, port) {
152 tb_discover_tunnels(port->remote->sw);
164 if (tb_switch_is_usb4(port->sw))
171 if (tb_switch_is_usb4(port->sw))
181 struct tb_switch *sw = port->sw;
182 struct tb *tb = sw->tb;
193 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid,
196 tb_port_at(route, sw)->xdomain = xd;
202 static int tb_enable_tmu(struct tb_switch *sw)
207 if (tb_switch_tmu_is_enabled(sw))
210 ret = tb_switch_tmu_disable(sw);
214 ret = tb_switch_tmu_post_time(sw);
218 return tb_switch_tmu_enable(sw);
222 * tb_find_unused_port() - return the first inactive port on @sw
223 * @sw: Switch to find the port on
226 static struct tb_port *tb_find_unused_port(struct tb_switch *sw,
231 tb_switch_for_each_port(sw, port) {
245 static struct tb_port *tb_find_usb3_down(struct tb_switch *sw,
250 down = usb4_switch_map_usb3_down(sw, port);
279 struct tb_switch *sw;
282 if (dst_port->sw->config.depth > src_port->sw->config.depth)
283 sw = dst_port->sw;
285 sw = src_port->sw;
288 if (sw == tb->root_switch)
292 port = tb_port_at(tb_route(sw), tb->root_switch);
332 link_speed = port->sw->link_speed;
433 static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw)
435 struct tb_switch *parent = tb_switch_parent(sw);
441 up = tb_switch_find_port(sw, TB_TYPE_USB3_UP);
445 if (!sw->link_usb4)
452 port = tb_port_at(tb_route(sw), parent);
511 static int tb_create_usb3_tunnels(struct tb_switch *sw)
516 if (tb_route(sw)) {
517 ret = tb_tunnel_usb3(sw->tb, sw);
522 tb_switch_for_each_port(sw, port) {
525 ret = tb_create_usb3_tunnels(port->remote->sw);
538 static void tb_scan_switch(struct tb_switch *sw)
542 pm_runtime_get_sync(&sw->dev);
544 tb_switch_for_each_port(sw, port)
547 pm_runtime_mark_last_busy(&sw->dev);
548 pm_runtime_put_autosuspend(&sw->dev);
556 struct tb_cm *tcm = tb_priv(port->sw->tb);
558 struct tb_switch *sw;
566 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port,
587 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev,
589 if (IS_ERR(sw)) {
595 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL)
600 if (tb_switch_configure(sw)) {
601 tb_switch_put(sw);
621 dev_set_uevent_suppress(&sw->dev, true);
627 sw->rpm = sw->generation > 1;
629 if (tb_switch_add(sw)) {
630 tb_switch_put(sw);
635 upstream_port = tb_upstream_port(sw);
644 tb_switch_lane_bonding_enable(sw);
646 tb_switch_configure_link(sw);
648 if (tb_enable_tmu(sw))
649 tb_sw_warn(sw, "failed to enable TMU\n");
660 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw))
661 tb_sw_warn(sw, "USB3 tunnel creation failed\n");
663 tb_add_dp_resources(sw);
664 tb_scan_switch(sw);
688 tb_switch_dealloc_dp_resource(src_port->sw, src_port);
690 pm_runtime_mark_last_busy(&dst_port->sw->dev);
691 pm_runtime_put_autosuspend(&dst_port->sw->dev);
692 pm_runtime_mark_last_busy(&src_port->sw->dev);
693 pm_runtime_put_autosuspend(&src_port->sw->dev);
729 static void tb_free_unplugged_children(struct tb_switch *sw)
733 tb_switch_for_each_port(sw, port) {
737 if (port->remote->sw->is_unplugged) {
739 tb_remove_dp_resources(port->remote->sw);
740 tb_switch_unconfigure_link(port->remote->sw);
741 tb_switch_lane_bonding_disable(port->remote->sw);
742 tb_switch_remove(port->remote->sw);
747 tb_free_unplugged_children(port->remote->sw);
752 static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,
761 if (tb_switch_is_usb4(sw)) {
762 down = usb4_switch_map_pcie_down(sw, port);
763 } else if (!tb_route(sw)) {
771 if (tb_switch_is_cactus_ridge(sw) ||
772 tb_switch_is_alpine_ridge(sw))
774 else if (tb_switch_is_falcon_ridge(sw))
776 else if (tb_switch_is_titan_ridge(sw))
782 if (WARN_ON(index > sw->config.max_port_number))
785 down = &sw->ports[index];
798 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN);
806 host_port = tb_route(in->sw) ?
807 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL;
824 if (host_port && tb_route(port->sw)) {
827 p = tb_port_at(tb_route(port->sw), tb->root_switch);
888 pm_runtime_get_sync(&in->sw->dev);
889 pm_runtime_get_sync(&out->sw->dev);
891 if (tb_switch_alloc_dp_resource(in->sw, in)) {
931 tb_switch_dealloc_dp_resource(in->sw, in);
933 pm_runtime_mark_last_busy(&out->sw->dev);
934 pm_runtime_put_autosuspend(&out->sw->dev);
935 pm_runtime_mark_last_busy(&in->sw->dev);
936 pm_runtime_put_autosuspend(&in->sw->dev);
1009 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
1016 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
1024 parent_sw = tb_to_switch(sw->dev.parent);
1025 port = tb_port_at(tb_route(sw), parent_sw);
1050 struct tb_switch *sw;
1052 sw = tb_to_switch(xd->dev.parent);
1053 dst_port = tb_port_at(xd->route, sw);
1082 struct tb_switch *sw;
1084 sw = tb_to_switch(xd->dev.parent);
1085 dst_port = tb_port_at(xd->route, sw);
1118 struct tb_switch *sw;
1128 sw = tb_switch_find_by_route(tb, ev->route);
1129 if (!sw) {
1135 if (ev->port > sw->config.max_port_number) {
1141 port = &sw->ports[ev->port];
1148 pm_runtime_get_sync(&sw->dev);
1155 tb_sw_set_unplugged(port->remote->sw);
1157 tb_remove_dp_resources(port->remote->sw);
1158 tb_switch_tmu_disable(port->remote->sw);
1159 tb_switch_unconfigure_link(port->remote->sw);
1160 tb_switch_lane_bonding_disable(port->remote->sw);
1161 tb_switch_remove(port->remote->sw);
1203 pm_runtime_mark_last_busy(&sw->dev);
1204 pm_runtime_put_autosuspend(&sw->dev);
1207 tb_switch_put(sw);
1268 struct tb_switch *sw = tb_to_switch(dev);
1275 if (sw->boot)
1276 sw->authorized = 1;
1352 static void tb_restore_children(struct tb_switch *sw)
1357 if (sw->is_unplugged)
1360 if (tb_enable_tmu(sw))
1361 tb_sw_warn(sw, "failed to restore TMU configuration\n");
1363 tb_switch_for_each_port(sw, port) {
1368 tb_switch_lane_bonding_enable(port->remote->sw);
1369 tb_switch_configure_link(port->remote->sw);
1371 tb_restore_children(port->remote->sw);
1409 static int tb_free_unplugged_xdomains(struct tb_switch *sw)
1414 tb_switch_for_each_port(sw, port) {
1424 ret += tb_free_unplugged_xdomains(port->remote->sw);