Lines Matching refs:sw
46 static struct nvm_auth_status *__nvm_get_auth_status(const struct tb_switch *sw) in __nvm_get_auth_status() argument
51 if (uuid_equal(&st->uuid, sw->uuid)) in __nvm_get_auth_status()
58 static void nvm_get_auth_status(const struct tb_switch *sw, u32 *status) in nvm_get_auth_status() argument
63 st = __nvm_get_auth_status(sw); in nvm_get_auth_status()
69 static void nvm_set_auth_status(const struct tb_switch *sw, u32 status) in nvm_set_auth_status() argument
73 if (WARN_ON(!sw->uuid)) in nvm_set_auth_status()
77 st = __nvm_get_auth_status(sw); in nvm_set_auth_status()
84 memcpy(&st->uuid, sw->uuid, sizeof(st->uuid)); in nvm_set_auth_status()
94 static void nvm_clear_auth_status(const struct tb_switch *sw) in nvm_clear_auth_status() argument
99 st = __nvm_get_auth_status(sw); in nvm_clear_auth_status()
107 static int nvm_validate_and_write(struct tb_switch *sw) in nvm_validate_and_write() argument
110 const u8 *buf = sw->nvm->buf; in nvm_validate_and_write()
117 image_size = sw->nvm->buf_data_size; in nvm_validate_and_write()
141 if (!sw->safe_mode) { in nvm_validate_and_write()
149 if (device_id != sw->config.device_id) in nvm_validate_and_write()
152 if (sw->generation < 3) { in nvm_validate_and_write()
154 ret = dma_port_flash_write(sw->dma_port, in nvm_validate_and_write()
166 return dma_port_flash_write(sw->dma_port, 0, buf, image_size); in nvm_validate_and_write()
169 static int nvm_authenticate_host(struct tb_switch *sw) in nvm_authenticate_host() argument
178 if (!sw->safe_mode) { in nvm_authenticate_host()
179 ret = tb_domain_disconnect_all_paths(sw->tb); in nvm_authenticate_host()
186 ret = dma_port_flash_update_auth(sw->dma_port); in nvm_authenticate_host()
194 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_host()
198 static int nvm_authenticate_device(struct tb_switch *sw) in nvm_authenticate_device() argument
202 ret = dma_port_flash_update_auth(sw->dma_port); in nvm_authenticate_device()
215 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in nvm_authenticate_device()
220 tb_sw_warn(sw, "failed to authenticate NVM\n"); in nvm_authenticate_device()
221 nvm_set_auth_status(sw, status); in nvm_authenticate_device()
224 tb_sw_info(sw, "power cycling the switch now\n"); in nvm_authenticate_device()
225 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_device()
238 struct tb_switch *sw = priv; in tb_switch_nvm_read() local
241 pm_runtime_get_sync(&sw->dev); in tb_switch_nvm_read()
243 if (!mutex_trylock(&sw->tb->lock)) { in tb_switch_nvm_read()
248 ret = dma_port_flash_read(sw->dma_port, offset, val, bytes); in tb_switch_nvm_read()
249 mutex_unlock(&sw->tb->lock); in tb_switch_nvm_read()
252 pm_runtime_mark_last_busy(&sw->dev); in tb_switch_nvm_read()
253 pm_runtime_put_autosuspend(&sw->dev); in tb_switch_nvm_read()
261 struct tb_switch *sw = priv; in tb_switch_nvm_write() local
264 if (!mutex_trylock(&sw->tb->lock)) in tb_switch_nvm_write()
273 if (!sw->nvm->buf) { in tb_switch_nvm_write()
274 sw->nvm->buf = vmalloc(NVM_MAX_SIZE); in tb_switch_nvm_write()
275 if (!sw->nvm->buf) { in tb_switch_nvm_write()
281 sw->nvm->buf_data_size = offset + bytes; in tb_switch_nvm_write()
282 memcpy(sw->nvm->buf + offset, val, bytes); in tb_switch_nvm_write()
285 mutex_unlock(&sw->tb->lock); in tb_switch_nvm_write()
290 static struct nvmem_device *register_nvmem(struct tb_switch *sw, int id, in register_nvmem() argument
311 config.dev = &sw->dev; in register_nvmem()
313 config.priv = sw; in register_nvmem()
318 static int tb_switch_nvm_add(struct tb_switch *sw) in tb_switch_nvm_add() argument
325 if (!sw->dma_port) in tb_switch_nvm_add()
339 if (!sw->safe_mode) { in tb_switch_nvm_add()
342 ret = dma_port_flash_read(sw->dma_port, NVM_FLASH_SIZE, &val, in tb_switch_nvm_add()
347 hdr_size = sw->generation < 3 ? SZ_8K : SZ_16K; in tb_switch_nvm_add()
351 ret = dma_port_flash_read(sw->dma_port, NVM_VERSION, &val, in tb_switch_nvm_add()
359 nvm_dev = register_nvmem(sw, nvm->id, nvm_size, true); in tb_switch_nvm_add()
367 if (!sw->no_nvm_upgrade) { in tb_switch_nvm_add()
368 nvm_dev = register_nvmem(sw, nvm->id, NVM_MAX_SIZE, false); in tb_switch_nvm_add()
376 sw->nvm = nvm; in tb_switch_nvm_add()
389 static void tb_switch_nvm_remove(struct tb_switch *sw) in tb_switch_nvm_remove() argument
393 nvm = sw->nvm; in tb_switch_nvm_remove()
394 sw->nvm = NULL; in tb_switch_nvm_remove()
401 nvm_clear_auth_status(sw); in tb_switch_nvm_remove()
553 if (credits == 0 || port->sw->is_unplugged) in tb_port_add_nfc_credits()
619 tb_dbg(port->sw->tb, " Port %d: not implemented\n", in tb_init_port()
640 tb_dump_port(port->sw->tb, &port->config); in tb_init_port()
747 if (prev->sw == end->sw) { in tb_next_port_on_path()
753 if (start->sw->config.depth < end->sw->config.depth) { in tb_next_port_on_path()
755 prev->remote->sw->config.depth > prev->sw->config.depth) in tb_next_port_on_path()
758 next = tb_port_at(tb_route(end->sw), prev->sw); in tb_next_port_on_path()
763 next = tb_upstream_port(prev->sw); in tb_next_port_on_path()
937 static void tb_dump_switch(struct tb *tb, struct tb_regs_switch_header *sw) in tb_dump_switch() argument
940 sw->vendor_id, sw->device_id, sw->revision, in tb_dump_switch()
941 sw->thunderbolt_version); in tb_dump_switch()
942 tb_dbg(tb, " Max Port Number: %d\n", sw->max_port_number); in tb_dump_switch()
946 sw->upstream_port_number, sw->depth, in tb_dump_switch()
947 (((u64) sw->route_hi) << 32) | sw->route_lo, in tb_dump_switch()
948 sw->enabled, sw->plug_events_delay); in tb_dump_switch()
950 sw->__unknown1, sw->__unknown4); in tb_dump_switch()
984 static int tb_plug_events_active(struct tb_switch *sw, bool active) in tb_plug_events_active() argument
989 if (!sw->config.enabled) in tb_plug_events_active()
992 sw->config.plug_events_delay = 0xff; in tb_plug_events_active()
993 res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1); in tb_plug_events_active()
997 res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1003 switch (sw->config.device_id) { in tb_plug_events_active()
1014 return tb_sw_write(sw, &data, TB_CFG_SWITCH, in tb_plug_events_active()
1015 sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1022 struct tb_switch *sw = tb_to_switch(dev); in authorized_show() local
1024 return sprintf(buf, "%u\n", sw->authorized); in authorized_show()
1027 static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val) in tb_switch_set_authorized() argument
1031 if (!mutex_trylock(&sw->tb->lock)) in tb_switch_set_authorized()
1034 if (sw->authorized) in tb_switch_set_authorized()
1040 if (sw->key) in tb_switch_set_authorized()
1041 ret = tb_domain_approve_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1043 ret = tb_domain_approve_switch(sw->tb, sw); in tb_switch_set_authorized()
1048 if (sw->key) in tb_switch_set_authorized()
1049 ret = tb_domain_challenge_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1057 sw->authorized = val; in tb_switch_set_authorized()
1059 kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); in tb_switch_set_authorized()
1063 mutex_unlock(&sw->tb->lock); in tb_switch_set_authorized()
1071 struct tb_switch *sw = tb_to_switch(dev); in authorized_store() local
1081 pm_runtime_get_sync(&sw->dev); in authorized_store()
1082 ret = tb_switch_set_authorized(sw, val); in authorized_store()
1083 pm_runtime_mark_last_busy(&sw->dev); in authorized_store()
1084 pm_runtime_put_autosuspend(&sw->dev); in authorized_store()
1093 struct tb_switch *sw = tb_to_switch(dev); in boot_show() local
1095 return sprintf(buf, "%u\n", sw->boot); in boot_show()
1102 struct tb_switch *sw = tb_to_switch(dev); in device_show() local
1104 return sprintf(buf, "%#x\n", sw->device); in device_show()
1111 struct tb_switch *sw = tb_to_switch(dev); in device_name_show() local
1113 return sprintf(buf, "%s\n", sw->device_name ? sw->device_name : ""); in device_name_show()
1120 struct tb_switch *sw = tb_to_switch(dev); in key_show() local
1123 if (!mutex_trylock(&sw->tb->lock)) in key_show()
1126 if (sw->key) in key_show()
1127 ret = sprintf(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key); in key_show()
1131 mutex_unlock(&sw->tb->lock); in key_show()
1138 struct tb_switch *sw = tb_to_switch(dev); in key_store() local
1148 if (!mutex_trylock(&sw->tb->lock)) in key_store()
1151 if (sw->authorized) { in key_store()
1154 kfree(sw->key); in key_store()
1156 sw->key = NULL; in key_store()
1158 sw->key = kmemdup(key, sizeof(key), GFP_KERNEL); in key_store()
1159 if (!sw->key) in key_store()
1164 mutex_unlock(&sw->tb->lock); in key_store()
1169 static void nvm_authenticate_start(struct tb_switch *sw) in nvm_authenticate_start() argument
1179 root_port = pci_find_pcie_root_port(sw->tb->nhi->pdev); in nvm_authenticate_start()
1184 static void nvm_authenticate_complete(struct tb_switch *sw) in nvm_authenticate_complete() argument
1188 root_port = pci_find_pcie_root_port(sw->tb->nhi->pdev); in nvm_authenticate_complete()
1196 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_show() local
1199 nvm_get_auth_status(sw, &status); in nvm_authenticate_show()
1206 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_store() local
1210 pm_runtime_get_sync(&sw->dev); in nvm_authenticate_store()
1212 if (!mutex_trylock(&sw->tb->lock)) { in nvm_authenticate_store()
1218 if (!sw->nvm) { in nvm_authenticate_store()
1228 nvm_clear_auth_status(sw); in nvm_authenticate_store()
1231 if (!sw->nvm->buf) { in nvm_authenticate_store()
1236 ret = nvm_validate_and_write(sw); in nvm_authenticate_store()
1240 sw->nvm->authenticating = true; in nvm_authenticate_store()
1242 if (!tb_route(sw)) { in nvm_authenticate_store()
1247 nvm_authenticate_start(sw); in nvm_authenticate_store()
1248 ret = nvm_authenticate_host(sw); in nvm_authenticate_store()
1250 nvm_authenticate_complete(sw); in nvm_authenticate_store()
1252 ret = nvm_authenticate_device(sw); in nvm_authenticate_store()
1257 mutex_unlock(&sw->tb->lock); in nvm_authenticate_store()
1259 pm_runtime_mark_last_busy(&sw->dev); in nvm_authenticate_store()
1260 pm_runtime_put_autosuspend(&sw->dev); in nvm_authenticate_store()
1271 struct tb_switch *sw = tb_to_switch(dev); in nvm_version_show() local
1274 if (!mutex_trylock(&sw->tb->lock)) in nvm_version_show()
1277 if (sw->safe_mode) in nvm_version_show()
1279 else if (!sw->nvm) in nvm_version_show()
1282 ret = sprintf(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor); in nvm_version_show()
1284 mutex_unlock(&sw->tb->lock); in nvm_version_show()
1293 struct tb_switch *sw = tb_to_switch(dev); in vendor_show() local
1295 return sprintf(buf, "%#x\n", sw->vendor); in vendor_show()
1302 struct tb_switch *sw = tb_to_switch(dev); in vendor_name_show() local
1304 return sprintf(buf, "%s\n", sw->vendor_name ? sw->vendor_name : ""); in vendor_name_show()
1311 struct tb_switch *sw = tb_to_switch(dev); in unique_id_show() local
1313 return sprintf(buf, "%pUb\n", sw->uuid); in unique_id_show()
1335 struct tb_switch *sw = tb_to_switch(dev); in switch_attr_is_visible() local
1338 if (!sw->device) in switch_attr_is_visible()
1341 if (!sw->device_name) in switch_attr_is_visible()
1344 if (!sw->vendor) in switch_attr_is_visible()
1347 if (!sw->vendor_name) in switch_attr_is_visible()
1350 if (tb_route(sw) && in switch_attr_is_visible()
1351 sw->tb->security_level == TB_SECURITY_SECURE && in switch_attr_is_visible()
1352 sw->security_level == TB_SECURITY_SECURE) in switch_attr_is_visible()
1356 if (sw->dma_port && !sw->no_nvm_upgrade) in switch_attr_is_visible()
1360 if (sw->dma_port) in switch_attr_is_visible()
1364 if (tb_route(sw)) in switch_attr_is_visible()
1369 return sw->safe_mode ? 0 : attr->mode; in switch_attr_is_visible()
1384 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_release() local
1387 dma_port_free(sw->dma_port); in tb_switch_release()
1389 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_release()
1390 if (!sw->ports[i].disabled) { in tb_switch_release()
1391 ida_destroy(&sw->ports[i].in_hopids); in tb_switch_release()
1392 ida_destroy(&sw->ports[i].out_hopids); in tb_switch_release()
1396 kfree(sw->uuid); in tb_switch_release()
1397 kfree(sw->device_name); in tb_switch_release()
1398 kfree(sw->vendor_name); in tb_switch_release()
1399 kfree(sw->ports); in tb_switch_release()
1400 kfree(sw->drom); in tb_switch_release()
1401 kfree(sw->key); in tb_switch_release()
1402 kfree(sw); in tb_switch_release()
1411 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_suspend() local
1412 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_suspend()
1415 return cm_ops->runtime_suspend_switch(sw); in tb_switch_runtime_suspend()
1422 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_resume() local
1423 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_resume()
1426 return cm_ops->runtime_resume_switch(sw); in tb_switch_runtime_resume()
1441 static int tb_switch_get_generation(struct tb_switch *sw) in tb_switch_get_generation() argument
1443 switch (sw->config.device_id) { in tb_switch_get_generation()
1476 tb_sw_warn(sw, "unsupported switch device id %#x\n", in tb_switch_get_generation()
1477 sw->config.device_id); in tb_switch_get_generation()
1499 struct tb_switch *sw; in tb_switch_alloc() local
1512 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc()
1513 if (!sw) in tb_switch_alloc()
1516 sw->tb = tb; in tb_switch_alloc()
1517 ret = tb_cfg_read(tb->ctl, &sw->config, route, 0, TB_CFG_SWITCH, 0, 5); in tb_switch_alloc()
1522 tb_dump_switch(tb, &sw->config); in tb_switch_alloc()
1525 sw->config.upstream_port_number = upstream_port; in tb_switch_alloc()
1526 sw->config.depth = depth; in tb_switch_alloc()
1527 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc()
1528 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc()
1529 sw->config.enabled = 0; in tb_switch_alloc()
1532 sw->ports = kcalloc(sw->config.max_port_number + 1, sizeof(*sw->ports), in tb_switch_alloc()
1534 if (!sw->ports) { in tb_switch_alloc()
1539 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_alloc()
1541 sw->ports[i].sw = sw; in tb_switch_alloc()
1542 sw->ports[i].port = i; in tb_switch_alloc()
1545 sw->generation = tb_switch_get_generation(sw); in tb_switch_alloc()
1547 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_PLUG_EVENTS); in tb_switch_alloc()
1549 tb_sw_warn(sw, "cannot find TB_VSE_CAP_PLUG_EVENTS aborting\n"); in tb_switch_alloc()
1552 sw->cap_plug_events = ret; in tb_switch_alloc()
1554 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_LINK_CONTROLLER); in tb_switch_alloc()
1556 sw->cap_lc = ret; in tb_switch_alloc()
1560 sw->authorized = true; in tb_switch_alloc()
1562 device_initialize(&sw->dev); in tb_switch_alloc()
1563 sw->dev.parent = parent; in tb_switch_alloc()
1564 sw->dev.bus = &tb_bus_type; in tb_switch_alloc()
1565 sw->dev.type = &tb_switch_type; in tb_switch_alloc()
1566 sw->dev.groups = switch_groups; in tb_switch_alloc()
1567 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc()
1569 return sw; in tb_switch_alloc()
1572 kfree(sw->ports); in tb_switch_alloc()
1573 kfree(sw); in tb_switch_alloc()
1595 struct tb_switch *sw; in tb_switch_alloc_safe_mode() local
1597 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc_safe_mode()
1598 if (!sw) in tb_switch_alloc_safe_mode()
1601 sw->tb = tb; in tb_switch_alloc_safe_mode()
1602 sw->config.depth = tb_route_length(route); in tb_switch_alloc_safe_mode()
1603 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc_safe_mode()
1604 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc_safe_mode()
1605 sw->safe_mode = true; in tb_switch_alloc_safe_mode()
1607 device_initialize(&sw->dev); in tb_switch_alloc_safe_mode()
1608 sw->dev.parent = parent; in tb_switch_alloc_safe_mode()
1609 sw->dev.bus = &tb_bus_type; in tb_switch_alloc_safe_mode()
1610 sw->dev.type = &tb_switch_type; in tb_switch_alloc_safe_mode()
1611 sw->dev.groups = switch_groups; in tb_switch_alloc_safe_mode()
1612 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc_safe_mode()
1614 return sw; in tb_switch_alloc_safe_mode()
1627 int tb_switch_configure(struct tb_switch *sw) in tb_switch_configure() argument
1629 struct tb *tb = sw->tb; in tb_switch_configure()
1633 route = tb_route(sw); in tb_switch_configure()
1635 route, tb_route_length(route), sw->config.upstream_port_number); in tb_switch_configure()
1637 if (sw->config.vendor_id != PCI_VENDOR_ID_INTEL) in tb_switch_configure()
1638 tb_sw_warn(sw, "unknown switch vendor id %#x\n", in tb_switch_configure()
1639 sw->config.vendor_id); in tb_switch_configure()
1641 sw->config.enabled = 1; in tb_switch_configure()
1644 ret = tb_sw_write(sw, 1 + (u32 *)&sw->config, TB_CFG_SWITCH, 1, 3); in tb_switch_configure()
1648 ret = tb_lc_configure_link(sw); in tb_switch_configure()
1652 return tb_plug_events_active(sw, true); in tb_switch_configure()
1655 static int tb_switch_set_uuid(struct tb_switch *sw) in tb_switch_set_uuid() argument
1660 if (sw->uuid) in tb_switch_set_uuid()
1667 ret = tb_lc_read_uuid(sw, uuid); in tb_switch_set_uuid()
1675 uuid[0] = sw->uid & 0xffffffff; in tb_switch_set_uuid()
1676 uuid[1] = (sw->uid >> 32) & 0xffffffff; in tb_switch_set_uuid()
1681 sw->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL); in tb_switch_set_uuid()
1682 if (!sw->uuid) in tb_switch_set_uuid()
1687 static int tb_switch_add_dma_port(struct tb_switch *sw) in tb_switch_add_dma_port() argument
1692 switch (sw->generation) { in tb_switch_add_dma_port()
1698 if (tb_route(sw)) in tb_switch_add_dma_port()
1707 if (!sw->safe_mode) in tb_switch_add_dma_port()
1713 if (!tb_route(sw) && sw->config.enabled) in tb_switch_add_dma_port()
1716 sw->dma_port = dma_port_alloc(sw); in tb_switch_add_dma_port()
1717 if (!sw->dma_port) in tb_switch_add_dma_port()
1720 if (sw->no_nvm_upgrade) in tb_switch_add_dma_port()
1728 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in tb_switch_add_dma_port()
1733 if (!tb_route(sw)) in tb_switch_add_dma_port()
1734 nvm_authenticate_complete(sw); in tb_switch_add_dma_port()
1737 tb_sw_info(sw, "switch flash authentication failed\n"); in tb_switch_add_dma_port()
1738 ret = tb_switch_set_uuid(sw); in tb_switch_add_dma_port()
1741 nvm_set_auth_status(sw, status); in tb_switch_add_dma_port()
1744 tb_sw_info(sw, "power cycling the switch now\n"); in tb_switch_add_dma_port()
1745 dma_port_power_cycle(sw->dma_port); in tb_switch_add_dma_port()
1766 int tb_switch_add(struct tb_switch *sw) in tb_switch_add() argument
1777 ret = tb_switch_add_dma_port(sw); in tb_switch_add()
1781 if (!sw->safe_mode) { in tb_switch_add()
1783 ret = tb_drom_read(sw); in tb_switch_add()
1785 tb_sw_warn(sw, "tb_eeprom_read_rom failed\n"); in tb_switch_add()
1788 tb_sw_dbg(sw, "uid: %#llx\n", sw->uid); in tb_switch_add()
1790 ret = tb_switch_set_uuid(sw); in tb_switch_add()
1794 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_add()
1795 if (sw->ports[i].disabled) { in tb_switch_add()
1796 tb_port_dbg(&sw->ports[i], "disabled by eeprom\n"); in tb_switch_add()
1799 ret = tb_init_port(&sw->ports[i]); in tb_switch_add()
1805 ret = device_add(&sw->dev); in tb_switch_add()
1809 if (tb_route(sw)) { in tb_switch_add()
1810 dev_info(&sw->dev, "new device found, vendor=%#x device=%#x\n", in tb_switch_add()
1811 sw->vendor, sw->device); in tb_switch_add()
1812 if (sw->vendor_name && sw->device_name) in tb_switch_add()
1813 dev_info(&sw->dev, "%s %s\n", sw->vendor_name, in tb_switch_add()
1814 sw->device_name); in tb_switch_add()
1817 ret = tb_switch_nvm_add(sw); in tb_switch_add()
1819 device_del(&sw->dev); in tb_switch_add()
1823 pm_runtime_set_active(&sw->dev); in tb_switch_add()
1824 if (sw->rpm) { in tb_switch_add()
1825 pm_runtime_set_autosuspend_delay(&sw->dev, TB_AUTOSUSPEND_DELAY); in tb_switch_add()
1826 pm_runtime_use_autosuspend(&sw->dev); in tb_switch_add()
1827 pm_runtime_mark_last_busy(&sw->dev); in tb_switch_add()
1828 pm_runtime_enable(&sw->dev); in tb_switch_add()
1829 pm_request_autosuspend(&sw->dev); in tb_switch_add()
1843 void tb_switch_remove(struct tb_switch *sw) in tb_switch_remove() argument
1847 if (sw->rpm) { in tb_switch_remove()
1848 pm_runtime_get_sync(&sw->dev); in tb_switch_remove()
1849 pm_runtime_disable(&sw->dev); in tb_switch_remove()
1853 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_remove()
1854 if (tb_port_has_remote(&sw->ports[i])) { in tb_switch_remove()
1855 tb_switch_remove(sw->ports[i].remote->sw); in tb_switch_remove()
1856 sw->ports[i].remote = NULL; in tb_switch_remove()
1857 } else if (sw->ports[i].xdomain) { in tb_switch_remove()
1858 tb_xdomain_remove(sw->ports[i].xdomain); in tb_switch_remove()
1859 sw->ports[i].xdomain = NULL; in tb_switch_remove()
1863 if (!sw->is_unplugged) in tb_switch_remove()
1864 tb_plug_events_active(sw, false); in tb_switch_remove()
1865 tb_lc_unconfigure_link(sw); in tb_switch_remove()
1867 tb_switch_nvm_remove(sw); in tb_switch_remove()
1869 if (tb_route(sw)) in tb_switch_remove()
1870 dev_info(&sw->dev, "device disconnected\n"); in tb_switch_remove()
1871 device_unregister(&sw->dev); in tb_switch_remove()
1877 void tb_sw_set_unplugged(struct tb_switch *sw) in tb_sw_set_unplugged() argument
1880 if (sw == sw->tb->root_switch) { in tb_sw_set_unplugged()
1881 tb_sw_WARN(sw, "cannot unplug root switch\n"); in tb_sw_set_unplugged()
1884 if (sw->is_unplugged) { in tb_sw_set_unplugged()
1885 tb_sw_WARN(sw, "is_unplugged already set\n"); in tb_sw_set_unplugged()
1888 sw->is_unplugged = true; in tb_sw_set_unplugged()
1889 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_sw_set_unplugged()
1890 if (tb_port_has_remote(&sw->ports[i])) in tb_sw_set_unplugged()
1891 tb_sw_set_unplugged(sw->ports[i].remote->sw); in tb_sw_set_unplugged()
1892 else if (sw->ports[i].xdomain) in tb_sw_set_unplugged()
1893 sw->ports[i].xdomain->is_unplugged = true; in tb_sw_set_unplugged()
1897 int tb_switch_resume(struct tb_switch *sw) in tb_switch_resume() argument
1900 tb_sw_dbg(sw, "resuming switch\n"); in tb_switch_resume()
1906 if (tb_route(sw)) { in tb_switch_resume()
1914 err = tb_cfg_get_upstream_port(sw->tb->ctl, tb_route(sw)); in tb_switch_resume()
1916 tb_sw_info(sw, "switch not present anymore\n"); in tb_switch_resume()
1920 err = tb_drom_read_uid_only(sw, &uid); in tb_switch_resume()
1922 tb_sw_warn(sw, "uid read failed\n"); in tb_switch_resume()
1925 if (sw->uid != uid) { in tb_switch_resume()
1926 tb_sw_info(sw, in tb_switch_resume()
1928 sw->uid, uid); in tb_switch_resume()
1934 err = tb_sw_write(sw, 1 + (u32 *) &sw->config, TB_CFG_SWITCH, 1, 3); in tb_switch_resume()
1938 err = tb_lc_configure_link(sw); in tb_switch_resume()
1942 err = tb_plug_events_active(sw, true); in tb_switch_resume()
1947 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_resume()
1948 struct tb_port *port = &sw->ports[i]; in tb_switch_resume()
1957 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
1961 if (tb_switch_resume(port->remote->sw)) { in tb_switch_resume()
1964 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
1971 void tb_switch_suspend(struct tb_switch *sw) in tb_switch_suspend() argument
1974 err = tb_plug_events_active(sw, false); in tb_switch_suspend()
1978 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_suspend()
1979 if (tb_port_has_remote(&sw->ports[i])) in tb_switch_suspend()
1980 tb_switch_suspend(sw->ports[i].remote->sw); in tb_switch_suspend()
1983 tb_lc_set_sleep(sw); in tb_switch_suspend()
1996 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_match() local
1999 if (!sw) in tb_switch_match()
2001 if (sw->tb != lookup->tb) in tb_switch_match()
2005 return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid)); in tb_switch_match()
2008 return sw->config.route_lo == lower_32_bits(lookup->route) && in tb_switch_match()
2009 sw->config.route_hi == upper_32_bits(lookup->route); in tb_switch_match()
2014 return !sw->depth; in tb_switch_match()
2016 return sw->link == lookup->link && sw->depth == lookup->depth; in tb_switch_match()