Lines Matching full:sw

37 static struct nvm_auth_status *__nvm_get_auth_status(const struct tb_switch *sw)  in __nvm_get_auth_status()  argument
42 if (uuid_equal(&st->uuid, sw->uuid)) in __nvm_get_auth_status()
49 static void nvm_get_auth_status(const struct tb_switch *sw, u32 *status) in nvm_get_auth_status() argument
54 st = __nvm_get_auth_status(sw); in nvm_get_auth_status()
60 static void nvm_set_auth_status(const struct tb_switch *sw, u32 status) in nvm_set_auth_status() argument
64 if (WARN_ON(!sw->uuid)) in nvm_set_auth_status()
68 st = __nvm_get_auth_status(sw); in nvm_set_auth_status()
75 memcpy(&st->uuid, sw->uuid, sizeof(st->uuid)); in nvm_set_auth_status()
85 static void nvm_clear_auth_status(const struct tb_switch *sw) in nvm_clear_auth_status() argument
90 st = __nvm_get_auth_status(sw); in nvm_clear_auth_status()
98 static int nvm_validate_and_write(struct tb_switch *sw) in nvm_validate_and_write() argument
104 ret = tb_nvm_validate(sw->nvm); in nvm_validate_and_write()
108 ret = tb_nvm_write_headers(sw->nvm); in nvm_validate_and_write()
112 buf = sw->nvm->buf_data_start; in nvm_validate_and_write()
113 image_size = sw->nvm->buf_data_size; in nvm_validate_and_write()
115 if (tb_switch_is_usb4(sw)) in nvm_validate_and_write()
116 ret = usb4_switch_nvm_write(sw, 0, buf, image_size); in nvm_validate_and_write()
118 ret = dma_port_flash_write(sw->dma_port, 0, buf, image_size); in nvm_validate_and_write()
122 sw->nvm->flushed = true; in nvm_validate_and_write()
126 static int nvm_authenticate_host_dma_port(struct tb_switch *sw) in nvm_authenticate_host_dma_port() argument
135 if (!sw->safe_mode) { in nvm_authenticate_host_dma_port()
138 ret = tb_domain_disconnect_all_paths(sw->tb); in nvm_authenticate_host_dma_port()
145 ret = dma_port_flash_update_auth(sw->dma_port); in nvm_authenticate_host_dma_port()
153 tb_sw_warn(sw, "failed to authenticate NVM, power cycling\n"); in nvm_authenticate_host_dma_port()
154 if (dma_port_flash_update_auth_status(sw->dma_port, &status) > 0) in nvm_authenticate_host_dma_port()
155 nvm_set_auth_status(sw, status); in nvm_authenticate_host_dma_port()
162 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_host_dma_port()
166 static int nvm_authenticate_device_dma_port(struct tb_switch *sw) in nvm_authenticate_device_dma_port() argument
170 ret = dma_port_flash_update_auth(sw->dma_port); in nvm_authenticate_device_dma_port()
191 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in nvm_authenticate_device_dma_port()
196 tb_sw_warn(sw, "failed to authenticate NVM\n"); in nvm_authenticate_device_dma_port()
197 nvm_set_auth_status(sw, status); in nvm_authenticate_device_dma_port()
200 tb_sw_info(sw, "power cycling the switch now\n"); in nvm_authenticate_device_dma_port()
201 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_device_dma_port()
211 static void nvm_authenticate_start_dma_port(struct tb_switch *sw) in nvm_authenticate_start_dma_port() argument
221 root_port = pcie_find_root_port(sw->tb->nhi->pdev); in nvm_authenticate_start_dma_port()
226 static void nvm_authenticate_complete_dma_port(struct tb_switch *sw) in nvm_authenticate_complete_dma_port() argument
230 root_port = pcie_find_root_port(sw->tb->nhi->pdev); in nvm_authenticate_complete_dma_port()
235 static inline bool nvm_readable(struct tb_switch *sw) in nvm_readable() argument
237 if (tb_switch_is_usb4(sw)) { in nvm_readable()
244 return usb4_switch_nvm_sector_size(sw) > 0; in nvm_readable()
248 return !!sw->dma_port; in nvm_readable()
251 static inline bool nvm_upgradeable(struct tb_switch *sw) in nvm_upgradeable() argument
253 if (sw->no_nvm_upgrade) in nvm_upgradeable()
255 return nvm_readable(sw); in nvm_upgradeable()
258 static int nvm_authenticate(struct tb_switch *sw, bool auth_only) in nvm_authenticate() argument
262 if (tb_switch_is_usb4(sw)) { in nvm_authenticate()
264 ret = usb4_switch_nvm_set_offset(sw, 0); in nvm_authenticate()
268 sw->nvm->authenticating = true; in nvm_authenticate()
269 return usb4_switch_nvm_authenticate(sw); in nvm_authenticate()
274 sw->nvm->authenticating = true; in nvm_authenticate()
275 if (!tb_route(sw)) { in nvm_authenticate()
276 nvm_authenticate_start_dma_port(sw); in nvm_authenticate()
277 ret = nvm_authenticate_host_dma_port(sw); in nvm_authenticate()
279 ret = nvm_authenticate_device_dma_port(sw); in nvm_authenticate()
287 * @sw: Router whose NVM to read
296 int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf, in tb_switch_nvm_read() argument
299 if (tb_switch_is_usb4(sw)) in tb_switch_nvm_read()
300 return usb4_switch_nvm_read(sw, address, buf, size); in tb_switch_nvm_read()
301 return dma_port_flash_read(sw->dma_port, address, buf, size); in tb_switch_nvm_read()
307 struct tb_switch *sw = tb_to_switch(nvm->dev); in nvm_read() local
310 pm_runtime_get_sync(&sw->dev); in nvm_read()
312 if (!mutex_trylock(&sw->tb->lock)) { in nvm_read()
317 ret = tb_switch_nvm_read(sw, offset, val, bytes); in nvm_read()
318 mutex_unlock(&sw->tb->lock); in nvm_read()
321 pm_runtime_mark_last_busy(&sw->dev); in nvm_read()
322 pm_runtime_put_autosuspend(&sw->dev); in nvm_read()
330 struct tb_switch *sw = tb_to_switch(nvm->dev); in nvm_write() local
333 if (!mutex_trylock(&sw->tb->lock)) in nvm_write()
343 mutex_unlock(&sw->tb->lock); in nvm_write()
348 static int tb_switch_nvm_add(struct tb_switch *sw) in tb_switch_nvm_add() argument
353 if (!nvm_readable(sw)) in tb_switch_nvm_add()
356 nvm = tb_nvm_alloc(&sw->dev); in tb_switch_nvm_add()
371 if (!sw->safe_mode) { in tb_switch_nvm_add()
375 tb_sw_dbg(sw, "NVM version %x.%x\n", nvm->major, nvm->minor); in tb_switch_nvm_add()
378 if (!sw->no_nvm_upgrade) { in tb_switch_nvm_add()
384 sw->nvm = nvm; in tb_switch_nvm_add()
388 tb_sw_dbg(sw, "NVM upgrade disabled\n"); in tb_switch_nvm_add()
389 sw->no_nvm_upgrade = true; in tb_switch_nvm_add()
396 static void tb_switch_nvm_remove(struct tb_switch *sw) in tb_switch_nvm_remove() argument
400 nvm = sw->nvm; in tb_switch_nvm_remove()
401 sw->nvm = NULL; in tb_switch_nvm_remove()
408 nvm_clear_auth_status(sw); in tb_switch_nvm_remove()
571 if (credits == 0 || port->sw->is_unplugged) in tb_port_add_nfc_credits()
578 if (tb_switch_is_usb4(port->sw) && !tb_port_is_null(port)) in tb_port_add_nfc_credits()
620 if (tb_switch_is_icm(port->sw)) in tb_port_unlock()
624 if (tb_switch_is_usb4(port->sw)) in tb_port_unlock()
701 tb_dbg(port->sw->tb, " Port %d: not implemented\n", in tb_init_port()
746 tb_dump_port(port->sw->tb, port); in tb_init_port()
826 const struct tb_switch *sw) in tb_switch_is_reachable() argument
829 return (tb_route(parent) & mask) == (tb_route(sw) & mask); in tb_switch_is_reachable()
855 if (prev->sw == end->sw) { in tb_next_port_on_path()
861 if (tb_switch_is_reachable(prev->sw, end->sw)) { in tb_next_port_on_path()
862 next = tb_port_at(tb_route(end->sw), prev->sw); in tb_next_port_on_path()
871 next = tb_upstream_port(prev->sw); in tb_next_port_on_path()
1262 if (tb_switch_is_usb4(port->sw)) in tb_port_start_lane_initialization()
1437 if (tb_switch_is_usb4(port->sw)) in tb_dp_port_set_hops()
1503 static const char *tb_switch_generation_name(const struct tb_switch *sw) in tb_switch_generation_name() argument
1505 switch (sw->generation) { in tb_switch_generation_name()
1519 static void tb_dump_switch(const struct tb *tb, const struct tb_switch *sw) in tb_dump_switch() argument
1521 const struct tb_regs_switch_header *regs = &sw->config; in tb_dump_switch()
1524 tb_switch_generation_name(sw), regs->vendor_id, regs->device_id, in tb_dump_switch()
1539 * @sw: Switch to reset
1543 int tb_switch_reset(struct tb_switch *sw) in tb_switch_reset() argument
1547 if (sw->generation > 1) in tb_switch_reset()
1550 tb_sw_dbg(sw, "resetting switch\n"); in tb_switch_reset()
1552 res.err = tb_sw_write(sw, ((u32 *) &sw->config) + 2, in tb_switch_reset()
1556 res = tb_cfg_reset(sw->tb->ctl, tb_route(sw)); in tb_switch_reset()
1564 * @sw: Router to read the offset value from
1574 int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit, in tb_switch_wait_for_bit() argument
1583 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_wait_for_bit()
1603 static int tb_plug_events_active(struct tb_switch *sw, bool active) in tb_plug_events_active() argument
1608 if (tb_switch_is_icm(sw) || tb_switch_is_usb4(sw)) in tb_plug_events_active()
1611 sw->config.plug_events_delay = 0xff; in tb_plug_events_active()
1612 res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1); in tb_plug_events_active()
1616 res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1622 switch (sw->config.device_id) { in tb_plug_events_active()
1633 if (!tb_switch_is_alpine_ridge(sw)) in tb_plug_events_active()
1639 return tb_sw_write(sw, &data, TB_CFG_SWITCH, in tb_plug_events_active()
1640 sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1647 struct tb_switch *sw = tb_to_switch(dev); in authorized_show() local
1649 return sysfs_emit(buf, "%u\n", sw->authorized); in authorized_show()
1655 struct tb_switch *sw; in disapprove_switch() local
1657 sw = tb_to_switch(dev); in disapprove_switch()
1658 if (sw && sw->authorized) { in disapprove_switch()
1662 ret = device_for_each_child_reverse(&sw->dev, NULL, disapprove_switch); in disapprove_switch()
1666 ret = tb_domain_disapprove_switch(sw->tb, sw); in disapprove_switch()
1670 sw->authorized = 0; in disapprove_switch()
1671 kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); in disapprove_switch()
1677 static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val) in tb_switch_set_authorized() argument
1683 if (!mutex_trylock(&sw->tb->lock)) in tb_switch_set_authorized()
1686 if (!!sw->authorized == !!val) in tb_switch_set_authorized()
1692 if (tb_route(sw)) { in tb_switch_set_authorized()
1693 ret = disapprove_switch(&sw->dev, NULL); in tb_switch_set_authorized()
1700 if (sw->key) in tb_switch_set_authorized()
1701 ret = tb_domain_approve_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1703 ret = tb_domain_approve_switch(sw->tb, sw); in tb_switch_set_authorized()
1708 if (sw->key) in tb_switch_set_authorized()
1709 ret = tb_domain_challenge_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1717 sw->authorized = val; in tb_switch_set_authorized()
1722 sprintf(envp_string, "AUTHORIZED=%u", sw->authorized); in tb_switch_set_authorized()
1723 kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); in tb_switch_set_authorized()
1727 mutex_unlock(&sw->tb->lock); in tb_switch_set_authorized()
1735 struct tb_switch *sw = tb_to_switch(dev); in authorized_store() local
1745 pm_runtime_get_sync(&sw->dev); in authorized_store()
1746 ret = tb_switch_set_authorized(sw, val); in authorized_store()
1747 pm_runtime_mark_last_busy(&sw->dev); in authorized_store()
1748 pm_runtime_put_autosuspend(&sw->dev); in authorized_store()
1757 struct tb_switch *sw = tb_to_switch(dev); in boot_show() local
1759 return sysfs_emit(buf, "%u\n", sw->boot); in boot_show()
1766 struct tb_switch *sw = tb_to_switch(dev); in device_show() local
1768 return sysfs_emit(buf, "%#x\n", sw->device); in device_show()
1775 struct tb_switch *sw = tb_to_switch(dev); in device_name_show() local
1777 return sysfs_emit(buf, "%s\n", sw->device_name ?: ""); in device_name_show()
1784 struct tb_switch *sw = tb_to_switch(dev); in generation_show() local
1786 return sysfs_emit(buf, "%u\n", sw->generation); in generation_show()
1793 struct tb_switch *sw = tb_to_switch(dev); in key_show() local
1796 if (!mutex_trylock(&sw->tb->lock)) in key_show()
1799 if (sw->key) in key_show()
1800 ret = sysfs_emit(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key); in key_show()
1804 mutex_unlock(&sw->tb->lock); in key_show()
1811 struct tb_switch *sw = tb_to_switch(dev); in key_store() local
1821 if (!mutex_trylock(&sw->tb->lock)) in key_store()
1824 if (sw->authorized) { in key_store()
1827 kfree(sw->key); in key_store()
1829 sw->key = NULL; in key_store()
1831 sw->key = kmemdup(key, sizeof(key), GFP_KERNEL); in key_store()
1832 if (!sw->key) in key_store()
1837 mutex_unlock(&sw->tb->lock); in key_store()
1845 struct tb_switch *sw = tb_to_switch(dev); in speed_show() local
1847 return sysfs_emit(buf, "%u.0 Gb/s\n", sw->link_speed); in speed_show()
1860 struct tb_switch *sw = tb_to_switch(dev); in rx_lanes_show() local
1863 switch (sw->link_width) { in rx_lanes_show()
1886 struct tb_switch *sw = tb_to_switch(dev); in tx_lanes_show() local
1889 switch (sw->link_width) { in tx_lanes_show()
1912 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_show() local
1915 nvm_get_auth_status(sw, &status); in nvm_authenticate_show()
1922 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_sysfs() local
1925 pm_runtime_get_sync(&sw->dev); in nvm_authenticate_sysfs()
1927 if (!mutex_trylock(&sw->tb->lock)) { in nvm_authenticate_sysfs()
1932 if (sw->no_nvm_upgrade) { in nvm_authenticate_sysfs()
1938 if (!sw->nvm) { in nvm_authenticate_sysfs()
1948 nvm_clear_auth_status(sw); in nvm_authenticate_sysfs()
1955 ret = nvm_authenticate(sw, true); in nvm_authenticate_sysfs()
1957 if (!sw->nvm->flushed) { in nvm_authenticate_sysfs()
1958 if (!sw->nvm->buf) { in nvm_authenticate_sysfs()
1963 ret = nvm_validate_and_write(sw); in nvm_authenticate_sysfs()
1969 ret = tb_lc_force_power(sw); in nvm_authenticate_sysfs()
1971 ret = nvm_authenticate(sw, false); in nvm_authenticate_sysfs()
1977 mutex_unlock(&sw->tb->lock); in nvm_authenticate_sysfs()
1979 pm_runtime_mark_last_busy(&sw->dev); in nvm_authenticate_sysfs()
1980 pm_runtime_put_autosuspend(&sw->dev); in nvm_authenticate_sysfs()
2014 struct tb_switch *sw = tb_to_switch(dev); in nvm_version_show() local
2017 if (!mutex_trylock(&sw->tb->lock)) in nvm_version_show()
2020 if (sw->safe_mode) in nvm_version_show()
2022 else if (!sw->nvm) in nvm_version_show()
2025 ret = sysfs_emit(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor); in nvm_version_show()
2027 mutex_unlock(&sw->tb->lock); in nvm_version_show()
2036 struct tb_switch *sw = tb_to_switch(dev); in vendor_show() local
2038 return sysfs_emit(buf, "%#x\n", sw->vendor); in vendor_show()
2045 struct tb_switch *sw = tb_to_switch(dev); in vendor_name_show() local
2047 return sysfs_emit(buf, "%s\n", sw->vendor_name ?: ""); in vendor_name_show()
2054 struct tb_switch *sw = tb_to_switch(dev); in unique_id_show() local
2056 return sysfs_emit(buf, "%pUb\n", sw->uuid); in unique_id_show()
2084 struct tb_switch *sw = tb_to_switch(dev); in switch_attr_is_visible() local
2087 if (sw->tb->security_level == TB_SECURITY_NOPCIE || in switch_attr_is_visible()
2088 sw->tb->security_level == TB_SECURITY_DPONLY) in switch_attr_is_visible()
2091 if (!sw->device) in switch_attr_is_visible()
2094 if (!sw->device_name) in switch_attr_is_visible()
2097 if (!sw->vendor) in switch_attr_is_visible()
2100 if (!sw->vendor_name) in switch_attr_is_visible()
2103 if (tb_route(sw) && in switch_attr_is_visible()
2104 sw->tb->security_level == TB_SECURITY_SECURE && in switch_attr_is_visible()
2105 sw->security_level == TB_SECURITY_SECURE) in switch_attr_is_visible()
2112 if (tb_route(sw)) in switch_attr_is_visible()
2116 if (nvm_upgradeable(sw)) in switch_attr_is_visible()
2120 if (nvm_readable(sw)) in switch_attr_is_visible()
2124 if (tb_route(sw)) in switch_attr_is_visible()
2128 if (sw->quirks & QUIRK_FORCE_POWER_LINK_CONTROLLER) in switch_attr_is_visible()
2133 return sw->safe_mode ? 0 : attr->mode; in switch_attr_is_visible()
2148 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_release() local
2151 dma_port_free(sw->dma_port); in tb_switch_release()
2153 tb_switch_for_each_port(sw, port) { in tb_switch_release()
2158 kfree(sw->uuid); in tb_switch_release()
2159 kfree(sw->device_name); in tb_switch_release()
2160 kfree(sw->vendor_name); in tb_switch_release()
2161 kfree(sw->ports); in tb_switch_release()
2162 kfree(sw->drom); in tb_switch_release()
2163 kfree(sw->key); in tb_switch_release()
2164 kfree(sw); in tb_switch_release()
2169 const struct tb_switch *sw = tb_to_switch(dev); in tb_switch_uevent() local
2172 if (tb_switch_is_usb4(sw)) { in tb_switch_uevent()
2174 usb4_switch_version(sw))) in tb_switch_uevent()
2178 if (!tb_route(sw)) { in tb_switch_uevent()
2185 tb_switch_for_each_port(sw, port) { in tb_switch_uevent()
2207 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_suspend() local
2208 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_suspend()
2211 return cm_ops->runtime_suspend_switch(sw); in tb_switch_runtime_suspend()
2218 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_resume() local
2219 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_resume()
2222 return cm_ops->runtime_resume_switch(sw); in tb_switch_runtime_resume()
2238 static int tb_switch_get_generation(struct tb_switch *sw) in tb_switch_get_generation() argument
2240 if (tb_switch_is_usb4(sw)) in tb_switch_get_generation()
2243 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_get_generation()
2244 switch (sw->config.device_id) { in tb_switch_get_generation()
2278 tb_sw_warn(sw, "unsupported switch device id %#x\n", in tb_switch_get_generation()
2279 sw->config.device_id); in tb_switch_get_generation()
2283 static bool tb_switch_exceeds_max_depth(const struct tb_switch *sw, int depth) in tb_switch_exceeds_max_depth() argument
2287 if (tb_switch_is_usb4(sw) || in tb_switch_exceeds_max_depth()
2288 (sw->tb->root_switch && tb_switch_is_usb4(sw->tb->root_switch))) in tb_switch_exceeds_max_depth()
2313 struct tb_switch *sw; in tb_switch_alloc() local
2332 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc()
2333 if (!sw) in tb_switch_alloc()
2336 sw->tb = tb; in tb_switch_alloc()
2337 ret = tb_cfg_read(tb->ctl, &sw->config, route, 0, TB_CFG_SWITCH, 0, 5); in tb_switch_alloc()
2341 sw->generation = tb_switch_get_generation(sw); in tb_switch_alloc()
2344 tb_dump_switch(tb, sw); in tb_switch_alloc()
2347 sw->config.upstream_port_number = upstream_port; in tb_switch_alloc()
2348 sw->config.depth = depth; in tb_switch_alloc()
2349 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc()
2350 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc()
2351 sw->config.enabled = 0; in tb_switch_alloc()
2354 if (tb_switch_exceeds_max_depth(sw, depth)) { in tb_switch_alloc()
2360 sw->ports = kcalloc(sw->config.max_port_number + 1, sizeof(*sw->ports), in tb_switch_alloc()
2362 if (!sw->ports) { in tb_switch_alloc()
2367 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_alloc()
2369 sw->ports[i].sw = sw; in tb_switch_alloc()
2370 sw->ports[i].port = i; in tb_switch_alloc()
2374 ida_init(&sw->ports[i].in_hopids); in tb_switch_alloc()
2375 ida_init(&sw->ports[i].out_hopids); in tb_switch_alloc()
2379 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_PLUG_EVENTS); in tb_switch_alloc()
2381 sw->cap_plug_events = ret; in tb_switch_alloc()
2383 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_TIME2); in tb_switch_alloc()
2385 sw->cap_vsec_tmu = ret; in tb_switch_alloc()
2387 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_LINK_CONTROLLER); in tb_switch_alloc()
2389 sw->cap_lc = ret; in tb_switch_alloc()
2391 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_CP_LP); in tb_switch_alloc()
2393 sw->cap_lp = ret; in tb_switch_alloc()
2397 sw->authorized = true; in tb_switch_alloc()
2399 device_initialize(&sw->dev); in tb_switch_alloc()
2400 sw->dev.parent = parent; in tb_switch_alloc()
2401 sw->dev.bus = &tb_bus_type; in tb_switch_alloc()
2402 sw->dev.type = &tb_switch_type; in tb_switch_alloc()
2403 sw->dev.groups = switch_groups; in tb_switch_alloc()
2404 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc()
2406 return sw; in tb_switch_alloc()
2409 kfree(sw->ports); in tb_switch_alloc()
2410 kfree(sw); in tb_switch_alloc()
2432 struct tb_switch *sw; in tb_switch_alloc_safe_mode() local
2434 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc_safe_mode()
2435 if (!sw) in tb_switch_alloc_safe_mode()
2438 sw->tb = tb; in tb_switch_alloc_safe_mode()
2439 sw->config.depth = tb_route_length(route); in tb_switch_alloc_safe_mode()
2440 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc_safe_mode()
2441 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc_safe_mode()
2442 sw->safe_mode = true; in tb_switch_alloc_safe_mode()
2444 device_initialize(&sw->dev); in tb_switch_alloc_safe_mode()
2445 sw->dev.parent = parent; in tb_switch_alloc_safe_mode()
2446 sw->dev.bus = &tb_bus_type; in tb_switch_alloc_safe_mode()
2447 sw->dev.type = &tb_switch_type; in tb_switch_alloc_safe_mode()
2448 sw->dev.groups = switch_groups; in tb_switch_alloc_safe_mode()
2449 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc_safe_mode()
2451 return sw; in tb_switch_alloc_safe_mode()
2456 * @sw: Switch to configure
2465 int tb_switch_configure(struct tb_switch *sw) in tb_switch_configure() argument
2467 struct tb *tb = sw->tb; in tb_switch_configure()
2471 route = tb_route(sw); in tb_switch_configure()
2474 sw->config.enabled ? "restoring" : "initializing", route, in tb_switch_configure()
2475 tb_route_length(route), sw->config.upstream_port_number); in tb_switch_configure()
2477 sw->config.enabled = 1; in tb_switch_configure()
2479 if (tb_switch_is_usb4(sw)) { in tb_switch_configure()
2486 if (usb4_switch_version(sw) < 2) in tb_switch_configure()
2487 sw->config.cmuv = ROUTER_CS_4_CMUV_V1; in tb_switch_configure()
2489 sw->config.cmuv = ROUTER_CS_4_CMUV_V2; in tb_switch_configure()
2490 sw->config.plug_events_delay = 0xa; in tb_switch_configure()
2493 ret = tb_sw_write(sw, (u32 *)&sw->config + 1, TB_CFG_SWITCH, in tb_switch_configure()
2498 ret = usb4_switch_setup(sw); in tb_switch_configure()
2500 if (sw->config.vendor_id != PCI_VENDOR_ID_INTEL) in tb_switch_configure()
2501 tb_sw_warn(sw, "unknown switch vendor id %#x\n", in tb_switch_configure()
2502 sw->config.vendor_id); in tb_switch_configure()
2504 if (!sw->cap_plug_events) { in tb_switch_configure()
2505 tb_sw_warn(sw, "cannot find TB_VSE_CAP_PLUG_EVENTS aborting\n"); in tb_switch_configure()
2510 ret = tb_sw_write(sw, (u32 *)&sw->config + 1, TB_CFG_SWITCH, in tb_switch_configure()
2516 return tb_plug_events_active(sw, true); in tb_switch_configure()
2521 * @sw: Router to configure
2528 int tb_switch_configuration_valid(struct tb_switch *sw) in tb_switch_configuration_valid() argument
2530 if (tb_switch_is_usb4(sw)) in tb_switch_configuration_valid()
2531 return usb4_switch_configuration_valid(sw); in tb_switch_configuration_valid()
2535 static int tb_switch_set_uuid(struct tb_switch *sw) in tb_switch_set_uuid() argument
2541 if (sw->uuid) in tb_switch_set_uuid()
2544 if (tb_switch_is_usb4(sw)) { in tb_switch_set_uuid()
2545 ret = usb4_switch_read_uid(sw, &sw->uid); in tb_switch_set_uuid()
2554 ret = tb_lc_read_uuid(sw, uuid); in tb_switch_set_uuid()
2569 uuid[0] = sw->uid & 0xffffffff; in tb_switch_set_uuid()
2570 uuid[1] = (sw->uid >> 32) & 0xffffffff; in tb_switch_set_uuid()
2575 sw->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL); in tb_switch_set_uuid()
2576 if (!sw->uuid) in tb_switch_set_uuid()
2581 static int tb_switch_add_dma_port(struct tb_switch *sw) in tb_switch_add_dma_port() argument
2586 switch (sw->generation) { in tb_switch_add_dma_port()
2589 if (tb_route(sw)) in tb_switch_add_dma_port()
2595 ret = tb_switch_set_uuid(sw); in tb_switch_add_dma_port()
2605 if (!sw->safe_mode) in tb_switch_add_dma_port()
2610 if (sw->no_nvm_upgrade) in tb_switch_add_dma_port()
2613 if (tb_switch_is_usb4(sw)) { in tb_switch_add_dma_port()
2614 ret = usb4_switch_nvm_authenticate_status(sw, &status); in tb_switch_add_dma_port()
2619 tb_sw_info(sw, "switch flash authentication failed\n"); in tb_switch_add_dma_port()
2620 nvm_set_auth_status(sw, status); in tb_switch_add_dma_port()
2627 if (!tb_route(sw) && !tb_switch_is_icm(sw)) in tb_switch_add_dma_port()
2630 sw->dma_port = dma_port_alloc(sw); in tb_switch_add_dma_port()
2631 if (!sw->dma_port) in tb_switch_add_dma_port()
2640 nvm_get_auth_status(sw, &status); in tb_switch_add_dma_port()
2642 if (!tb_route(sw)) in tb_switch_add_dma_port()
2643 nvm_authenticate_complete_dma_port(sw); in tb_switch_add_dma_port()
2652 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in tb_switch_add_dma_port()
2657 if (!tb_route(sw)) in tb_switch_add_dma_port()
2658 nvm_authenticate_complete_dma_port(sw); in tb_switch_add_dma_port()
2661 tb_sw_info(sw, "switch flash authentication failed\n"); in tb_switch_add_dma_port()
2662 nvm_set_auth_status(sw, status); in tb_switch_add_dma_port()
2665 tb_sw_info(sw, "power cycling the switch now\n"); in tb_switch_add_dma_port()
2666 dma_port_power_cycle(sw->dma_port); in tb_switch_add_dma_port()
2675 static void tb_switch_default_link_ports(struct tb_switch *sw) in tb_switch_default_link_ports() argument
2679 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_default_link_ports()
2680 struct tb_port *port = &sw->ports[i]; in tb_switch_default_link_ports()
2687 if (i == sw->config.max_port_number || in tb_switch_default_link_ports()
2688 !tb_port_is_null(&sw->ports[i + 1])) in tb_switch_default_link_ports()
2692 subordinate = &sw->ports[i + 1]; in tb_switch_default_link_ports()
2699 tb_sw_dbg(sw, "linked ports %d <-> %d\n", in tb_switch_default_link_ports()
2705 static bool tb_switch_lane_bonding_possible(struct tb_switch *sw) in tb_switch_lane_bonding_possible() argument
2707 const struct tb_port *up = tb_upstream_port(sw); in tb_switch_lane_bonding_possible()
2712 if (tb_switch_is_usb4(sw)) in tb_switch_lane_bonding_possible()
2713 return usb4_switch_lane_bonding_possible(sw); in tb_switch_lane_bonding_possible()
2714 return tb_lc_lane_bonding_possible(sw); in tb_switch_lane_bonding_possible()
2717 static int tb_switch_update_link_attributes(struct tb_switch *sw) in tb_switch_update_link_attributes() argument
2723 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_update_link_attributes()
2726 up = tb_upstream_port(sw); in tb_switch_update_link_attributes()
2731 if (sw->link_speed != ret) in tb_switch_update_link_attributes()
2733 sw->link_speed = ret; in tb_switch_update_link_attributes()
2738 if (sw->link_width != ret) in tb_switch_update_link_attributes()
2740 sw->link_width = ret; in tb_switch_update_link_attributes()
2743 if (device_is_registered(&sw->dev) && change) in tb_switch_update_link_attributes()
2744 kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); in tb_switch_update_link_attributes()
2750 static void tb_switch_link_init(struct tb_switch *sw) in tb_switch_link_init() argument
2755 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_link_init()
2758 tb_sw_dbg(sw, "current link speed %u.0 Gb/s\n", sw->link_speed); in tb_switch_link_init()
2759 tb_sw_dbg(sw, "current link width %s\n", tb_width_name(sw->link_width)); in tb_switch_link_init()
2761 bonded = sw->link_width >= TB_LINK_WIDTH_DUAL; in tb_switch_link_init()
2767 up = tb_upstream_port(sw); in tb_switch_link_init()
2768 down = tb_switch_downstream_port(sw); in tb_switch_link_init()
2789 sw->preferred_link_width = sw->link_width; in tb_switch_link_init()
2790 tb_sw_dbg(sw, "preferred link width %s\n", in tb_switch_link_init()
2791 tb_width_name(sw->preferred_link_width)); in tb_switch_link_init()
2796 * @sw: Switch to enable lane bonding
2802 static int tb_switch_lane_bonding_enable(struct tb_switch *sw) in tb_switch_lane_bonding_enable() argument
2808 if (!tb_switch_lane_bonding_possible(sw)) in tb_switch_lane_bonding_enable()
2811 up = tb_upstream_port(sw); in tb_switch_lane_bonding_enable()
2812 down = tb_switch_downstream_port(sw); in tb_switch_lane_bonding_enable()
2847 * @sw: Switch whose lane bonding to disable
2849 * Disables lane bonding between @sw and parent. This can be called even
2852 static int tb_switch_lane_bonding_disable(struct tb_switch *sw) in tb_switch_lane_bonding_disable() argument
2857 up = tb_upstream_port(sw); in tb_switch_lane_bonding_disable()
2864 * if the link is not up anymore (sw is unplugged). in tb_switch_lane_bonding_disable()
2872 down = tb_switch_downstream_port(sw); in tb_switch_lane_bonding_disable()
2883 /* Note updating sw->link_width done in tb_switch_update_link_attributes() */
2884 static int tb_switch_asym_enable(struct tb_switch *sw, enum tb_link_width width) in tb_switch_asym_enable() argument
2890 up = tb_upstream_port(sw); in tb_switch_asym_enable()
2891 down = tb_switch_downstream_port(sw); in tb_switch_asym_enable()
2913 if (sw->link_width != width) { in tb_switch_asym_enable()
2926 /* Note updating sw->link_width done in tb_switch_update_link_attributes() */
2927 static int tb_switch_asym_disable(struct tb_switch *sw) in tb_switch_asym_disable() argument
2932 up = tb_upstream_port(sw); in tb_switch_asym_disable()
2933 down = tb_switch_downstream_port(sw); in tb_switch_asym_disable()
2948 if (sw->link_width > TB_LINK_WIDTH_DUAL) { in tb_switch_asym_disable()
2949 if (sw->link_width == TB_LINK_WIDTH_ASYM_TX) in tb_switch_asym_disable()
2966 * @sw: Router to configure
2977 int tb_switch_set_link_width(struct tb_switch *sw, enum tb_link_width width) in tb_switch_set_link_width() argument
2982 if (!tb_route(sw)) in tb_switch_set_link_width()
2985 up = tb_upstream_port(sw); in tb_switch_set_link_width()
2986 down = tb_switch_downstream_port(sw); in tb_switch_set_link_width()
2990 ret = tb_switch_lane_bonding_disable(sw); in tb_switch_set_link_width()
2994 if (sw->link_width == TB_LINK_WIDTH_ASYM_TX || in tb_switch_set_link_width()
2995 sw->link_width == TB_LINK_WIDTH_ASYM_RX) { in tb_switch_set_link_width()
2996 ret = tb_switch_asym_disable(sw); in tb_switch_set_link_width()
3000 ret = tb_switch_lane_bonding_enable(sw); in tb_switch_set_link_width()
3005 ret = tb_switch_asym_enable(sw, width); in tb_switch_set_link_width()
3014 tb_sw_warn(sw, "timeout changing link width\n"); in tb_switch_set_link_width()
3023 tb_sw_dbg(sw, "failed to change link width: %d\n", ret); in tb_switch_set_link_width()
3030 tb_switch_update_link_attributes(sw); in tb_switch_set_link_width()
3032 tb_sw_dbg(sw, "link width set to %s\n", tb_width_name(width)); in tb_switch_set_link_width()
3038 * @sw: Switch whose link is configured
3040 * Sets the link upstream from @sw configured (from both ends) so that
3048 int tb_switch_configure_link(struct tb_switch *sw) in tb_switch_configure_link() argument
3053 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_configure_link()
3056 up = tb_upstream_port(sw); in tb_switch_configure_link()
3057 if (tb_switch_is_usb4(up->sw)) in tb_switch_configure_link()
3065 if (tb_switch_is_usb4(down->sw)) in tb_switch_configure_link()
3072 * @sw: Switch whose link is unconfigured
3074 * Sets the link unconfigured so the @sw will be disconnected if the
3077 void tb_switch_unconfigure_link(struct tb_switch *sw) in tb_switch_unconfigure_link() argument
3081 if (sw->is_unplugged) in tb_switch_unconfigure_link()
3083 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_unconfigure_link()
3086 up = tb_upstream_port(sw); in tb_switch_unconfigure_link()
3087 if (tb_switch_is_usb4(up->sw)) in tb_switch_unconfigure_link()
3093 if (tb_switch_is_usb4(down->sw)) in tb_switch_unconfigure_link()
3099 static void tb_switch_credits_init(struct tb_switch *sw) in tb_switch_credits_init() argument
3101 if (tb_switch_is_icm(sw)) in tb_switch_credits_init()
3103 if (!tb_switch_is_usb4(sw)) in tb_switch_credits_init()
3105 if (usb4_switch_credits_init(sw)) in tb_switch_credits_init()
3106 tb_sw_info(sw, "failed to determine preferred buffer allocation, using defaults\n"); in tb_switch_credits_init()
3109 static int tb_switch_port_hotplug_enable(struct tb_switch *sw) in tb_switch_port_hotplug_enable() argument
3113 if (tb_switch_is_icm(sw)) in tb_switch_port_hotplug_enable()
3116 tb_switch_for_each_port(sw, port) { in tb_switch_port_hotplug_enable()
3131 * @sw: Switch to add
3141 int tb_switch_add(struct tb_switch *sw) in tb_switch_add() argument
3152 ret = tb_switch_add_dma_port(sw); in tb_switch_add()
3154 dev_err(&sw->dev, "failed to add DMA port\n"); in tb_switch_add()
3158 if (!sw->safe_mode) { in tb_switch_add()
3159 tb_switch_credits_init(sw); in tb_switch_add()
3162 ret = tb_drom_read(sw); in tb_switch_add()
3164 dev_warn(&sw->dev, "reading DROM failed: %d\n", ret); in tb_switch_add()
3165 tb_sw_dbg(sw, "uid: %#llx\n", sw->uid); in tb_switch_add()
3167 ret = tb_switch_set_uuid(sw); in tb_switch_add()
3169 dev_err(&sw->dev, "failed to set UUID\n"); in tb_switch_add()
3173 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_add()
3174 if (sw->ports[i].disabled) { in tb_switch_add()
3175 tb_port_dbg(&sw->ports[i], "disabled by eeprom\n"); in tb_switch_add()
3178 ret = tb_init_port(&sw->ports[i]); in tb_switch_add()
3180 dev_err(&sw->dev, "failed to initialize port %d\n", i); in tb_switch_add()
3185 tb_check_quirks(sw); in tb_switch_add()
3187 tb_switch_default_link_ports(sw); in tb_switch_add()
3189 ret = tb_switch_update_link_attributes(sw); in tb_switch_add()
3193 tb_switch_link_init(sw); in tb_switch_add()
3195 ret = tb_switch_clx_init(sw); in tb_switch_add()
3199 ret = tb_switch_tmu_init(sw); in tb_switch_add()
3204 ret = tb_switch_port_hotplug_enable(sw); in tb_switch_add()
3208 ret = device_add(&sw->dev); in tb_switch_add()
3210 dev_err(&sw->dev, "failed to add device: %d\n", ret); in tb_switch_add()
3214 if (tb_route(sw)) { in tb_switch_add()
3215 dev_info(&sw->dev, "new device found, vendor=%#x device=%#x\n", in tb_switch_add()
3216 sw->vendor, sw->device); in tb_switch_add()
3217 if (sw->vendor_name && sw->device_name) in tb_switch_add()
3218 dev_info(&sw->dev, "%s %s\n", sw->vendor_name, in tb_switch_add()
3219 sw->device_name); in tb_switch_add()
3222 ret = usb4_switch_add_ports(sw); in tb_switch_add()
3224 dev_err(&sw->dev, "failed to add USB4 ports\n"); in tb_switch_add()
3228 ret = tb_switch_nvm_add(sw); in tb_switch_add()
3230 dev_err(&sw->dev, "failed to add NVM devices\n"); in tb_switch_add()
3239 device_init_wakeup(&sw->dev, true); in tb_switch_add()
3241 pm_runtime_set_active(&sw->dev); in tb_switch_add()
3242 if (sw->rpm) { in tb_switch_add()
3243 pm_runtime_set_autosuspend_delay(&sw->dev, TB_AUTOSUSPEND_DELAY); in tb_switch_add()
3244 pm_runtime_use_autosuspend(&sw->dev); in tb_switch_add()
3245 pm_runtime_mark_last_busy(&sw->dev); in tb_switch_add()
3246 pm_runtime_enable(&sw->dev); in tb_switch_add()
3247 pm_request_autosuspend(&sw->dev); in tb_switch_add()
3250 tb_switch_debugfs_init(sw); in tb_switch_add()
3254 usb4_switch_remove_ports(sw); in tb_switch_add()
3256 device_del(&sw->dev); in tb_switch_add()
3263 * @sw: Switch to remove
3269 void tb_switch_remove(struct tb_switch *sw) in tb_switch_remove() argument
3273 tb_switch_debugfs_remove(sw); in tb_switch_remove()
3275 if (sw->rpm) { in tb_switch_remove()
3276 pm_runtime_get_sync(&sw->dev); in tb_switch_remove()
3277 pm_runtime_disable(&sw->dev); in tb_switch_remove()
3281 tb_switch_for_each_port(sw, port) { in tb_switch_remove()
3283 tb_switch_remove(port->remote->sw); in tb_switch_remove()
3294 if (!sw->is_unplugged) in tb_switch_remove()
3295 tb_plug_events_active(sw, false); in tb_switch_remove()
3297 tb_switch_nvm_remove(sw); in tb_switch_remove()
3298 usb4_switch_remove_ports(sw); in tb_switch_remove()
3300 if (tb_route(sw)) in tb_switch_remove()
3301 dev_info(&sw->dev, "device disconnected\n"); in tb_switch_remove()
3302 device_unregister(&sw->dev); in tb_switch_remove()
3307 * @sw: Router to mark unplugged
3309 void tb_sw_set_unplugged(struct tb_switch *sw) in tb_sw_set_unplugged() argument
3313 if (sw == sw->tb->root_switch) { in tb_sw_set_unplugged()
3314 tb_sw_WARN(sw, "cannot unplug root switch\n"); in tb_sw_set_unplugged()
3317 if (sw->is_unplugged) { in tb_sw_set_unplugged()
3318 tb_sw_WARN(sw, "is_unplugged already set\n"); in tb_sw_set_unplugged()
3321 sw->is_unplugged = true; in tb_sw_set_unplugged()
3322 tb_switch_for_each_port(sw, port) { in tb_sw_set_unplugged()
3324 tb_sw_set_unplugged(port->remote->sw); in tb_sw_set_unplugged()
3330 static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags) in tb_switch_set_wake() argument
3333 tb_sw_dbg(sw, "enabling wakeup: %#x\n", flags); in tb_switch_set_wake()
3335 tb_sw_dbg(sw, "disabling wakeup\n"); in tb_switch_set_wake()
3337 if (tb_switch_is_usb4(sw)) in tb_switch_set_wake()
3338 return usb4_switch_set_wake(sw, flags); in tb_switch_set_wake()
3339 return tb_lc_set_wake(sw, flags); in tb_switch_set_wake()
3342 int tb_switch_resume(struct tb_switch *sw) in tb_switch_resume() argument
3347 tb_sw_dbg(sw, "resuming switch\n"); in tb_switch_resume()
3353 if (tb_route(sw)) { in tb_switch_resume()
3361 err = tb_cfg_get_upstream_port(sw->tb->ctl, tb_route(sw)); in tb_switch_resume()
3363 tb_sw_info(sw, "switch not present anymore\n"); in tb_switch_resume()
3368 if (!sw->uid) in tb_switch_resume()
3371 if (tb_switch_is_usb4(sw)) in tb_switch_resume()
3372 err = usb4_switch_read_uid(sw, &uid); in tb_switch_resume()
3374 err = tb_drom_read_uid_only(sw, &uid); in tb_switch_resume()
3376 tb_sw_warn(sw, "uid read failed\n"); in tb_switch_resume()
3379 if (sw->uid != uid) { in tb_switch_resume()
3380 tb_sw_info(sw, in tb_switch_resume()
3382 sw->uid, uid); in tb_switch_resume()
3387 err = tb_switch_configure(sw); in tb_switch_resume()
3392 tb_switch_set_wake(sw, 0); in tb_switch_resume()
3394 err = tb_switch_tmu_init(sw); in tb_switch_resume()
3399 tb_switch_for_each_port(sw, port) { in tb_switch_resume()
3410 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
3420 if (port->remote && tb_switch_resume(port->remote->sw)) { in tb_switch_resume()
3423 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
3432 * @sw: Switch to suspend
3436 * value of @runtime and then sets sleep bit for the router. If @sw is
3440 void tb_switch_suspend(struct tb_switch *sw, bool runtime) in tb_switch_suspend() argument
3446 tb_sw_dbg(sw, "suspending switch\n"); in tb_switch_suspend()
3452 tb_switch_clx_disable(sw); in tb_switch_suspend()
3454 err = tb_plug_events_active(sw, false); in tb_switch_suspend()
3458 tb_switch_for_each_port(sw, port) { in tb_switch_suspend()
3460 tb_switch_suspend(port->remote->sw, runtime); in tb_switch_suspend()
3468 } else if (device_may_wakeup(&sw->dev)) { in tb_switch_suspend()
3472 tb_switch_set_wake(sw, flags); in tb_switch_suspend()
3474 if (tb_switch_is_usb4(sw)) in tb_switch_suspend()
3475 usb4_switch_set_sleep(sw); in tb_switch_suspend()
3477 tb_lc_set_sleep(sw); in tb_switch_suspend()
3482 * @sw: Switch whose DP resource is queried
3488 bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_query_dp_resource() argument
3490 if (tb_switch_is_usb4(sw)) in tb_switch_query_dp_resource()
3491 return usb4_switch_query_dp_resource(sw, in); in tb_switch_query_dp_resource()
3492 return tb_lc_dp_sink_query(sw, in); in tb_switch_query_dp_resource()
3497 * @sw: Switch whose DP resource is allocated
3504 int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_alloc_dp_resource() argument
3508 if (tb_switch_is_usb4(sw)) in tb_switch_alloc_dp_resource()
3509 ret = usb4_switch_alloc_dp_resource(sw, in); in tb_switch_alloc_dp_resource()
3511 ret = tb_lc_dp_sink_alloc(sw, in); in tb_switch_alloc_dp_resource()
3514 tb_sw_warn(sw, "failed to allocate DP resource for port %d\n", in tb_switch_alloc_dp_resource()
3517 tb_sw_dbg(sw, "allocated DP resource for port %d\n", in->port); in tb_switch_alloc_dp_resource()
3524 * @sw: Switch whose DP resource is de-allocated
3530 void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_dealloc_dp_resource() argument
3534 if (tb_switch_is_usb4(sw)) in tb_switch_dealloc_dp_resource()
3535 ret = usb4_switch_dealloc_dp_resource(sw, in); in tb_switch_dealloc_dp_resource()
3537 ret = tb_lc_dp_sink_dealloc(sw, in); in tb_switch_dealloc_dp_resource()
3540 tb_sw_warn(sw, "failed to de-allocate DP resource for port %d\n", in tb_switch_dealloc_dp_resource()
3543 tb_sw_dbg(sw, "released DP resource for port %d\n", in->port); in tb_switch_dealloc_dp_resource()
3556 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_match() local
3559 if (!sw) in tb_switch_match()
3561 if (sw->tb != lookup->tb) in tb_switch_match()
3565 return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid)); in tb_switch_match()
3568 return sw->config.route_lo == lower_32_bits(lookup->route) && in tb_switch_match()
3569 sw->config.route_hi == upper_32_bits(lookup->route); in tb_switch_match()
3574 return !sw->depth; in tb_switch_match()
3576 return sw->link == lookup->link && sw->depth == lookup->depth; in tb_switch_match()
3657 * tb_switch_find_port() - return the first port of @type on @sw or NULL
3658 * @sw: Switch to find the port from
3661 struct tb_port *tb_switch_find_port(struct tb_switch *sw, in tb_switch_find_port() argument
3666 tb_switch_for_each_port(sw, port) { in tb_switch_find_port()
3678 static int tb_switch_pcie_bridge_write(struct tb_switch *sw, unsigned int bridge, in tb_switch_pcie_bridge_write() argument
3684 if (sw->generation != 3) in tb_switch_pcie_bridge_write()
3687 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_WR_DATA; in tb_switch_pcie_bridge_write()
3688 ret = tb_sw_write(sw, &value, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3699 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_CMD; in tb_switch_pcie_bridge_write()
3701 ret = tb_sw_write(sw, &command, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3705 ret = tb_switch_wait_for_bit(sw, offset, in tb_switch_pcie_bridge_write()
3710 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3722 * @sw: Router to enable PCIe L1
3729 int tb_switch_pcie_l1_enable(struct tb_switch *sw) in tb_switch_pcie_l1_enable() argument
3731 struct tb_switch *parent = tb_switch_parent(sw); in tb_switch_pcie_l1_enable()
3734 if (!tb_route(sw)) in tb_switch_pcie_l1_enable()
3737 if (!tb_switch_is_titan_ridge(sw)) in tb_switch_pcie_l1_enable()
3745 ret = tb_switch_pcie_bridge_write(sw, 5, 0x143, 0x0c7806b1); in tb_switch_pcie_l1_enable()
3750 return tb_switch_pcie_bridge_write(sw, 0, 0x143, 0x0c5806b1); in tb_switch_pcie_l1_enable()
3755 * @sw: Router whose xHCI to connect
3763 int tb_switch_xhci_connect(struct tb_switch *sw) in tb_switch_xhci_connect() argument
3768 if (sw->generation != 3) in tb_switch_xhci_connect()
3771 port1 = &sw->ports[1]; in tb_switch_xhci_connect()
3772 port3 = &sw->ports[3]; in tb_switch_xhci_connect()
3774 if (tb_switch_is_alpine_ridge(sw)) { in tb_switch_xhci_connect()
3790 } else if (tb_switch_is_titan_ridge(sw)) { in tb_switch_xhci_connect()
3802 * @sw: Router whose xHCI to disconnect
3807 void tb_switch_xhci_disconnect(struct tb_switch *sw) in tb_switch_xhci_disconnect() argument
3809 if (sw->generation == 3) { in tb_switch_xhci_disconnect()
3810 struct tb_port *port1 = &sw->ports[1]; in tb_switch_xhci_disconnect()
3811 struct tb_port *port3 = &sw->ports[3]; in tb_switch_xhci_disconnect()