Lines Matching refs:sw
400 struct icm_fr_pkg_get_topology_response *switches, *sw; in icm_fr_get_route() local
417 sw = &switches[0]; in icm_fr_get_route()
418 index = icm_fr_get_switch_index(sw->ports[link]); in icm_fr_get_route()
424 sw = &switches[index]; in icm_fr_get_route()
428 if (!(sw->first_data & ICM_SWITCH_USED)) { in icm_fr_get_route()
433 for (j = 0; j < ARRAY_SIZE(sw->ports); j++) { in icm_fr_get_route()
434 index = icm_fr_get_switch_index(sw->ports[j]); in icm_fr_get_route()
435 if (index > sw->switch_index) { in icm_fr_get_route()
436 sw = &switches[index]; in icm_fr_get_route()
442 *route = get_route(sw->route_hi, sw->route_lo); in icm_fr_get_route()
476 static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw) in icm_fr_approve_switch() argument
483 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_fr_approve_switch()
485 request.connection_id = sw->connection_id; in icm_fr_approve_switch()
486 request.connection_key = sw->connection_key; in icm_fr_approve_switch()
503 static int icm_fr_add_switch_key(struct tb *tb, struct tb_switch *sw) in icm_fr_add_switch_key() argument
510 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_fr_add_switch_key()
512 request.connection_id = sw->connection_id; in icm_fr_add_switch_key()
513 request.connection_key = sw->connection_key; in icm_fr_add_switch_key()
514 memcpy(request.key, sw->key, TB_SWITCH_KEY_SIZE); in icm_fr_add_switch_key()
530 static int icm_fr_challenge_switch_key(struct tb *tb, struct tb_switch *sw, in icm_fr_challenge_switch_key() argument
538 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_fr_challenge_switch_key()
540 request.connection_id = sw->connection_id; in icm_fr_challenge_switch_key()
541 request.connection_key = sw->connection_key; in icm_fr_challenge_switch_key()
613 struct tb_switch *sw; in alloc_switch() local
615 sw = tb_switch_alloc(tb, &parent_sw->dev, route); in alloc_switch()
616 if (IS_ERR(sw)) { in alloc_switch()
618 return sw; in alloc_switch()
621 sw->uuid = kmemdup(uuid, sizeof(*uuid), GFP_KERNEL); in alloc_switch()
622 if (!sw->uuid) { in alloc_switch()
623 tb_switch_put(sw); in alloc_switch()
627 init_completion(&sw->rpm_complete); in alloc_switch()
628 return sw; in alloc_switch()
631 static int add_switch(struct tb_switch *parent_sw, struct tb_switch *sw) in add_switch() argument
633 u64 route = tb_route(sw); in add_switch()
637 tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw); in add_switch()
638 tb_upstream_port(sw)->remote = tb_port_at(route, parent_sw); in add_switch()
640 ret = tb_switch_add(sw); in add_switch()
642 tb_port_at(tb_route(sw), parent_sw)->remote = NULL; in add_switch()
647 static void update_switch(struct tb_switch *sw, u64 route, u8 connection_id, in update_switch() argument
650 struct tb_switch *parent_sw = tb_switch_parent(sw); in update_switch()
653 tb_switch_downstream_port(sw)->remote = NULL; in update_switch()
655 tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw); in update_switch()
658 sw->config.route_hi = upper_32_bits(route); in update_switch()
659 sw->config.route_lo = lower_32_bits(route); in update_switch()
660 sw->connection_id = connection_id; in update_switch()
661 sw->connection_key = connection_key; in update_switch()
662 sw->link = link; in update_switch()
663 sw->depth = depth; in update_switch()
664 sw->boot = boot; in update_switch()
667 sw->is_unplugged = false; in update_switch()
670 complete(&sw->rpm_complete); in update_switch()
673 static void remove_switch(struct tb_switch *sw) in remove_switch() argument
675 tb_switch_downstream_port(sw)->remote = NULL; in remove_switch()
676 tb_switch_remove(sw); in remove_switch()
679 static void add_xdomain(struct tb_switch *sw, u64 route, in add_xdomain() argument
685 pm_runtime_get_sync(&sw->dev); in add_xdomain()
687 xd = tb_xdomain_alloc(sw->tb, &sw->dev, route, local_uuid, remote_uuid); in add_xdomain()
694 tb_port_at(route, sw)->xdomain = xd; in add_xdomain()
699 pm_runtime_mark_last_busy(&sw->dev); in add_xdomain()
700 pm_runtime_put_autosuspend(&sw->dev); in add_xdomain()
712 struct tb_switch *sw; in remove_xdomain() local
714 sw = tb_to_switch(xd->dev.parent); in remove_xdomain()
715 tb_port_at(xd->route, sw)->xdomain = NULL; in remove_xdomain()
725 struct tb_switch *sw, *parent_sw; in icm_fr_device_connected() local
752 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in icm_fr_device_connected()
753 if (sw) { in icm_fr_device_connected()
756 sw_phy_port = tb_phy_port_from_link(sw->link); in icm_fr_device_connected()
767 if (sw->depth == depth && sw_phy_port == phy_port && in icm_fr_device_connected()
768 !!sw->authorized == authorized) { in icm_fr_device_connected()
773 if (sw->link != link) { in icm_fr_device_connected()
778 tb_switch_put(sw); in icm_fr_device_connected()
782 route = tb_route(sw); in icm_fr_device_connected()
785 update_switch(sw, route, pkg->connection_id, in icm_fr_device_connected()
787 tb_switch_put(sw); in icm_fr_device_connected()
796 remove_switch(sw); in icm_fr_device_connected()
797 tb_switch_put(sw); in icm_fr_device_connected()
806 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_device_connected()
807 if (!sw) { in icm_fr_device_connected()
812 sw = tb_switch_find_by_link_depth(tb, dual_link, depth); in icm_fr_device_connected()
814 if (sw) { in icm_fr_device_connected()
815 remove_switch(sw); in icm_fr_device_connected()
816 tb_switch_put(sw); in icm_fr_device_connected()
843 sw = alloc_switch(parent_sw, route, &pkg->ep_uuid); in icm_fr_device_connected()
844 if (!IS_ERR(sw)) { in icm_fr_device_connected()
845 sw->connection_id = pkg->connection_id; in icm_fr_device_connected()
846 sw->connection_key = pkg->connection_key; in icm_fr_device_connected()
847 sw->link = link; in icm_fr_device_connected()
848 sw->depth = depth; in icm_fr_device_connected()
849 sw->authorized = authorized; in icm_fr_device_connected()
850 sw->security_level = security_level; in icm_fr_device_connected()
851 sw->boot = boot; in icm_fr_device_connected()
852 sw->link_speed = speed_gen3 ? 20 : 10; in icm_fr_device_connected()
853 sw->link_width = dual_lane ? TB_LINK_WIDTH_DUAL : in icm_fr_device_connected()
855 sw->rpm = intel_vss_is_rtd3(pkg->ep_name, sizeof(pkg->ep_name)); in icm_fr_device_connected()
857 if (add_switch(parent_sw, sw)) in icm_fr_device_connected()
858 tb_switch_put(sw); in icm_fr_device_connected()
872 struct tb_switch *sw; in icm_fr_device_disconnected() local
884 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_device_disconnected()
885 if (!sw) { in icm_fr_device_disconnected()
891 pm_runtime_get_sync(sw->dev.parent); in icm_fr_device_disconnected()
893 remove_switch(sw); in icm_fr_device_disconnected()
895 pm_runtime_mark_last_busy(sw->dev.parent); in icm_fr_device_disconnected()
896 pm_runtime_put_autosuspend(sw->dev.parent); in icm_fr_device_disconnected()
898 tb_switch_put(sw); in icm_fr_device_disconnected()
907 struct tb_switch *sw; in icm_fr_xdomain_connected() local
969 sw = tb_switch_find_by_route(tb, route); in icm_fr_xdomain_connected()
970 if (sw) { in icm_fr_xdomain_connected()
971 remove_switch(sw); in icm_fr_xdomain_connected()
972 tb_switch_put(sw); in icm_fr_xdomain_connected()
975 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_xdomain_connected()
976 if (!sw) { in icm_fr_xdomain_connected()
982 add_xdomain(sw, route, &pkg->local_uuid, &pkg->remote_uuid, link, in icm_fr_xdomain_connected()
984 tb_switch_put(sw); in icm_fr_xdomain_connected()
1041 static int icm_tr_approve_switch(struct tb *tb, struct tb_switch *sw) in icm_tr_approve_switch() argument
1048 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_tr_approve_switch()
1050 request.route_lo = sw->config.route_lo; in icm_tr_approve_switch()
1051 request.route_hi = sw->config.route_hi; in icm_tr_approve_switch()
1052 request.connection_id = sw->connection_id; in icm_tr_approve_switch()
1068 static int icm_tr_add_switch_key(struct tb *tb, struct tb_switch *sw) in icm_tr_add_switch_key() argument
1075 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_tr_add_switch_key()
1077 request.route_lo = sw->config.route_lo; in icm_tr_add_switch_key()
1078 request.route_hi = sw->config.route_hi; in icm_tr_add_switch_key()
1079 request.connection_id = sw->connection_id; in icm_tr_add_switch_key()
1080 memcpy(request.key, sw->key, TB_SWITCH_KEY_SIZE); in icm_tr_add_switch_key()
1096 static int icm_tr_challenge_switch_key(struct tb *tb, struct tb_switch *sw, in icm_tr_challenge_switch_key() argument
1104 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_tr_challenge_switch_key()
1106 request.route_lo = sw->config.route_lo; in icm_tr_challenge_switch_key()
1107 request.route_hi = sw->config.route_hi; in icm_tr_challenge_switch_key()
1108 request.connection_id = sw->connection_id; in icm_tr_challenge_switch_key()
1205 struct tb_switch *sw, *parent_sw; in __icm_tr_device_connected() local
1233 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in __icm_tr_device_connected()
1234 if (sw) { in __icm_tr_device_connected()
1236 if (tb_route(sw) == route && !!sw->authorized == authorized) { in __icm_tr_device_connected()
1237 update_switch(sw, route, pkg->connection_id, 0, 0, 0, in __icm_tr_device_connected()
1239 tb_switch_put(sw); in __icm_tr_device_connected()
1243 remove_switch(sw); in __icm_tr_device_connected()
1244 tb_switch_put(sw); in __icm_tr_device_connected()
1248 sw = tb_switch_find_by_route(tb, route); in __icm_tr_device_connected()
1249 if (sw) { in __icm_tr_device_connected()
1250 remove_switch(sw); in __icm_tr_device_connected()
1251 tb_switch_put(sw); in __icm_tr_device_connected()
1269 sw = alloc_switch(parent_sw, route, &pkg->ep_uuid); in __icm_tr_device_connected()
1270 if (!IS_ERR(sw)) { in __icm_tr_device_connected()
1271 sw->connection_id = pkg->connection_id; in __icm_tr_device_connected()
1272 sw->authorized = authorized; in __icm_tr_device_connected()
1273 sw->security_level = security_level; in __icm_tr_device_connected()
1274 sw->boot = boot; in __icm_tr_device_connected()
1275 sw->link_speed = speed_gen3 ? 20 : 10; in __icm_tr_device_connected()
1276 sw->link_width = dual_lane ? TB_LINK_WIDTH_DUAL : in __icm_tr_device_connected()
1278 sw->rpm = force_rtd3; in __icm_tr_device_connected()
1279 if (!sw->rpm) in __icm_tr_device_connected()
1280 sw->rpm = intel_vss_is_rtd3(pkg->ep_name, in __icm_tr_device_connected()
1283 if (add_switch(parent_sw, sw)) in __icm_tr_device_connected()
1284 tb_switch_put(sw); in __icm_tr_device_connected()
1304 struct tb_switch *sw; in icm_tr_device_disconnected() local
1309 sw = tb_switch_find_by_route(tb, route); in icm_tr_device_disconnected()
1310 if (!sw) { in icm_tr_device_disconnected()
1314 pm_runtime_get_sync(sw->dev.parent); in icm_tr_device_disconnected()
1316 remove_switch(sw); in icm_tr_device_disconnected()
1318 pm_runtime_mark_last_busy(sw->dev.parent); in icm_tr_device_disconnected()
1319 pm_runtime_put_autosuspend(sw->dev.parent); in icm_tr_device_disconnected()
1321 tb_switch_put(sw); in icm_tr_device_disconnected()
1330 struct tb_switch *sw; in icm_tr_xdomain_connected() local
1362 sw = tb_switch_find_by_route(tb, route); in icm_tr_xdomain_connected()
1363 if (sw) { in icm_tr_xdomain_connected()
1364 remove_switch(sw); in icm_tr_xdomain_connected()
1365 tb_switch_put(sw); in icm_tr_xdomain_connected()
1368 sw = tb_switch_find_by_route(tb, get_parent_route(route)); in icm_tr_xdomain_connected()
1369 if (!sw) { in icm_tr_xdomain_connected()
1374 add_xdomain(sw, route, &pkg->local_uuid, &pkg->remote_uuid, 0, 0); in icm_tr_xdomain_connected()
1375 tb_switch_put(sw); in icm_tr_xdomain_connected()
2008 static void icm_unplug_children(struct tb_switch *sw) in icm_unplug_children() argument
2012 if (tb_route(sw)) in icm_unplug_children()
2013 sw->is_unplugged = true; in icm_unplug_children()
2015 tb_switch_for_each_port(sw, port) { in icm_unplug_children()
2019 icm_unplug_children(port->remote->sw); in icm_unplug_children()
2025 struct tb_switch *sw = tb_to_switch(dev); in complete_rpm() local
2027 if (sw) in complete_rpm()
2028 complete(&sw->rpm_complete); in complete_rpm()
2032 static void remove_unplugged_switch(struct tb_switch *sw) in remove_unplugged_switch() argument
2034 struct device *parent = get_device(sw->dev.parent); in remove_unplugged_switch()
2043 complete_rpm(&sw->dev, NULL); in remove_unplugged_switch()
2044 bus_for_each_dev(&tb_bus_type, &sw->dev, NULL, complete_rpm); in remove_unplugged_switch()
2045 tb_switch_remove(sw); in remove_unplugged_switch()
2053 static void icm_free_unplugged_children(struct tb_switch *sw) in icm_free_unplugged_children() argument
2057 tb_switch_for_each_port(sw, port) { in icm_free_unplugged_children()
2062 if (port->remote->sw->is_unplugged) { in icm_free_unplugged_children()
2063 remove_unplugged_switch(port->remote->sw); in icm_free_unplugged_children()
2066 icm_free_unplugged_children(port->remote->sw); in icm_free_unplugged_children()
2119 static int icm_runtime_suspend_switch(struct tb_switch *sw) in icm_runtime_suspend_switch() argument
2121 if (tb_route(sw)) in icm_runtime_suspend_switch()
2122 reinit_completion(&sw->rpm_complete); in icm_runtime_suspend_switch()
2126 static int icm_runtime_resume_switch(struct tb_switch *sw) in icm_runtime_resume_switch() argument
2128 if (tb_route(sw)) { in icm_runtime_resume_switch()
2129 if (!wait_for_completion_timeout(&sw->rpm_complete, in icm_runtime_resume_switch()
2131 dev_dbg(&sw->dev, "runtime resuming timed out\n"); in icm_runtime_resume_switch()
2258 static int icm_usb4_switch_op(struct tb_switch *sw, u16 opcode, u32 *metadata, in icm_usb4_switch_op() argument
2264 struct tb *tb = sw->tb; in icm_usb4_switch_op()
2266 u64 route = tb_route(sw); in icm_usb4_switch_op()
2320 static int icm_usb4_switch_nvm_authenticate_status(struct tb_switch *sw, in icm_usb4_switch_nvm_authenticate_status() argument
2324 struct tb *tb = sw->tb; in icm_usb4_switch_nvm_authenticate_status()
2334 if (auth && auth->reply.route_hi == sw->config.route_hi && in icm_usb4_switch_nvm_authenticate_status()
2335 auth->reply.route_lo == sw->config.route_lo) { in icm_usb4_switch_nvm_authenticate_status()
2337 tb_route(sw), auth->reply.hdr.flags, auth->reply.status); in icm_usb4_switch_nvm_authenticate_status()