Lines Matching full:sw

40 static struct nvm_auth_status *__nvm_get_auth_status(const struct tb_switch *sw)  in __nvm_get_auth_status()  argument
45 if (uuid_equal(&st->uuid, sw->uuid)) in __nvm_get_auth_status()
52 static void nvm_get_auth_status(const struct tb_switch *sw, u32 *status) in nvm_get_auth_status() argument
57 st = __nvm_get_auth_status(sw); in nvm_get_auth_status()
63 static void nvm_set_auth_status(const struct tb_switch *sw, u32 status) in nvm_set_auth_status() argument
67 if (WARN_ON(!sw->uuid)) in nvm_set_auth_status()
71 st = __nvm_get_auth_status(sw); in nvm_set_auth_status()
78 memcpy(&st->uuid, sw->uuid, sizeof(st->uuid)); in nvm_set_auth_status()
88 static void nvm_clear_auth_status(const struct tb_switch *sw) in nvm_clear_auth_status() argument
93 st = __nvm_get_auth_status(sw); in nvm_clear_auth_status()
101 static int nvm_validate_and_write(struct tb_switch *sw) in nvm_validate_and_write() argument
107 ret = tb_nvm_validate(sw->nvm); in nvm_validate_and_write()
111 ret = tb_nvm_write_headers(sw->nvm); in nvm_validate_and_write()
115 buf = sw->nvm->buf_data_start; in nvm_validate_and_write()
116 image_size = sw->nvm->buf_data_size; in nvm_validate_and_write()
118 if (tb_switch_is_usb4(sw)) in nvm_validate_and_write()
119 ret = usb4_switch_nvm_write(sw, 0, buf, image_size); in nvm_validate_and_write()
121 ret = dma_port_flash_write(sw->dma_port, 0, buf, image_size); in nvm_validate_and_write()
125 sw->nvm->flushed = true; in nvm_validate_and_write()
129 static int nvm_authenticate_host_dma_port(struct tb_switch *sw) in nvm_authenticate_host_dma_port() argument
138 if (!sw->safe_mode) { in nvm_authenticate_host_dma_port()
141 ret = tb_domain_disconnect_all_paths(sw->tb); in nvm_authenticate_host_dma_port()
148 ret = dma_port_flash_update_auth(sw->dma_port); in nvm_authenticate_host_dma_port()
156 tb_sw_warn(sw, "failed to authenticate NVM, power cycling\n"); in nvm_authenticate_host_dma_port()
157 if (dma_port_flash_update_auth_status(sw->dma_port, &status) > 0) in nvm_authenticate_host_dma_port()
158 nvm_set_auth_status(sw, status); in nvm_authenticate_host_dma_port()
165 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_host_dma_port()
169 static int nvm_authenticate_device_dma_port(struct tb_switch *sw) in nvm_authenticate_device_dma_port() argument
173 ret = dma_port_flash_update_auth(sw->dma_port); in nvm_authenticate_device_dma_port()
194 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in nvm_authenticate_device_dma_port()
199 tb_sw_warn(sw, "failed to authenticate NVM\n"); in nvm_authenticate_device_dma_port()
200 nvm_set_auth_status(sw, status); in nvm_authenticate_device_dma_port()
203 tb_sw_info(sw, "power cycling the switch now\n"); in nvm_authenticate_device_dma_port()
204 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_device_dma_port()
214 static void nvm_authenticate_start_dma_port(struct tb_switch *sw) in nvm_authenticate_start_dma_port() argument
224 root_port = pcie_find_root_port(sw->tb->nhi->pdev); in nvm_authenticate_start_dma_port()
229 static void nvm_authenticate_complete_dma_port(struct tb_switch *sw) in nvm_authenticate_complete_dma_port() argument
233 root_port = pcie_find_root_port(sw->tb->nhi->pdev); in nvm_authenticate_complete_dma_port()
238 static inline bool nvm_readable(struct tb_switch *sw) in nvm_readable() argument
240 if (tb_switch_is_usb4(sw)) { in nvm_readable()
247 return usb4_switch_nvm_sector_size(sw) > 0; in nvm_readable()
251 return !!sw->dma_port; in nvm_readable()
254 static inline bool nvm_upgradeable(struct tb_switch *sw) in nvm_upgradeable() argument
256 if (sw->no_nvm_upgrade) in nvm_upgradeable()
258 return nvm_readable(sw); in nvm_upgradeable()
261 static int nvm_authenticate(struct tb_switch *sw, bool auth_only) in nvm_authenticate() argument
265 if (tb_switch_is_usb4(sw)) { in nvm_authenticate()
267 ret = usb4_switch_nvm_set_offset(sw, 0); in nvm_authenticate()
271 sw->nvm->authenticating = true; in nvm_authenticate()
272 return usb4_switch_nvm_authenticate(sw); in nvm_authenticate()
277 sw->nvm->authenticating = true; in nvm_authenticate()
278 if (!tb_route(sw)) { in nvm_authenticate()
279 nvm_authenticate_start_dma_port(sw); in nvm_authenticate()
280 ret = nvm_authenticate_host_dma_port(sw); in nvm_authenticate()
282 ret = nvm_authenticate_device_dma_port(sw); in nvm_authenticate()
290 * @sw: Router whose NVM to read
299 int tb_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf, in tb_switch_nvm_read() argument
302 if (tb_switch_is_usb4(sw)) in tb_switch_nvm_read()
303 return usb4_switch_nvm_read(sw, address, buf, size); in tb_switch_nvm_read()
304 return dma_port_flash_read(sw->dma_port, address, buf, size); in tb_switch_nvm_read()
310 struct tb_switch *sw = tb_to_switch(nvm->dev); in nvm_read() local
313 pm_runtime_get_sync(&sw->dev); in nvm_read()
315 if (!mutex_trylock(&sw->tb->lock)) { in nvm_read()
320 ret = tb_switch_nvm_read(sw, offset, val, bytes); in nvm_read()
321 mutex_unlock(&sw->tb->lock); in nvm_read()
324 pm_runtime_mark_last_busy(&sw->dev); in nvm_read()
325 pm_runtime_put_autosuspend(&sw->dev); in nvm_read()
333 struct tb_switch *sw = tb_to_switch(nvm->dev); in nvm_write() local
336 if (!mutex_trylock(&sw->tb->lock)) in nvm_write()
346 mutex_unlock(&sw->tb->lock); in nvm_write()
351 static int tb_switch_nvm_add(struct tb_switch *sw) in tb_switch_nvm_add() argument
356 if (!nvm_readable(sw)) in tb_switch_nvm_add()
359 nvm = tb_nvm_alloc(&sw->dev); in tb_switch_nvm_add()
374 if (!sw->safe_mode) { in tb_switch_nvm_add()
380 if (!sw->no_nvm_upgrade) { in tb_switch_nvm_add()
386 sw->nvm = nvm; in tb_switch_nvm_add()
390 tb_sw_dbg(sw, "NVM upgrade disabled\n"); in tb_switch_nvm_add()
391 sw->no_nvm_upgrade = true; in tb_switch_nvm_add()
398 static void tb_switch_nvm_remove(struct tb_switch *sw) in tb_switch_nvm_remove() argument
402 nvm = sw->nvm; in tb_switch_nvm_remove()
403 sw->nvm = NULL; in tb_switch_nvm_remove()
410 nvm_clear_auth_status(sw); in tb_switch_nvm_remove()
565 if (credits == 0 || port->sw->is_unplugged) in tb_port_add_nfc_credits()
572 if (tb_switch_is_usb4(port->sw) && !tb_port_is_null(port)) in tb_port_add_nfc_credits()
614 if (tb_switch_is_icm(port->sw)) in tb_port_unlock()
618 if (tb_switch_is_usb4(port->sw)) in tb_port_unlock()
695 tb_dbg(port->sw->tb, " Port %d: not implemented\n", in tb_init_port()
721 if (tb_switch_is_usb4(port->sw)) { in tb_init_port()
740 tb_dump_port(port->sw->tb, port); in tb_init_port()
820 const struct tb_switch *sw) in tb_switch_is_reachable() argument
823 return (tb_route(parent) & mask) == (tb_route(sw) & mask); in tb_switch_is_reachable()
849 if (prev->sw == end->sw) { in tb_next_port_on_path()
855 if (tb_switch_is_reachable(prev->sw, end->sw)) { in tb_next_port_on_path()
856 next = tb_port_at(tb_route(end->sw), prev->sw); in tb_next_port_on_path()
865 next = tb_upstream_port(prev->sw); in tb_next_port_on_path()
1220 if (tb_switch_is_usb4(port->sw)) { in tb_port_clx_supported()
1310 if (tb_switch_is_usb4(port->sw)) in tb_port_start_lane_initialization()
1485 if (tb_switch_is_usb4(port->sw)) in tb_dp_port_set_hops()
1551 static const char *tb_switch_generation_name(const struct tb_switch *sw) in tb_switch_generation_name() argument
1553 switch (sw->generation) { in tb_switch_generation_name()
1567 static void tb_dump_switch(const struct tb *tb, const struct tb_switch *sw) in tb_dump_switch() argument
1569 const struct tb_regs_switch_header *regs = &sw->config; in tb_dump_switch()
1572 tb_switch_generation_name(sw), regs->vendor_id, regs->device_id, in tb_dump_switch()
1587 * @sw: Switch to reset
1591 int tb_switch_reset(struct tb_switch *sw) in tb_switch_reset() argument
1595 if (sw->generation > 1) in tb_switch_reset()
1598 tb_sw_dbg(sw, "resetting switch\n"); in tb_switch_reset()
1600 res.err = tb_sw_write(sw, ((u32 *) &sw->config) + 2, in tb_switch_reset()
1604 res = tb_cfg_reset(sw->tb->ctl, tb_route(sw)); in tb_switch_reset()
1612 * @sw: Router to read the offset value from
1622 int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit, in tb_switch_wait_for_bit() argument
1631 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_wait_for_bit()
1651 static int tb_plug_events_active(struct tb_switch *sw, bool active) in tb_plug_events_active() argument
1656 if (tb_switch_is_icm(sw) || tb_switch_is_usb4(sw)) in tb_plug_events_active()
1659 sw->config.plug_events_delay = 0xff; in tb_plug_events_active()
1660 res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1); in tb_plug_events_active()
1664 res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1670 switch (sw->config.device_id) { in tb_plug_events_active()
1681 if (!tb_switch_is_alpine_ridge(sw)) in tb_plug_events_active()
1687 return tb_sw_write(sw, &data, TB_CFG_SWITCH, in tb_plug_events_active()
1688 sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1695 struct tb_switch *sw = tb_to_switch(dev); in authorized_show() local
1697 return sysfs_emit(buf, "%u\n", sw->authorized); in authorized_show()
1703 struct tb_switch *sw; in disapprove_switch() local
1705 sw = tb_to_switch(dev); in disapprove_switch()
1706 if (sw && sw->authorized) { in disapprove_switch()
1710 ret = device_for_each_child_reverse(&sw->dev, NULL, disapprove_switch); in disapprove_switch()
1714 ret = tb_domain_disapprove_switch(sw->tb, sw); in disapprove_switch()
1718 sw->authorized = 0; in disapprove_switch()
1719 kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); in disapprove_switch()
1725 static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val) in tb_switch_set_authorized() argument
1731 if (!mutex_trylock(&sw->tb->lock)) in tb_switch_set_authorized()
1734 if (!!sw->authorized == !!val) in tb_switch_set_authorized()
1740 if (tb_route(sw)) { in tb_switch_set_authorized()
1741 ret = disapprove_switch(&sw->dev, NULL); in tb_switch_set_authorized()
1748 if (sw->key) in tb_switch_set_authorized()
1749 ret = tb_domain_approve_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1751 ret = tb_domain_approve_switch(sw->tb, sw); in tb_switch_set_authorized()
1756 if (sw->key) in tb_switch_set_authorized()
1757 ret = tb_domain_challenge_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1765 sw->authorized = val; in tb_switch_set_authorized()
1770 sprintf(envp_string, "AUTHORIZED=%u", sw->authorized); in tb_switch_set_authorized()
1771 kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); in tb_switch_set_authorized()
1775 mutex_unlock(&sw->tb->lock); in tb_switch_set_authorized()
1783 struct tb_switch *sw = tb_to_switch(dev); in authorized_store() local
1793 pm_runtime_get_sync(&sw->dev); in authorized_store()
1794 ret = tb_switch_set_authorized(sw, val); in authorized_store()
1795 pm_runtime_mark_last_busy(&sw->dev); in authorized_store()
1796 pm_runtime_put_autosuspend(&sw->dev); in authorized_store()
1805 struct tb_switch *sw = tb_to_switch(dev); in boot_show() local
1807 return sysfs_emit(buf, "%u\n", sw->boot); in boot_show()
1814 struct tb_switch *sw = tb_to_switch(dev); in device_show() local
1816 return sysfs_emit(buf, "%#x\n", sw->device); in device_show()
1823 struct tb_switch *sw = tb_to_switch(dev); in device_name_show() local
1825 return sysfs_emit(buf, "%s\n", sw->device_name ?: ""); in device_name_show()
1832 struct tb_switch *sw = tb_to_switch(dev); in generation_show() local
1834 return sysfs_emit(buf, "%u\n", sw->generation); in generation_show()
1841 struct tb_switch *sw = tb_to_switch(dev); in key_show() local
1844 if (!mutex_trylock(&sw->tb->lock)) in key_show()
1847 if (sw->key) in key_show()
1848 ret = sysfs_emit(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key); in key_show()
1852 mutex_unlock(&sw->tb->lock); in key_show()
1859 struct tb_switch *sw = tb_to_switch(dev); in key_store() local
1869 if (!mutex_trylock(&sw->tb->lock)) in key_store()
1872 if (sw->authorized) { in key_store()
1875 kfree(sw->key); in key_store()
1877 sw->key = NULL; in key_store()
1879 sw->key = kmemdup(key, sizeof(key), GFP_KERNEL); in key_store()
1880 if (!sw->key) in key_store()
1885 mutex_unlock(&sw->tb->lock); in key_store()
1893 struct tb_switch *sw = tb_to_switch(dev); in speed_show() local
1895 return sysfs_emit(buf, "%u.0 Gb/s\n", sw->link_speed); in speed_show()
1908 struct tb_switch *sw = tb_to_switch(dev); in lanes_show() local
1910 return sysfs_emit(buf, "%u\n", sw->link_width); in lanes_show()
1923 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_show() local
1926 nvm_get_auth_status(sw, &status); in nvm_authenticate_show()
1933 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_sysfs() local
1936 pm_runtime_get_sync(&sw->dev); in nvm_authenticate_sysfs()
1938 if (!mutex_trylock(&sw->tb->lock)) { in nvm_authenticate_sysfs()
1943 if (sw->no_nvm_upgrade) { in nvm_authenticate_sysfs()
1949 if (!sw->nvm) { in nvm_authenticate_sysfs()
1959 nvm_clear_auth_status(sw); in nvm_authenticate_sysfs()
1966 ret = nvm_authenticate(sw, true); in nvm_authenticate_sysfs()
1968 if (!sw->nvm->flushed) { in nvm_authenticate_sysfs()
1969 if (!sw->nvm->buf) { in nvm_authenticate_sysfs()
1974 ret = nvm_validate_and_write(sw); in nvm_authenticate_sysfs()
1980 ret = tb_lc_force_power(sw); in nvm_authenticate_sysfs()
1982 ret = nvm_authenticate(sw, false); in nvm_authenticate_sysfs()
1988 mutex_unlock(&sw->tb->lock); in nvm_authenticate_sysfs()
1990 pm_runtime_mark_last_busy(&sw->dev); in nvm_authenticate_sysfs()
1991 pm_runtime_put_autosuspend(&sw->dev); in nvm_authenticate_sysfs()
2025 struct tb_switch *sw = tb_to_switch(dev); in nvm_version_show() local
2028 if (!mutex_trylock(&sw->tb->lock)) in nvm_version_show()
2031 if (sw->safe_mode) in nvm_version_show()
2033 else if (!sw->nvm) in nvm_version_show()
2036 ret = sysfs_emit(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor); in nvm_version_show()
2038 mutex_unlock(&sw->tb->lock); in nvm_version_show()
2047 struct tb_switch *sw = tb_to_switch(dev); in vendor_show() local
2049 return sysfs_emit(buf, "%#x\n", sw->vendor); in vendor_show()
2056 struct tb_switch *sw = tb_to_switch(dev); in vendor_name_show() local
2058 return sysfs_emit(buf, "%s\n", sw->vendor_name ?: ""); in vendor_name_show()
2065 struct tb_switch *sw = tb_to_switch(dev); in unique_id_show() local
2067 return sysfs_emit(buf, "%pUb\n", sw->uuid); in unique_id_show()
2095 struct tb_switch *sw = tb_to_switch(dev); in switch_attr_is_visible() local
2098 if (sw->tb->security_level == TB_SECURITY_NOPCIE || in switch_attr_is_visible()
2099 sw->tb->security_level == TB_SECURITY_DPONLY) in switch_attr_is_visible()
2102 if (!sw->device) in switch_attr_is_visible()
2105 if (!sw->device_name) in switch_attr_is_visible()
2108 if (!sw->vendor) in switch_attr_is_visible()
2111 if (!sw->vendor_name) in switch_attr_is_visible()
2114 if (tb_route(sw) && in switch_attr_is_visible()
2115 sw->tb->security_level == TB_SECURITY_SECURE && in switch_attr_is_visible()
2116 sw->security_level == TB_SECURITY_SECURE) in switch_attr_is_visible()
2123 if (tb_route(sw)) in switch_attr_is_visible()
2127 if (nvm_upgradeable(sw)) in switch_attr_is_visible()
2131 if (nvm_readable(sw)) in switch_attr_is_visible()
2135 if (tb_route(sw)) in switch_attr_is_visible()
2139 if (sw->quirks & QUIRK_FORCE_POWER_LINK_CONTROLLER) in switch_attr_is_visible()
2144 return sw->safe_mode ? 0 : attr->mode; in switch_attr_is_visible()
2159 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_release() local
2162 dma_port_free(sw->dma_port); in tb_switch_release()
2164 tb_switch_for_each_port(sw, port) { in tb_switch_release()
2169 kfree(sw->uuid); in tb_switch_release()
2170 kfree(sw->device_name); in tb_switch_release()
2171 kfree(sw->vendor_name); in tb_switch_release()
2172 kfree(sw->ports); in tb_switch_release()
2173 kfree(sw->drom); in tb_switch_release()
2174 kfree(sw->key); in tb_switch_release()
2175 kfree(sw); in tb_switch_release()
2180 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_uevent() local
2183 if (sw->config.thunderbolt_version == USB4_VERSION_1_0) { in tb_switch_uevent()
2188 if (!tb_route(sw)) { in tb_switch_uevent()
2195 tb_switch_for_each_port(sw, port) { in tb_switch_uevent()
2217 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_suspend() local
2218 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_suspend()
2221 return cm_ops->runtime_suspend_switch(sw); in tb_switch_runtime_suspend()
2228 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_resume() local
2229 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_resume()
2232 return cm_ops->runtime_resume_switch(sw); in tb_switch_runtime_resume()
2248 static int tb_switch_get_generation(struct tb_switch *sw) in tb_switch_get_generation() argument
2250 switch (sw->config.device_id) { in tb_switch_get_generation()
2279 if (tb_switch_is_usb4(sw)) in tb_switch_get_generation()
2286 tb_sw_warn(sw, "unsupported switch device id %#x\n", in tb_switch_get_generation()
2287 sw->config.device_id); in tb_switch_get_generation()
2292 static bool tb_switch_exceeds_max_depth(const struct tb_switch *sw, int depth) in tb_switch_exceeds_max_depth() argument
2296 if (tb_switch_is_usb4(sw) || in tb_switch_exceeds_max_depth()
2297 (sw->tb->root_switch && tb_switch_is_usb4(sw->tb->root_switch))) in tb_switch_exceeds_max_depth()
2322 struct tb_switch *sw; in tb_switch_alloc() local
2341 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc()
2342 if (!sw) in tb_switch_alloc()
2345 sw->tb = tb; in tb_switch_alloc()
2346 ret = tb_cfg_read(tb->ctl, &sw->config, route, 0, TB_CFG_SWITCH, 0, 5); in tb_switch_alloc()
2350 sw->generation = tb_switch_get_generation(sw); in tb_switch_alloc()
2353 tb_dump_switch(tb, sw); in tb_switch_alloc()
2356 sw->config.upstream_port_number = upstream_port; in tb_switch_alloc()
2357 sw->config.depth = depth; in tb_switch_alloc()
2358 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc()
2359 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc()
2360 sw->config.enabled = 0; in tb_switch_alloc()
2363 if (tb_switch_exceeds_max_depth(sw, depth)) { in tb_switch_alloc()
2369 sw->ports = kcalloc(sw->config.max_port_number + 1, sizeof(*sw->ports), in tb_switch_alloc()
2371 if (!sw->ports) { in tb_switch_alloc()
2376 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_alloc()
2378 sw->ports[i].sw = sw; in tb_switch_alloc()
2379 sw->ports[i].port = i; in tb_switch_alloc()
2383 ida_init(&sw->ports[i].in_hopids); in tb_switch_alloc()
2384 ida_init(&sw->ports[i].out_hopids); in tb_switch_alloc()
2388 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_PLUG_EVENTS); in tb_switch_alloc()
2390 sw->cap_plug_events = ret; in tb_switch_alloc()
2392 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_TIME2); in tb_switch_alloc()
2394 sw->cap_vsec_tmu = ret; in tb_switch_alloc()
2396 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_LINK_CONTROLLER); in tb_switch_alloc()
2398 sw->cap_lc = ret; in tb_switch_alloc()
2400 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_CP_LP); in tb_switch_alloc()
2402 sw->cap_lp = ret; in tb_switch_alloc()
2406 sw->authorized = true; in tb_switch_alloc()
2408 device_initialize(&sw->dev); in tb_switch_alloc()
2409 sw->dev.parent = parent; in tb_switch_alloc()
2410 sw->dev.bus = &tb_bus_type; in tb_switch_alloc()
2411 sw->dev.type = &tb_switch_type; in tb_switch_alloc()
2412 sw->dev.groups = switch_groups; in tb_switch_alloc()
2413 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc()
2415 return sw; in tb_switch_alloc()
2418 kfree(sw->ports); in tb_switch_alloc()
2419 kfree(sw); in tb_switch_alloc()
2441 struct tb_switch *sw; in tb_switch_alloc_safe_mode() local
2443 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc_safe_mode()
2444 if (!sw) in tb_switch_alloc_safe_mode()
2447 sw->tb = tb; in tb_switch_alloc_safe_mode()
2448 sw->config.depth = tb_route_length(route); in tb_switch_alloc_safe_mode()
2449 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc_safe_mode()
2450 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc_safe_mode()
2451 sw->safe_mode = true; in tb_switch_alloc_safe_mode()
2453 device_initialize(&sw->dev); in tb_switch_alloc_safe_mode()
2454 sw->dev.parent = parent; in tb_switch_alloc_safe_mode()
2455 sw->dev.bus = &tb_bus_type; in tb_switch_alloc_safe_mode()
2456 sw->dev.type = &tb_switch_type; in tb_switch_alloc_safe_mode()
2457 sw->dev.groups = switch_groups; in tb_switch_alloc_safe_mode()
2458 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc_safe_mode()
2460 return sw; in tb_switch_alloc_safe_mode()
2465 * @sw: Switch to configure
2474 int tb_switch_configure(struct tb_switch *sw) in tb_switch_configure() argument
2476 struct tb *tb = sw->tb; in tb_switch_configure()
2480 route = tb_route(sw); in tb_switch_configure()
2483 sw->config.enabled ? "restoring" : "initializing", route, in tb_switch_configure()
2484 tb_route_length(route), sw->config.upstream_port_number); in tb_switch_configure()
2486 sw->config.enabled = 1; in tb_switch_configure()
2488 if (tb_switch_is_usb4(sw)) { in tb_switch_configure()
2494 sw->config.cmuv = USB4_VERSION_1_0; in tb_switch_configure()
2495 sw->config.plug_events_delay = 0xa; in tb_switch_configure()
2498 ret = tb_sw_write(sw, (u32 *)&sw->config + 1, TB_CFG_SWITCH, in tb_switch_configure()
2503 ret = usb4_switch_setup(sw); in tb_switch_configure()
2505 if (sw->config.vendor_id != PCI_VENDOR_ID_INTEL) in tb_switch_configure()
2506 tb_sw_warn(sw, "unknown switch vendor id %#x\n", in tb_switch_configure()
2507 sw->config.vendor_id); in tb_switch_configure()
2509 if (!sw->cap_plug_events) { in tb_switch_configure()
2510 tb_sw_warn(sw, "cannot find TB_VSE_CAP_PLUG_EVENTS aborting\n"); in tb_switch_configure()
2515 ret = tb_sw_write(sw, (u32 *)&sw->config + 1, TB_CFG_SWITCH, in tb_switch_configure()
2521 return tb_plug_events_active(sw, true); in tb_switch_configure()
2524 static int tb_switch_set_uuid(struct tb_switch *sw) in tb_switch_set_uuid() argument
2530 if (sw->uuid) in tb_switch_set_uuid()
2533 if (tb_switch_is_usb4(sw)) { in tb_switch_set_uuid()
2534 ret = usb4_switch_read_uid(sw, &sw->uid); in tb_switch_set_uuid()
2543 ret = tb_lc_read_uuid(sw, uuid); in tb_switch_set_uuid()
2558 uuid[0] = sw->uid & 0xffffffff; in tb_switch_set_uuid()
2559 uuid[1] = (sw->uid >> 32) & 0xffffffff; in tb_switch_set_uuid()
2564 sw->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL); in tb_switch_set_uuid()
2565 if (!sw->uuid) in tb_switch_set_uuid()
2570 static int tb_switch_add_dma_port(struct tb_switch *sw) in tb_switch_add_dma_port() argument
2575 switch (sw->generation) { in tb_switch_add_dma_port()
2578 if (tb_route(sw)) in tb_switch_add_dma_port()
2584 ret = tb_switch_set_uuid(sw); in tb_switch_add_dma_port()
2594 if (!sw->safe_mode) in tb_switch_add_dma_port()
2599 if (sw->no_nvm_upgrade) in tb_switch_add_dma_port()
2602 if (tb_switch_is_usb4(sw)) { in tb_switch_add_dma_port()
2603 ret = usb4_switch_nvm_authenticate_status(sw, &status); in tb_switch_add_dma_port()
2608 tb_sw_info(sw, "switch flash authentication failed\n"); in tb_switch_add_dma_port()
2609 nvm_set_auth_status(sw, status); in tb_switch_add_dma_port()
2616 if (!tb_route(sw) && !tb_switch_is_icm(sw)) in tb_switch_add_dma_port()
2619 sw->dma_port = dma_port_alloc(sw); in tb_switch_add_dma_port()
2620 if (!sw->dma_port) in tb_switch_add_dma_port()
2629 nvm_get_auth_status(sw, &status); in tb_switch_add_dma_port()
2631 if (!tb_route(sw)) in tb_switch_add_dma_port()
2632 nvm_authenticate_complete_dma_port(sw); in tb_switch_add_dma_port()
2641 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in tb_switch_add_dma_port()
2646 if (!tb_route(sw)) in tb_switch_add_dma_port()
2647 nvm_authenticate_complete_dma_port(sw); in tb_switch_add_dma_port()
2650 tb_sw_info(sw, "switch flash authentication failed\n"); in tb_switch_add_dma_port()
2651 nvm_set_auth_status(sw, status); in tb_switch_add_dma_port()
2654 tb_sw_info(sw, "power cycling the switch now\n"); in tb_switch_add_dma_port()
2655 dma_port_power_cycle(sw->dma_port); in tb_switch_add_dma_port()
2664 static void tb_switch_default_link_ports(struct tb_switch *sw) in tb_switch_default_link_ports() argument
2668 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_default_link_ports()
2669 struct tb_port *port = &sw->ports[i]; in tb_switch_default_link_ports()
2676 if (i == sw->config.max_port_number || in tb_switch_default_link_ports()
2677 !tb_port_is_null(&sw->ports[i + 1])) in tb_switch_default_link_ports()
2681 subordinate = &sw->ports[i + 1]; in tb_switch_default_link_ports()
2688 tb_sw_dbg(sw, "linked ports %d <-> %d\n", in tb_switch_default_link_ports()
2694 static bool tb_switch_lane_bonding_possible(struct tb_switch *sw) in tb_switch_lane_bonding_possible() argument
2696 const struct tb_port *up = tb_upstream_port(sw); in tb_switch_lane_bonding_possible()
2701 if (tb_switch_is_usb4(sw)) in tb_switch_lane_bonding_possible()
2702 return usb4_switch_lane_bonding_possible(sw); in tb_switch_lane_bonding_possible()
2703 return tb_lc_lane_bonding_possible(sw); in tb_switch_lane_bonding_possible()
2706 static int tb_switch_update_link_attributes(struct tb_switch *sw) in tb_switch_update_link_attributes() argument
2712 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_update_link_attributes()
2715 up = tb_upstream_port(sw); in tb_switch_update_link_attributes()
2720 if (sw->link_speed != ret) in tb_switch_update_link_attributes()
2722 sw->link_speed = ret; in tb_switch_update_link_attributes()
2727 if (sw->link_width != ret) in tb_switch_update_link_attributes()
2729 sw->link_width = ret; in tb_switch_update_link_attributes()
2732 if (device_is_registered(&sw->dev) && change) in tb_switch_update_link_attributes()
2733 kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); in tb_switch_update_link_attributes()
2740 * @sw: Switch to enable lane bonding
2746 int tb_switch_lane_bonding_enable(struct tb_switch *sw) in tb_switch_lane_bonding_enable() argument
2748 struct tb_switch *parent = tb_to_switch(sw->dev.parent); in tb_switch_lane_bonding_enable()
2750 u64 route = tb_route(sw); in tb_switch_lane_bonding_enable()
2756 if (!tb_switch_lane_bonding_possible(sw)) in tb_switch_lane_bonding_enable()
2759 up = tb_upstream_port(sw); in tb_switch_lane_bonding_enable()
2787 tb_switch_update_link_attributes(sw); in tb_switch_lane_bonding_enable()
2789 tb_sw_dbg(sw, "lane bonding enabled\n"); in tb_switch_lane_bonding_enable()
2795 * @sw: Switch whose lane bonding to disable
2797 * Disables lane bonding between @sw and parent. This can be called even
2800 void tb_switch_lane_bonding_disable(struct tb_switch *sw) in tb_switch_lane_bonding_disable() argument
2802 struct tb_switch *parent = tb_to_switch(sw->dev.parent); in tb_switch_lane_bonding_disable()
2805 if (!tb_route(sw)) in tb_switch_lane_bonding_disable()
2808 up = tb_upstream_port(sw); in tb_switch_lane_bonding_disable()
2812 down = tb_port_at(tb_route(sw), parent); in tb_switch_lane_bonding_disable()
2822 tb_sw_warn(sw, "timeout disabling lane bonding\n"); in tb_switch_lane_bonding_disable()
2826 tb_switch_update_link_attributes(sw); in tb_switch_lane_bonding_disable()
2828 tb_sw_dbg(sw, "lane bonding disabled\n"); in tb_switch_lane_bonding_disable()
2833 * @sw: Switch whose link is configured
2835 * Sets the link upstream from @sw configured (from both ends) so that
2843 int tb_switch_configure_link(struct tb_switch *sw) in tb_switch_configure_link() argument
2848 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_configure_link()
2851 up = tb_upstream_port(sw); in tb_switch_configure_link()
2852 if (tb_switch_is_usb4(up->sw)) in tb_switch_configure_link()
2860 if (tb_switch_is_usb4(down->sw)) in tb_switch_configure_link()
2867 * @sw: Switch whose link is unconfigured
2869 * Sets the link unconfigured so the @sw will be disconnected if the
2872 void tb_switch_unconfigure_link(struct tb_switch *sw) in tb_switch_unconfigure_link() argument
2876 if (sw->is_unplugged) in tb_switch_unconfigure_link()
2878 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_unconfigure_link()
2881 up = tb_upstream_port(sw); in tb_switch_unconfigure_link()
2882 if (tb_switch_is_usb4(up->sw)) in tb_switch_unconfigure_link()
2888 if (tb_switch_is_usb4(down->sw)) in tb_switch_unconfigure_link()
2894 static void tb_switch_credits_init(struct tb_switch *sw) in tb_switch_credits_init() argument
2896 if (tb_switch_is_icm(sw)) in tb_switch_credits_init()
2898 if (!tb_switch_is_usb4(sw)) in tb_switch_credits_init()
2900 if (usb4_switch_credits_init(sw)) in tb_switch_credits_init()
2901 tb_sw_info(sw, "failed to determine preferred buffer allocation, using defaults\n"); in tb_switch_credits_init()
2904 static int tb_switch_port_hotplug_enable(struct tb_switch *sw) in tb_switch_port_hotplug_enable() argument
2908 if (tb_switch_is_icm(sw)) in tb_switch_port_hotplug_enable()
2911 tb_switch_for_each_port(sw, port) { in tb_switch_port_hotplug_enable()
2926 * @sw: Switch to add
2936 int tb_switch_add(struct tb_switch *sw) in tb_switch_add() argument
2947 ret = tb_switch_add_dma_port(sw); in tb_switch_add()
2949 dev_err(&sw->dev, "failed to add DMA port\n"); in tb_switch_add()
2953 if (!sw->safe_mode) { in tb_switch_add()
2954 tb_switch_credits_init(sw); in tb_switch_add()
2957 ret = tb_drom_read(sw); in tb_switch_add()
2959 dev_warn(&sw->dev, "reading DROM failed: %d\n", ret); in tb_switch_add()
2960 tb_sw_dbg(sw, "uid: %#llx\n", sw->uid); in tb_switch_add()
2962 tb_check_quirks(sw); in tb_switch_add()
2964 ret = tb_switch_set_uuid(sw); in tb_switch_add()
2966 dev_err(&sw->dev, "failed to set UUID\n"); in tb_switch_add()
2970 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_add()
2971 if (sw->ports[i].disabled) { in tb_switch_add()
2972 tb_port_dbg(&sw->ports[i], "disabled by eeprom\n"); in tb_switch_add()
2975 ret = tb_init_port(&sw->ports[i]); in tb_switch_add()
2977 dev_err(&sw->dev, "failed to initialize port %d\n", i); in tb_switch_add()
2982 tb_switch_default_link_ports(sw); in tb_switch_add()
2984 ret = tb_switch_update_link_attributes(sw); in tb_switch_add()
2988 ret = tb_switch_tmu_init(sw); in tb_switch_add()
2993 ret = tb_switch_port_hotplug_enable(sw); in tb_switch_add()
2997 ret = device_add(&sw->dev); in tb_switch_add()
2999 dev_err(&sw->dev, "failed to add device: %d\n", ret); in tb_switch_add()
3003 if (tb_route(sw)) { in tb_switch_add()
3004 dev_info(&sw->dev, "new device found, vendor=%#x device=%#x\n", in tb_switch_add()
3005 sw->vendor, sw->device); in tb_switch_add()
3006 if (sw->vendor_name && sw->device_name) in tb_switch_add()
3007 dev_info(&sw->dev, "%s %s\n", sw->vendor_name, in tb_switch_add()
3008 sw->device_name); in tb_switch_add()
3011 ret = usb4_switch_add_ports(sw); in tb_switch_add()
3013 dev_err(&sw->dev, "failed to add USB4 ports\n"); in tb_switch_add()
3017 ret = tb_switch_nvm_add(sw); in tb_switch_add()
3019 dev_err(&sw->dev, "failed to add NVM devices\n"); in tb_switch_add()
3028 device_init_wakeup(&sw->dev, true); in tb_switch_add()
3030 pm_runtime_set_active(&sw->dev); in tb_switch_add()
3031 if (sw->rpm) { in tb_switch_add()
3032 pm_runtime_set_autosuspend_delay(&sw->dev, TB_AUTOSUSPEND_DELAY); in tb_switch_add()
3033 pm_runtime_use_autosuspend(&sw->dev); in tb_switch_add()
3034 pm_runtime_mark_last_busy(&sw->dev); in tb_switch_add()
3035 pm_runtime_enable(&sw->dev); in tb_switch_add()
3036 pm_request_autosuspend(&sw->dev); in tb_switch_add()
3039 tb_switch_debugfs_init(sw); in tb_switch_add()
3043 usb4_switch_remove_ports(sw); in tb_switch_add()
3045 device_del(&sw->dev); in tb_switch_add()
3052 * @sw: Switch to remove
3058 void tb_switch_remove(struct tb_switch *sw) in tb_switch_remove() argument
3062 tb_switch_debugfs_remove(sw); in tb_switch_remove()
3064 if (sw->rpm) { in tb_switch_remove()
3065 pm_runtime_get_sync(&sw->dev); in tb_switch_remove()
3066 pm_runtime_disable(&sw->dev); in tb_switch_remove()
3070 tb_switch_for_each_port(sw, port) { in tb_switch_remove()
3072 tb_switch_remove(port->remote->sw); in tb_switch_remove()
3083 if (!sw->is_unplugged) in tb_switch_remove()
3084 tb_plug_events_active(sw, false); in tb_switch_remove()
3086 tb_switch_nvm_remove(sw); in tb_switch_remove()
3087 usb4_switch_remove_ports(sw); in tb_switch_remove()
3089 if (tb_route(sw)) in tb_switch_remove()
3090 dev_info(&sw->dev, "device disconnected\n"); in tb_switch_remove()
3091 device_unregister(&sw->dev); in tb_switch_remove()
3096 * @sw: Router to mark unplugged
3098 void tb_sw_set_unplugged(struct tb_switch *sw) in tb_sw_set_unplugged() argument
3102 if (sw == sw->tb->root_switch) { in tb_sw_set_unplugged()
3103 tb_sw_WARN(sw, "cannot unplug root switch\n"); in tb_sw_set_unplugged()
3106 if (sw->is_unplugged) { in tb_sw_set_unplugged()
3107 tb_sw_WARN(sw, "is_unplugged already set\n"); in tb_sw_set_unplugged()
3110 sw->is_unplugged = true; in tb_sw_set_unplugged()
3111 tb_switch_for_each_port(sw, port) { in tb_sw_set_unplugged()
3113 tb_sw_set_unplugged(port->remote->sw); in tb_sw_set_unplugged()
3119 static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags) in tb_switch_set_wake() argument
3122 tb_sw_dbg(sw, "enabling wakeup: %#x\n", flags); in tb_switch_set_wake()
3124 tb_sw_dbg(sw, "disabling wakeup\n"); in tb_switch_set_wake()
3126 if (tb_switch_is_usb4(sw)) in tb_switch_set_wake()
3127 return usb4_switch_set_wake(sw, flags); in tb_switch_set_wake()
3128 return tb_lc_set_wake(sw, flags); in tb_switch_set_wake()
3131 int tb_switch_resume(struct tb_switch *sw) in tb_switch_resume() argument
3136 tb_sw_dbg(sw, "resuming switch\n"); in tb_switch_resume()
3142 if (tb_route(sw)) { in tb_switch_resume()
3150 err = tb_cfg_get_upstream_port(sw->tb->ctl, tb_route(sw)); in tb_switch_resume()
3152 tb_sw_info(sw, "switch not present anymore\n"); in tb_switch_resume()
3157 if (!sw->uid) in tb_switch_resume()
3160 if (tb_switch_is_usb4(sw)) in tb_switch_resume()
3161 err = usb4_switch_read_uid(sw, &uid); in tb_switch_resume()
3163 err = tb_drom_read_uid_only(sw, &uid); in tb_switch_resume()
3165 tb_sw_warn(sw, "uid read failed\n"); in tb_switch_resume()
3168 if (sw->uid != uid) { in tb_switch_resume()
3169 tb_sw_info(sw, in tb_switch_resume()
3171 sw->uid, uid); in tb_switch_resume()
3176 err = tb_switch_configure(sw); in tb_switch_resume()
3181 tb_switch_set_wake(sw, 0); in tb_switch_resume()
3183 err = tb_switch_tmu_init(sw); in tb_switch_resume()
3188 tb_switch_for_each_port(sw, port) { in tb_switch_resume()
3199 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
3209 if (port->remote && tb_switch_resume(port->remote->sw)) { in tb_switch_resume()
3212 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
3221 * @sw: Switch to suspend
3225 * value of @runtime and then sets sleep bit for the router. If @sw is
3229 void tb_switch_suspend(struct tb_switch *sw, bool runtime) in tb_switch_suspend() argument
3235 tb_sw_dbg(sw, "suspending switch\n"); in tb_switch_suspend()
3242 if (tb_switch_is_clx_enabled(sw, TB_CL1)) { in tb_switch_suspend()
3243 if (tb_switch_disable_clx(sw, TB_CL1)) in tb_switch_suspend()
3244 tb_sw_warn(sw, "failed to disable %s on upstream port\n", in tb_switch_suspend()
3248 err = tb_plug_events_active(sw, false); in tb_switch_suspend()
3252 tb_switch_for_each_port(sw, port) { in tb_switch_suspend()
3254 tb_switch_suspend(port->remote->sw, runtime); in tb_switch_suspend()
3262 } else if (device_may_wakeup(&sw->dev)) { in tb_switch_suspend()
3266 tb_switch_set_wake(sw, flags); in tb_switch_suspend()
3268 if (tb_switch_is_usb4(sw)) in tb_switch_suspend()
3269 usb4_switch_set_sleep(sw); in tb_switch_suspend()
3271 tb_lc_set_sleep(sw); in tb_switch_suspend()
3276 * @sw: Switch whose DP resource is queried
3282 bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_query_dp_resource() argument
3284 if (tb_switch_is_usb4(sw)) in tb_switch_query_dp_resource()
3285 return usb4_switch_query_dp_resource(sw, in); in tb_switch_query_dp_resource()
3286 return tb_lc_dp_sink_query(sw, in); in tb_switch_query_dp_resource()
3291 * @sw: Switch whose DP resource is allocated
3298 int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_alloc_dp_resource() argument
3302 if (tb_switch_is_usb4(sw)) in tb_switch_alloc_dp_resource()
3303 ret = usb4_switch_alloc_dp_resource(sw, in); in tb_switch_alloc_dp_resource()
3305 ret = tb_lc_dp_sink_alloc(sw, in); in tb_switch_alloc_dp_resource()
3308 tb_sw_warn(sw, "failed to allocate DP resource for port %d\n", in tb_switch_alloc_dp_resource()
3311 tb_sw_dbg(sw, "allocated DP resource for port %d\n", in->port); in tb_switch_alloc_dp_resource()
3318 * @sw: Switch whose DP resource is de-allocated
3324 void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_dealloc_dp_resource() argument
3328 if (tb_switch_is_usb4(sw)) in tb_switch_dealloc_dp_resource()
3329 ret = usb4_switch_dealloc_dp_resource(sw, in); in tb_switch_dealloc_dp_resource()
3331 ret = tb_lc_dp_sink_dealloc(sw, in); in tb_switch_dealloc_dp_resource()
3334 tb_sw_warn(sw, "failed to de-allocate DP resource for port %d\n", in tb_switch_dealloc_dp_resource()
3337 tb_sw_dbg(sw, "released DP resource for port %d\n", in->port); in tb_switch_dealloc_dp_resource()
3350 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_match() local
3353 if (!sw) in tb_switch_match()
3355 if (sw->tb != lookup->tb) in tb_switch_match()
3359 return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid)); in tb_switch_match()
3362 return sw->config.route_lo == lower_32_bits(lookup->route) && in tb_switch_match()
3363 sw->config.route_hi == upper_32_bits(lookup->route); in tb_switch_match()
3368 return !sw->depth; in tb_switch_match()
3370 return sw->link == lookup->link && sw->depth == lookup->depth; in tb_switch_match()
3451 * tb_switch_find_port() - return the first port of @type on @sw or NULL
3452 * @sw: Switch to find the port from
3455 struct tb_port *tb_switch_find_port(struct tb_switch *sw, in tb_switch_find_port() argument
3460 tb_switch_for_each_port(sw, port) { in tb_switch_find_port()
3468 static int tb_switch_pm_secondary_resolve(struct tb_switch *sw) in tb_switch_pm_secondary_resolve() argument
3470 struct tb_switch *parent = tb_switch_parent(sw); in tb_switch_pm_secondary_resolve()
3474 if (!tb_route(sw)) in tb_switch_pm_secondary_resolve()
3477 up = tb_upstream_port(sw); in tb_switch_pm_secondary_resolve()
3478 down = tb_port_at(tb_route(sw), parent); in tb_switch_pm_secondary_resolve()
3486 static int __tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx) in __tb_switch_enable_clx() argument
3488 struct tb_switch *parent = tb_switch_parent(sw); in __tb_switch_enable_clx()
3493 if (!tb_switch_is_clx_supported(sw)) in __tb_switch_enable_clx()
3500 if (!tb_route(sw)) in __tb_switch_enable_clx()
3507 ret = tb_switch_pm_secondary_resolve(sw); in __tb_switch_enable_clx()
3511 up = tb_upstream_port(sw); in __tb_switch_enable_clx()
3512 down = tb_port_at(tb_route(sw), parent); in __tb_switch_enable_clx()
3535 ret = tb_switch_mask_clx_objections(sw); in __tb_switch_enable_clx()
3542 sw->clx = clx; in __tb_switch_enable_clx()
3550 * @sw: Router to enable CLx for
3562 int tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx) in tb_switch_enable_clx() argument
3564 struct tb_switch *root_sw = sw->tb->root_switch; in tb_switch_enable_clx()
3579 return __tb_switch_enable_clx(sw, clx); in tb_switch_enable_clx()
3586 static int __tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx) in __tb_switch_disable_clx() argument
3588 struct tb_switch *parent = tb_switch_parent(sw); in __tb_switch_disable_clx()
3592 if (!tb_switch_is_clx_supported(sw)) in __tb_switch_disable_clx()
3599 if (!tb_route(sw)) in __tb_switch_disable_clx()
3606 up = tb_upstream_port(sw); in __tb_switch_disable_clx()
3607 down = tb_port_at(tb_route(sw), parent); in __tb_switch_disable_clx()
3616 sw->clx = TB_CLX_DISABLE; in __tb_switch_disable_clx()
3624 * @sw: Router to disable CLx for
3629 int tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx) in tb_switch_disable_clx() argument
3637 return __tb_switch_disable_clx(sw, clx); in tb_switch_disable_clx()
3646 * @sw: Router to mask objections for
3652 int tb_switch_mask_clx_objections(struct tb_switch *sw) in tb_switch_mask_clx_objections() argument
3654 int up_port = sw->config.upstream_port_number; in tb_switch_mask_clx_objections()
3659 if (!tb_switch_is_titan_ridge(sw)) in tb_switch_mask_clx_objections()
3662 if (!tb_route(sw)) in tb_switch_mask_clx_objections()
3682 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_mask_clx_objections()
3683 sw->cap_lp + offset, ARRAY_SIZE(val)); in tb_switch_mask_clx_objections()
3692 return tb_sw_write(sw, &val, TB_CFG_SWITCH, in tb_switch_mask_clx_objections()
3693 sw->cap_lp + offset, ARRAY_SIZE(val)); in tb_switch_mask_clx_objections()
3700 static int tb_switch_pcie_bridge_write(struct tb_switch *sw, unsigned int bridge, in tb_switch_pcie_bridge_write() argument
3706 if (sw->generation != 3) in tb_switch_pcie_bridge_write()
3709 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_WR_DATA; in tb_switch_pcie_bridge_write()
3710 ret = tb_sw_write(sw, &value, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3721 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_CMD; in tb_switch_pcie_bridge_write()
3723 ret = tb_sw_write(sw, &command, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3727 ret = tb_switch_wait_for_bit(sw, offset, in tb_switch_pcie_bridge_write()
3732 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3744 * @sw: Router to enable PCIe L1
3751 int tb_switch_pcie_l1_enable(struct tb_switch *sw) in tb_switch_pcie_l1_enable() argument
3753 struct tb_switch *parent = tb_switch_parent(sw); in tb_switch_pcie_l1_enable()
3756 if (!tb_route(sw)) in tb_switch_pcie_l1_enable()
3759 if (!tb_switch_is_titan_ridge(sw)) in tb_switch_pcie_l1_enable()
3767 ret = tb_switch_pcie_bridge_write(sw, 5, 0x143, 0x0c7806b1); in tb_switch_pcie_l1_enable()
3772 return tb_switch_pcie_bridge_write(sw, 0, 0x143, 0x0c5806b1); in tb_switch_pcie_l1_enable()
3777 * @sw: Router whose xHCI to connect
3785 int tb_switch_xhci_connect(struct tb_switch *sw) in tb_switch_xhci_connect() argument
3790 if (sw->generation != 3) in tb_switch_xhci_connect()
3793 port1 = &sw->ports[1]; in tb_switch_xhci_connect()
3794 port3 = &sw->ports[3]; in tb_switch_xhci_connect()
3796 if (tb_switch_is_alpine_ridge(sw)) { in tb_switch_xhci_connect()
3812 } else if (tb_switch_is_titan_ridge(sw)) { in tb_switch_xhci_connect()
3824 * @sw: Router whose xHCI to disconnect
3829 void tb_switch_xhci_disconnect(struct tb_switch *sw) in tb_switch_xhci_disconnect() argument
3831 if (sw->generation == 3) { in tb_switch_xhci_disconnect()
3832 struct tb_port *port1 = &sw->ports[1]; in tb_switch_xhci_disconnect()
3833 struct tb_port *port3 = &sw->ports[3]; in tb_switch_xhci_disconnect()