• Home
  • Raw
  • Download

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()
377 if (!sw->no_nvm_upgrade) { in tb_switch_nvm_add()
383 sw->nvm = nvm; in tb_switch_nvm_add()
387 tb_sw_dbg(sw, "NVM upgrade disabled\n"); in tb_switch_nvm_add()
388 sw->no_nvm_upgrade = true; in tb_switch_nvm_add()
395 static void tb_switch_nvm_remove(struct tb_switch *sw) in tb_switch_nvm_remove() argument
399 nvm = sw->nvm; in tb_switch_nvm_remove()
400 sw->nvm = NULL; in tb_switch_nvm_remove()
407 nvm_clear_auth_status(sw); in tb_switch_nvm_remove()
570 if (credits == 0 || port->sw->is_unplugged) in tb_port_add_nfc_credits()
577 if (tb_switch_is_usb4(port->sw) && !tb_port_is_null(port)) in tb_port_add_nfc_credits()
619 if (tb_switch_is_icm(port->sw)) in tb_port_unlock()
623 if (tb_switch_is_usb4(port->sw)) in tb_port_unlock()
680 if (tb_switch_is_usb4(port->sw)) in tb_port_reset()
707 tb_dbg(port->sw->tb, " Port %d: not implemented\n", in tb_init_port()
752 tb_dump_port(port->sw->tb, port); in tb_init_port()
832 const struct tb_switch *sw) in tb_switch_is_reachable() argument
835 return (tb_route(parent) & mask) == (tb_route(sw) & mask); in tb_switch_is_reachable()
861 if (prev->sw == end->sw) { in tb_next_port_on_path()
867 if (tb_switch_is_reachable(prev->sw, end->sw)) { in tb_next_port_on_path()
868 next = tb_port_at(tb_route(end->sw), prev->sw); in tb_next_port_on_path()
877 next = tb_upstream_port(prev->sw); in tb_next_port_on_path()
1284 if (tb_switch_is_usb4(port->sw)) in tb_port_start_lane_initialization()
1459 if (tb_switch_is_usb4(port->sw)) in tb_dp_port_set_hops()
1525 static const char *tb_switch_generation_name(const struct tb_switch *sw) in tb_switch_generation_name() argument
1527 switch (sw->generation) { in tb_switch_generation_name()
1541 static void tb_dump_switch(const struct tb *tb, const struct tb_switch *sw) in tb_dump_switch() argument
1543 const struct tb_regs_switch_header *regs = &sw->config; in tb_dump_switch()
1546 tb_switch_generation_name(sw), regs->vendor_id, regs->device_id, in tb_dump_switch()
1559 static int tb_switch_reset_host(struct tb_switch *sw) in tb_switch_reset_host() argument
1561 if (sw->generation > 1) { in tb_switch_reset_host()
1564 tb_switch_for_each_port(sw, port) { in tb_switch_reset_host()
1604 res.err = tb_sw_write(sw, ((u32 *) &sw->config) + 2, in tb_switch_reset_host()
1608 res = tb_cfg_reset(sw->tb->ctl, tb_route(sw)); in tb_switch_reset_host()
1618 static int tb_switch_reset_device(struct tb_switch *sw) in tb_switch_reset_device() argument
1620 return tb_port_reset(tb_switch_downstream_port(sw)); in tb_switch_reset_device()
1623 static bool tb_switch_enumerated(struct tb_switch *sw) in tb_switch_enumerated() argument
1630 * during system sleep where sw->config.enabled is already set in tb_switch_enumerated()
1633 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_3, 1); in tb_switch_enumerated()
1642 * @sw: Router to reset
1644 * Issues reset to the router @sw. Can be used for any router. For host
1654 int tb_switch_reset(struct tb_switch *sw) in tb_switch_reset() argument
1663 if (!tb_switch_enumerated(sw)) in tb_switch_reset()
1666 tb_sw_dbg(sw, "resetting\n"); in tb_switch_reset()
1668 if (tb_route(sw)) in tb_switch_reset()
1669 ret = tb_switch_reset_device(sw); in tb_switch_reset()
1671 ret = tb_switch_reset_host(sw); in tb_switch_reset()
1674 tb_sw_warn(sw, "failed to reset\n"); in tb_switch_reset()
1681 * @sw: Router to read the offset value from
1691 int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit, in tb_switch_wait_for_bit() argument
1700 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_wait_for_bit()
1720 static int tb_plug_events_active(struct tb_switch *sw, bool active) in tb_plug_events_active() argument
1725 if (tb_switch_is_icm(sw) || tb_switch_is_usb4(sw)) in tb_plug_events_active()
1728 sw->config.plug_events_delay = 0xff; in tb_plug_events_active()
1729 res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1); in tb_plug_events_active()
1733 res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1739 switch (sw->config.device_id) { in tb_plug_events_active()
1750 if (!tb_switch_is_alpine_ridge(sw)) in tb_plug_events_active()
1756 return tb_sw_write(sw, &data, TB_CFG_SWITCH, in tb_plug_events_active()
1757 sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1764 struct tb_switch *sw = tb_to_switch(dev); in authorized_show() local
1766 return sysfs_emit(buf, "%u\n", sw->authorized); in authorized_show()
1772 struct tb_switch *sw; in disapprove_switch() local
1774 sw = tb_to_switch(dev); in disapprove_switch()
1775 if (sw && sw->authorized) { in disapprove_switch()
1779 ret = device_for_each_child_reverse(&sw->dev, NULL, disapprove_switch); in disapprove_switch()
1783 ret = tb_domain_disapprove_switch(sw->tb, sw); in disapprove_switch()
1787 sw->authorized = 0; in disapprove_switch()
1788 kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); in disapprove_switch()
1794 static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val) in tb_switch_set_authorized() argument
1800 if (!mutex_trylock(&sw->tb->lock)) in tb_switch_set_authorized()
1803 if (!!sw->authorized == !!val) in tb_switch_set_authorized()
1809 if (tb_route(sw)) { in tb_switch_set_authorized()
1810 ret = disapprove_switch(&sw->dev, NULL); in tb_switch_set_authorized()
1817 if (sw->key) in tb_switch_set_authorized()
1818 ret = tb_domain_approve_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1820 ret = tb_domain_approve_switch(sw->tb, sw); in tb_switch_set_authorized()
1825 if (sw->key) in tb_switch_set_authorized()
1826 ret = tb_domain_challenge_switch_key(sw->tb, sw); in tb_switch_set_authorized()
1834 sw->authorized = val; in tb_switch_set_authorized()
1839 sprintf(envp_string, "AUTHORIZED=%u", sw->authorized); in tb_switch_set_authorized()
1840 kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); in tb_switch_set_authorized()
1844 mutex_unlock(&sw->tb->lock); in tb_switch_set_authorized()
1852 struct tb_switch *sw = tb_to_switch(dev); in authorized_store() local
1862 pm_runtime_get_sync(&sw->dev); in authorized_store()
1863 ret = tb_switch_set_authorized(sw, val); in authorized_store()
1864 pm_runtime_mark_last_busy(&sw->dev); in authorized_store()
1865 pm_runtime_put_autosuspend(&sw->dev); in authorized_store()
1874 struct tb_switch *sw = tb_to_switch(dev); in boot_show() local
1876 return sysfs_emit(buf, "%u\n", sw->boot); in boot_show()
1883 struct tb_switch *sw = tb_to_switch(dev); in device_show() local
1885 return sysfs_emit(buf, "%#x\n", sw->device); in device_show()
1892 struct tb_switch *sw = tb_to_switch(dev); in device_name_show() local
1894 return sysfs_emit(buf, "%s\n", sw->device_name ?: ""); in device_name_show()
1901 struct tb_switch *sw = tb_to_switch(dev); in generation_show() local
1903 return sysfs_emit(buf, "%u\n", sw->generation); in generation_show()
1910 struct tb_switch *sw = tb_to_switch(dev); in key_show() local
1913 if (!mutex_trylock(&sw->tb->lock)) in key_show()
1916 if (sw->key) in key_show()
1917 ret = sysfs_emit(buf, "%*phN\n", TB_SWITCH_KEY_SIZE, sw->key); in key_show()
1921 mutex_unlock(&sw->tb->lock); in key_show()
1928 struct tb_switch *sw = tb_to_switch(dev); in key_store() local
1938 if (!mutex_trylock(&sw->tb->lock)) in key_store()
1941 if (sw->authorized) { in key_store()
1944 kfree(sw->key); in key_store()
1946 sw->key = NULL; in key_store()
1948 sw->key = kmemdup(key, sizeof(key), GFP_KERNEL); in key_store()
1949 if (!sw->key) in key_store()
1954 mutex_unlock(&sw->tb->lock); in key_store()
1962 struct tb_switch *sw = tb_to_switch(dev); in speed_show() local
1964 return sysfs_emit(buf, "%u.0 Gb/s\n", sw->link_speed); in speed_show()
1977 struct tb_switch *sw = tb_to_switch(dev); in rx_lanes_show() local
1980 switch (sw->link_width) { in rx_lanes_show()
2003 struct tb_switch *sw = tb_to_switch(dev); in tx_lanes_show() local
2006 switch (sw->link_width) { in tx_lanes_show()
2029 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_show() local
2032 nvm_get_auth_status(sw, &status); in nvm_authenticate_show()
2039 struct tb_switch *sw = tb_to_switch(dev); in nvm_authenticate_sysfs() local
2042 pm_runtime_get_sync(&sw->dev); in nvm_authenticate_sysfs()
2044 if (!mutex_trylock(&sw->tb->lock)) { in nvm_authenticate_sysfs()
2049 if (sw->no_nvm_upgrade) { in nvm_authenticate_sysfs()
2055 if (!sw->nvm) { in nvm_authenticate_sysfs()
2065 nvm_clear_auth_status(sw); in nvm_authenticate_sysfs()
2072 ret = nvm_authenticate(sw, true); in nvm_authenticate_sysfs()
2074 if (!sw->nvm->flushed) { in nvm_authenticate_sysfs()
2075 if (!sw->nvm->buf) { in nvm_authenticate_sysfs()
2080 ret = nvm_validate_and_write(sw); in nvm_authenticate_sysfs()
2086 ret = tb_lc_force_power(sw); in nvm_authenticate_sysfs()
2088 ret = nvm_authenticate(sw, false); in nvm_authenticate_sysfs()
2094 mutex_unlock(&sw->tb->lock); in nvm_authenticate_sysfs()
2096 pm_runtime_mark_last_busy(&sw->dev); in nvm_authenticate_sysfs()
2097 pm_runtime_put_autosuspend(&sw->dev); in nvm_authenticate_sysfs()
2131 struct tb_switch *sw = tb_to_switch(dev); in nvm_version_show() local
2134 if (!mutex_trylock(&sw->tb->lock)) in nvm_version_show()
2137 if (sw->safe_mode) in nvm_version_show()
2139 else if (!sw->nvm) in nvm_version_show()
2142 ret = sysfs_emit(buf, "%x.%x\n", sw->nvm->major, sw->nvm->minor); in nvm_version_show()
2144 mutex_unlock(&sw->tb->lock); in nvm_version_show()
2153 struct tb_switch *sw = tb_to_switch(dev); in vendor_show() local
2155 return sysfs_emit(buf, "%#x\n", sw->vendor); in vendor_show()
2162 struct tb_switch *sw = tb_to_switch(dev); in vendor_name_show() local
2164 return sysfs_emit(buf, "%s\n", sw->vendor_name ?: ""); in vendor_name_show()
2171 struct tb_switch *sw = tb_to_switch(dev); in unique_id_show() local
2173 return sysfs_emit(buf, "%pUb\n", sw->uuid); in unique_id_show()
2201 struct tb_switch *sw = tb_to_switch(dev); in switch_attr_is_visible() local
2204 if (sw->tb->security_level == TB_SECURITY_NOPCIE || in switch_attr_is_visible()
2205 sw->tb->security_level == TB_SECURITY_DPONLY) in switch_attr_is_visible()
2208 if (!sw->device) in switch_attr_is_visible()
2211 if (!sw->device_name) in switch_attr_is_visible()
2214 if (!sw->vendor) in switch_attr_is_visible()
2217 if (!sw->vendor_name) in switch_attr_is_visible()
2220 if (tb_route(sw) && in switch_attr_is_visible()
2221 sw->tb->security_level == TB_SECURITY_SECURE && in switch_attr_is_visible()
2222 sw->security_level == TB_SECURITY_SECURE) in switch_attr_is_visible()
2229 if (tb_route(sw)) in switch_attr_is_visible()
2233 if (nvm_upgradeable(sw)) in switch_attr_is_visible()
2237 if (nvm_readable(sw)) in switch_attr_is_visible()
2241 if (tb_route(sw)) in switch_attr_is_visible()
2245 if (sw->quirks & QUIRK_FORCE_POWER_LINK_CONTROLLER) in switch_attr_is_visible()
2250 return sw->safe_mode ? 0 : attr->mode; in switch_attr_is_visible()
2265 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_release() local
2268 dma_port_free(sw->dma_port); in tb_switch_release()
2270 tb_switch_for_each_port(sw, port) { in tb_switch_release()
2275 kfree(sw->uuid); in tb_switch_release()
2276 kfree(sw->device_name); in tb_switch_release()
2277 kfree(sw->vendor_name); in tb_switch_release()
2278 kfree(sw->ports); in tb_switch_release()
2279 kfree(sw->drom); in tb_switch_release()
2280 kfree(sw->key); in tb_switch_release()
2281 kfree(sw); in tb_switch_release()
2286 const struct tb_switch *sw = tb_to_switch(dev); in tb_switch_uevent() local
2289 if (tb_switch_is_usb4(sw)) { in tb_switch_uevent()
2291 usb4_switch_version(sw))) in tb_switch_uevent()
2295 if (!tb_route(sw)) { in tb_switch_uevent()
2302 tb_switch_for_each_port(sw, port) { in tb_switch_uevent()
2324 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_suspend() local
2325 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_suspend()
2328 return cm_ops->runtime_suspend_switch(sw); in tb_switch_runtime_suspend()
2335 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_runtime_resume() local
2336 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_resume()
2339 return cm_ops->runtime_resume_switch(sw); in tb_switch_runtime_resume()
2355 static int tb_switch_get_generation(struct tb_switch *sw) in tb_switch_get_generation() argument
2357 if (tb_switch_is_usb4(sw)) in tb_switch_get_generation()
2360 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) { in tb_switch_get_generation()
2361 switch (sw->config.device_id) { in tb_switch_get_generation()
2395 tb_sw_warn(sw, "unsupported switch device id %#x\n", in tb_switch_get_generation()
2396 sw->config.device_id); in tb_switch_get_generation()
2400 static bool tb_switch_exceeds_max_depth(const struct tb_switch *sw, int depth) in tb_switch_exceeds_max_depth() argument
2404 if (tb_switch_is_usb4(sw) || in tb_switch_exceeds_max_depth()
2405 (sw->tb->root_switch && tb_switch_is_usb4(sw->tb->root_switch))) in tb_switch_exceeds_max_depth()
2430 struct tb_switch *sw; in tb_switch_alloc() local
2449 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc()
2450 if (!sw) in tb_switch_alloc()
2453 sw->tb = tb; in tb_switch_alloc()
2454 ret = tb_cfg_read(tb->ctl, &sw->config, route, 0, TB_CFG_SWITCH, 0, 5); in tb_switch_alloc()
2458 sw->generation = tb_switch_get_generation(sw); in tb_switch_alloc()
2461 tb_dump_switch(tb, sw); in tb_switch_alloc()
2464 sw->config.upstream_port_number = upstream_port; in tb_switch_alloc()
2465 sw->config.depth = depth; in tb_switch_alloc()
2466 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc()
2467 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc()
2468 sw->config.enabled = 0; in tb_switch_alloc()
2471 if (tb_switch_exceeds_max_depth(sw, depth)) { in tb_switch_alloc()
2477 sw->ports = kcalloc(sw->config.max_port_number + 1, sizeof(*sw->ports), in tb_switch_alloc()
2479 if (!sw->ports) { in tb_switch_alloc()
2484 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_alloc()
2486 sw->ports[i].sw = sw; in tb_switch_alloc()
2487 sw->ports[i].port = i; in tb_switch_alloc()
2491 ida_init(&sw->ports[i].in_hopids); in tb_switch_alloc()
2492 ida_init(&sw->ports[i].out_hopids); in tb_switch_alloc()
2496 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_PLUG_EVENTS); in tb_switch_alloc()
2498 sw->cap_plug_events = ret; in tb_switch_alloc()
2500 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_TIME2); in tb_switch_alloc()
2502 sw->cap_vsec_tmu = ret; in tb_switch_alloc()
2504 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_LINK_CONTROLLER); in tb_switch_alloc()
2506 sw->cap_lc = ret; in tb_switch_alloc()
2508 ret = tb_switch_find_vse_cap(sw, TB_VSE_CAP_CP_LP); in tb_switch_alloc()
2510 sw->cap_lp = ret; in tb_switch_alloc()
2514 sw->authorized = true; in tb_switch_alloc()
2516 device_initialize(&sw->dev); in tb_switch_alloc()
2517 sw->dev.parent = parent; in tb_switch_alloc()
2518 sw->dev.bus = &tb_bus_type; in tb_switch_alloc()
2519 sw->dev.type = &tb_switch_type; in tb_switch_alloc()
2520 sw->dev.groups = switch_groups; in tb_switch_alloc()
2521 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc()
2523 return sw; in tb_switch_alloc()
2526 kfree(sw->ports); in tb_switch_alloc()
2527 kfree(sw); in tb_switch_alloc()
2549 struct tb_switch *sw; in tb_switch_alloc_safe_mode() local
2551 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc_safe_mode()
2552 if (!sw) in tb_switch_alloc_safe_mode()
2555 sw->tb = tb; in tb_switch_alloc_safe_mode()
2556 sw->config.depth = tb_route_length(route); in tb_switch_alloc_safe_mode()
2557 sw->config.route_hi = upper_32_bits(route); in tb_switch_alloc_safe_mode()
2558 sw->config.route_lo = lower_32_bits(route); in tb_switch_alloc_safe_mode()
2559 sw->safe_mode = true; in tb_switch_alloc_safe_mode()
2561 device_initialize(&sw->dev); in tb_switch_alloc_safe_mode()
2562 sw->dev.parent = parent; in tb_switch_alloc_safe_mode()
2563 sw->dev.bus = &tb_bus_type; in tb_switch_alloc_safe_mode()
2564 sw->dev.type = &tb_switch_type; in tb_switch_alloc_safe_mode()
2565 sw->dev.groups = switch_groups; in tb_switch_alloc_safe_mode()
2566 dev_set_name(&sw->dev, "%u-%llx", tb->index, tb_route(sw)); in tb_switch_alloc_safe_mode()
2568 return sw; in tb_switch_alloc_safe_mode()
2573 * @sw: Switch to configure
2582 int tb_switch_configure(struct tb_switch *sw) in tb_switch_configure() argument
2584 struct tb *tb = sw->tb; in tb_switch_configure()
2588 route = tb_route(sw); in tb_switch_configure()
2591 sw->config.enabled ? "restoring" : "initializing", route, in tb_switch_configure()
2592 tb_route_length(route), sw->config.upstream_port_number); in tb_switch_configure()
2594 sw->config.enabled = 1; in tb_switch_configure()
2596 if (tb_switch_is_usb4(sw)) { in tb_switch_configure()
2603 if (usb4_switch_version(sw) < 2) in tb_switch_configure()
2604 sw->config.cmuv = ROUTER_CS_4_CMUV_V1; in tb_switch_configure()
2606 sw->config.cmuv = ROUTER_CS_4_CMUV_V2; in tb_switch_configure()
2607 sw->config.plug_events_delay = 0xa; in tb_switch_configure()
2610 ret = tb_sw_write(sw, (u32 *)&sw->config + 1, TB_CFG_SWITCH, in tb_switch_configure()
2615 ret = usb4_switch_setup(sw); in tb_switch_configure()
2617 if (sw->config.vendor_id != PCI_VENDOR_ID_INTEL) in tb_switch_configure()
2618 tb_sw_warn(sw, "unknown switch vendor id %#x\n", in tb_switch_configure()
2619 sw->config.vendor_id); in tb_switch_configure()
2621 if (!sw->cap_plug_events) { in tb_switch_configure()
2622 tb_sw_warn(sw, "cannot find TB_VSE_CAP_PLUG_EVENTS aborting\n"); in tb_switch_configure()
2627 ret = tb_sw_write(sw, (u32 *)&sw->config + 1, TB_CFG_SWITCH, in tb_switch_configure()
2633 return tb_plug_events_active(sw, true); in tb_switch_configure()
2638 * @sw: Router to configure
2645 int tb_switch_configuration_valid(struct tb_switch *sw) in tb_switch_configuration_valid() argument
2647 if (tb_switch_is_usb4(sw)) in tb_switch_configuration_valid()
2648 return usb4_switch_configuration_valid(sw); in tb_switch_configuration_valid()
2652 static int tb_switch_set_uuid(struct tb_switch *sw) in tb_switch_set_uuid() argument
2658 if (sw->uuid) in tb_switch_set_uuid()
2661 if (tb_switch_is_usb4(sw)) { in tb_switch_set_uuid()
2662 ret = usb4_switch_read_uid(sw, &sw->uid); in tb_switch_set_uuid()
2671 ret = tb_lc_read_uuid(sw, uuid); in tb_switch_set_uuid()
2686 uuid[0] = sw->uid & 0xffffffff; in tb_switch_set_uuid()
2687 uuid[1] = (sw->uid >> 32) & 0xffffffff; in tb_switch_set_uuid()
2692 sw->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL); in tb_switch_set_uuid()
2693 if (!sw->uuid) in tb_switch_set_uuid()
2698 static int tb_switch_add_dma_port(struct tb_switch *sw) in tb_switch_add_dma_port() argument
2703 switch (sw->generation) { in tb_switch_add_dma_port()
2706 if (tb_route(sw)) in tb_switch_add_dma_port()
2712 ret = tb_switch_set_uuid(sw); in tb_switch_add_dma_port()
2722 if (!sw->safe_mode) in tb_switch_add_dma_port()
2727 if (sw->no_nvm_upgrade) in tb_switch_add_dma_port()
2730 if (tb_switch_is_usb4(sw)) { in tb_switch_add_dma_port()
2731 ret = usb4_switch_nvm_authenticate_status(sw, &status); in tb_switch_add_dma_port()
2736 tb_sw_info(sw, "switch flash authentication failed\n"); in tb_switch_add_dma_port()
2737 nvm_set_auth_status(sw, status); in tb_switch_add_dma_port()
2744 if (!tb_route(sw) && !tb_switch_is_icm(sw)) in tb_switch_add_dma_port()
2747 sw->dma_port = dma_port_alloc(sw); in tb_switch_add_dma_port()
2748 if (!sw->dma_port) in tb_switch_add_dma_port()
2757 nvm_get_auth_status(sw, &status); in tb_switch_add_dma_port()
2759 if (!tb_route(sw)) in tb_switch_add_dma_port()
2760 nvm_authenticate_complete_dma_port(sw); in tb_switch_add_dma_port()
2769 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in tb_switch_add_dma_port()
2774 if (!tb_route(sw)) in tb_switch_add_dma_port()
2775 nvm_authenticate_complete_dma_port(sw); in tb_switch_add_dma_port()
2778 tb_sw_info(sw, "switch flash authentication failed\n"); in tb_switch_add_dma_port()
2779 nvm_set_auth_status(sw, status); in tb_switch_add_dma_port()
2782 tb_sw_info(sw, "power cycling the switch now\n"); in tb_switch_add_dma_port()
2783 dma_port_power_cycle(sw->dma_port); in tb_switch_add_dma_port()
2792 static void tb_switch_default_link_ports(struct tb_switch *sw) in tb_switch_default_link_ports() argument
2796 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_default_link_ports()
2797 struct tb_port *port = &sw->ports[i]; in tb_switch_default_link_ports()
2804 if (i == sw->config.max_port_number || in tb_switch_default_link_ports()
2805 !tb_port_is_null(&sw->ports[i + 1])) in tb_switch_default_link_ports()
2809 subordinate = &sw->ports[i + 1]; in tb_switch_default_link_ports()
2816 tb_sw_dbg(sw, "linked ports %d <-> %d\n", in tb_switch_default_link_ports()
2822 static bool tb_switch_lane_bonding_possible(struct tb_switch *sw) in tb_switch_lane_bonding_possible() argument
2824 const struct tb_port *up = tb_upstream_port(sw); in tb_switch_lane_bonding_possible()
2829 if (tb_switch_is_usb4(sw)) in tb_switch_lane_bonding_possible()
2830 return usb4_switch_lane_bonding_possible(sw); in tb_switch_lane_bonding_possible()
2831 return tb_lc_lane_bonding_possible(sw); in tb_switch_lane_bonding_possible()
2834 static int tb_switch_update_link_attributes(struct tb_switch *sw) in tb_switch_update_link_attributes() argument
2840 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_update_link_attributes()
2843 up = tb_upstream_port(sw); in tb_switch_update_link_attributes()
2848 if (sw->link_speed != ret) in tb_switch_update_link_attributes()
2850 sw->link_speed = ret; in tb_switch_update_link_attributes()
2855 if (sw->link_width != ret) in tb_switch_update_link_attributes()
2857 sw->link_width = ret; in tb_switch_update_link_attributes()
2860 if (device_is_registered(&sw->dev) && change) in tb_switch_update_link_attributes()
2861 kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); in tb_switch_update_link_attributes()
2867 static void tb_switch_link_init(struct tb_switch *sw) in tb_switch_link_init() argument
2872 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_link_init()
2875 tb_sw_dbg(sw, "current link speed %u.0 Gb/s\n", sw->link_speed); in tb_switch_link_init()
2876 tb_sw_dbg(sw, "current link width %s\n", width_name(sw->link_width)); in tb_switch_link_init()
2878 bonded = sw->link_width >= TB_LINK_WIDTH_DUAL; in tb_switch_link_init()
2884 up = tb_upstream_port(sw); in tb_switch_link_init()
2885 down = tb_switch_downstream_port(sw); in tb_switch_link_init()
2900 * @sw: Switch to enable lane bonding
2906 static int tb_switch_lane_bonding_enable(struct tb_switch *sw) in tb_switch_lane_bonding_enable() argument
2912 if (!tb_switch_lane_bonding_possible(sw)) in tb_switch_lane_bonding_enable()
2915 up = tb_upstream_port(sw); in tb_switch_lane_bonding_enable()
2916 down = tb_switch_downstream_port(sw); in tb_switch_lane_bonding_enable()
2951 * @sw: Switch whose lane bonding to disable
2953 * Disables lane bonding between @sw and parent. This can be called even
2956 static int tb_switch_lane_bonding_disable(struct tb_switch *sw) in tb_switch_lane_bonding_disable() argument
2961 up = tb_upstream_port(sw); in tb_switch_lane_bonding_disable()
2968 * if the link is not up anymore (sw is unplugged). in tb_switch_lane_bonding_disable()
2976 down = tb_switch_downstream_port(sw); in tb_switch_lane_bonding_disable()
2987 /* Note updating sw->link_width done in tb_switch_update_link_attributes() */
2988 static int tb_switch_asym_enable(struct tb_switch *sw, enum tb_link_width width) in tb_switch_asym_enable() argument
2994 up = tb_upstream_port(sw); in tb_switch_asym_enable()
2995 down = tb_switch_downstream_port(sw); in tb_switch_asym_enable()
3017 if (sw->link_width != width) { in tb_switch_asym_enable()
3030 /* Note updating sw->link_width done in tb_switch_update_link_attributes() */
3031 static int tb_switch_asym_disable(struct tb_switch *sw) in tb_switch_asym_disable() argument
3036 up = tb_upstream_port(sw); in tb_switch_asym_disable()
3037 down = tb_switch_downstream_port(sw); in tb_switch_asym_disable()
3052 if (sw->link_width > TB_LINK_WIDTH_DUAL) { in tb_switch_asym_disable()
3053 if (sw->link_width == TB_LINK_WIDTH_ASYM_TX) in tb_switch_asym_disable()
3070 * @sw: Router to configure
3081 int tb_switch_set_link_width(struct tb_switch *sw, enum tb_link_width width) in tb_switch_set_link_width() argument
3086 if (!tb_route(sw)) in tb_switch_set_link_width()
3089 up = tb_upstream_port(sw); in tb_switch_set_link_width()
3090 down = tb_switch_downstream_port(sw); in tb_switch_set_link_width()
3094 ret = tb_switch_lane_bonding_disable(sw); in tb_switch_set_link_width()
3098 if (sw->link_width == TB_LINK_WIDTH_ASYM_TX || in tb_switch_set_link_width()
3099 sw->link_width == TB_LINK_WIDTH_ASYM_RX) { in tb_switch_set_link_width()
3100 ret = tb_switch_asym_disable(sw); in tb_switch_set_link_width()
3104 ret = tb_switch_lane_bonding_enable(sw); in tb_switch_set_link_width()
3109 ret = tb_switch_asym_enable(sw, width); in tb_switch_set_link_width()
3118 tb_sw_warn(sw, "timeout changing link width\n"); in tb_switch_set_link_width()
3127 tb_sw_dbg(sw, "failed to change link width: %d\n", ret); in tb_switch_set_link_width()
3134 tb_switch_update_link_attributes(sw); in tb_switch_set_link_width()
3136 tb_sw_dbg(sw, "link width set to %s\n", width_name(width)); in tb_switch_set_link_width()
3142 * @sw: Switch whose link is configured
3144 * Sets the link upstream from @sw configured (from both ends) so that
3152 int tb_switch_configure_link(struct tb_switch *sw) in tb_switch_configure_link() argument
3157 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_configure_link()
3160 up = tb_upstream_port(sw); in tb_switch_configure_link()
3161 if (tb_switch_is_usb4(up->sw)) in tb_switch_configure_link()
3169 if (tb_switch_is_usb4(down->sw)) in tb_switch_configure_link()
3176 * @sw: Switch whose link is unconfigured
3178 * Sets the link unconfigured so the @sw will be disconnected if the
3181 void tb_switch_unconfigure_link(struct tb_switch *sw) in tb_switch_unconfigure_link() argument
3185 if (!tb_route(sw) || tb_switch_is_icm(sw)) in tb_switch_unconfigure_link()
3193 up = tb_upstream_port(sw); in tb_switch_unconfigure_link()
3195 if (tb_switch_is_usb4(down->sw)) in tb_switch_unconfigure_link()
3200 if (sw->is_unplugged) in tb_switch_unconfigure_link()
3203 up = tb_upstream_port(sw); in tb_switch_unconfigure_link()
3204 if (tb_switch_is_usb4(up->sw)) in tb_switch_unconfigure_link()
3210 static void tb_switch_credits_init(struct tb_switch *sw) in tb_switch_credits_init() argument
3212 if (tb_switch_is_icm(sw)) in tb_switch_credits_init()
3214 if (!tb_switch_is_usb4(sw)) in tb_switch_credits_init()
3216 if (usb4_switch_credits_init(sw)) in tb_switch_credits_init()
3217 tb_sw_info(sw, "failed to determine preferred buffer allocation, using defaults\n"); in tb_switch_credits_init()
3220 static int tb_switch_port_hotplug_enable(struct tb_switch *sw) in tb_switch_port_hotplug_enable() argument
3224 if (tb_switch_is_icm(sw)) in tb_switch_port_hotplug_enable()
3227 tb_switch_for_each_port(sw, port) { in tb_switch_port_hotplug_enable()
3242 * @sw: Switch to add
3252 int tb_switch_add(struct tb_switch *sw) in tb_switch_add() argument
3263 ret = tb_switch_add_dma_port(sw); in tb_switch_add()
3265 dev_err(&sw->dev, "failed to add DMA port\n"); in tb_switch_add()
3269 if (!sw->safe_mode) { in tb_switch_add()
3270 tb_switch_credits_init(sw); in tb_switch_add()
3273 ret = tb_drom_read(sw); in tb_switch_add()
3275 dev_warn(&sw->dev, "reading DROM failed: %d\n", ret); in tb_switch_add()
3276 tb_sw_dbg(sw, "uid: %#llx\n", sw->uid); in tb_switch_add()
3278 ret = tb_switch_set_uuid(sw); in tb_switch_add()
3280 dev_err(&sw->dev, "failed to set UUID\n"); in tb_switch_add()
3284 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_add()
3285 if (sw->ports[i].disabled) { in tb_switch_add()
3286 tb_port_dbg(&sw->ports[i], "disabled by eeprom\n"); in tb_switch_add()
3289 ret = tb_init_port(&sw->ports[i]); in tb_switch_add()
3291 dev_err(&sw->dev, "failed to initialize port %d\n", i); in tb_switch_add()
3296 tb_check_quirks(sw); in tb_switch_add()
3298 tb_switch_default_link_ports(sw); in tb_switch_add()
3300 ret = tb_switch_update_link_attributes(sw); in tb_switch_add()
3304 tb_switch_link_init(sw); in tb_switch_add()
3306 ret = tb_switch_clx_init(sw); in tb_switch_add()
3310 ret = tb_switch_tmu_init(sw); in tb_switch_add()
3315 ret = tb_switch_port_hotplug_enable(sw); in tb_switch_add()
3319 ret = device_add(&sw->dev); in tb_switch_add()
3321 dev_err(&sw->dev, "failed to add device: %d\n", ret); in tb_switch_add()
3325 if (tb_route(sw)) { in tb_switch_add()
3326 dev_info(&sw->dev, "new device found, vendor=%#x device=%#x\n", in tb_switch_add()
3327 sw->vendor, sw->device); in tb_switch_add()
3328 if (sw->vendor_name && sw->device_name) in tb_switch_add()
3329 dev_info(&sw->dev, "%s %s\n", sw->vendor_name, in tb_switch_add()
3330 sw->device_name); in tb_switch_add()
3333 ret = usb4_switch_add_ports(sw); in tb_switch_add()
3335 dev_err(&sw->dev, "failed to add USB4 ports\n"); in tb_switch_add()
3339 ret = tb_switch_nvm_add(sw); in tb_switch_add()
3341 dev_err(&sw->dev, "failed to add NVM devices\n"); in tb_switch_add()
3350 device_init_wakeup(&sw->dev, true); in tb_switch_add()
3352 pm_runtime_set_active(&sw->dev); in tb_switch_add()
3353 if (sw->rpm) { in tb_switch_add()
3354 pm_runtime_set_autosuspend_delay(&sw->dev, TB_AUTOSUSPEND_DELAY); in tb_switch_add()
3355 pm_runtime_use_autosuspend(&sw->dev); in tb_switch_add()
3356 pm_runtime_mark_last_busy(&sw->dev); in tb_switch_add()
3357 pm_runtime_enable(&sw->dev); in tb_switch_add()
3358 pm_request_autosuspend(&sw->dev); in tb_switch_add()
3361 tb_switch_debugfs_init(sw); in tb_switch_add()
3365 usb4_switch_remove_ports(sw); in tb_switch_add()
3367 device_del(&sw->dev); in tb_switch_add()
3374 * @sw: Switch to remove
3380 void tb_switch_remove(struct tb_switch *sw) in tb_switch_remove() argument
3384 tb_switch_debugfs_remove(sw); in tb_switch_remove()
3386 if (sw->rpm) { in tb_switch_remove()
3387 pm_runtime_get_sync(&sw->dev); in tb_switch_remove()
3388 pm_runtime_disable(&sw->dev); in tb_switch_remove()
3392 tb_switch_for_each_port(sw, port) { in tb_switch_remove()
3394 tb_switch_remove(port->remote->sw); in tb_switch_remove()
3406 if (!sw->is_unplugged) in tb_switch_remove()
3407 tb_plug_events_active(sw, false); in tb_switch_remove()
3409 tb_switch_nvm_remove(sw); in tb_switch_remove()
3410 usb4_switch_remove_ports(sw); in tb_switch_remove()
3412 if (tb_route(sw)) in tb_switch_remove()
3413 dev_info(&sw->dev, "device disconnected\n"); in tb_switch_remove()
3414 device_unregister(&sw->dev); in tb_switch_remove()
3419 * @sw: Router to mark unplugged
3421 void tb_sw_set_unplugged(struct tb_switch *sw) in tb_sw_set_unplugged() argument
3425 if (sw == sw->tb->root_switch) { in tb_sw_set_unplugged()
3426 tb_sw_WARN(sw, "cannot unplug root switch\n"); in tb_sw_set_unplugged()
3429 if (sw->is_unplugged) { in tb_sw_set_unplugged()
3430 tb_sw_WARN(sw, "is_unplugged already set\n"); in tb_sw_set_unplugged()
3433 sw->is_unplugged = true; in tb_sw_set_unplugged()
3434 tb_switch_for_each_port(sw, port) { in tb_sw_set_unplugged()
3436 tb_sw_set_unplugged(port->remote->sw); in tb_sw_set_unplugged()
3442 static int tb_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime) in tb_switch_set_wake() argument
3445 tb_sw_dbg(sw, "enabling wakeup: %#x\n", flags); in tb_switch_set_wake()
3447 tb_sw_dbg(sw, "disabling wakeup\n"); in tb_switch_set_wake()
3449 if (tb_switch_is_usb4(sw)) in tb_switch_set_wake()
3450 return usb4_switch_set_wake(sw, flags, runtime); in tb_switch_set_wake()
3451 return tb_lc_set_wake(sw, flags); in tb_switch_set_wake()
3454 static void tb_switch_check_wakes(struct tb_switch *sw) in tb_switch_check_wakes() argument
3456 if (device_may_wakeup(&sw->dev)) { in tb_switch_check_wakes()
3457 if (tb_switch_is_usb4(sw)) in tb_switch_check_wakes()
3458 usb4_switch_check_wakes(sw); in tb_switch_check_wakes()
3464 * @sw: Switch to resume
3473 int tb_switch_resume(struct tb_switch *sw, bool runtime) in tb_switch_resume() argument
3478 tb_sw_dbg(sw, "resuming switch\n"); in tb_switch_resume()
3484 if (tb_route(sw)) { in tb_switch_resume()
3492 err = tb_cfg_get_upstream_port(sw->tb->ctl, tb_route(sw)); in tb_switch_resume()
3494 tb_sw_info(sw, "switch not present anymore\n"); in tb_switch_resume()
3499 if (!sw->uid) in tb_switch_resume()
3502 if (tb_switch_is_usb4(sw)) in tb_switch_resume()
3503 err = usb4_switch_read_uid(sw, &uid); in tb_switch_resume()
3505 err = tb_drom_read_uid_only(sw, &uid); in tb_switch_resume()
3507 tb_sw_warn(sw, "uid read failed\n"); in tb_switch_resume()
3510 if (sw->uid != uid) { in tb_switch_resume()
3511 tb_sw_info(sw, in tb_switch_resume()
3513 sw->uid, uid); in tb_switch_resume()
3518 err = tb_switch_configure(sw); in tb_switch_resume()
3523 tb_switch_check_wakes(sw); in tb_switch_resume()
3526 tb_switch_set_wake(sw, 0, true); in tb_switch_resume()
3528 err = tb_switch_tmu_init(sw); in tb_switch_resume()
3533 tb_switch_for_each_port(sw, port) { in tb_switch_resume()
3544 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
3555 tb_switch_resume(port->remote->sw, runtime)) { in tb_switch_resume()
3558 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
3567 * @sw: Switch to suspend
3571 * value of @runtime and then sets sleep bit for the router. If @sw is
3575 void tb_switch_suspend(struct tb_switch *sw, bool runtime) in tb_switch_suspend() argument
3581 tb_sw_dbg(sw, "suspending switch\n"); in tb_switch_suspend()
3587 tb_switch_clx_disable(sw); in tb_switch_suspend()
3589 err = tb_plug_events_active(sw, false); in tb_switch_suspend()
3593 tb_switch_for_each_port(sw, port) { in tb_switch_suspend()
3595 tb_switch_suspend(port->remote->sw, runtime); in tb_switch_suspend()
3603 } else if (device_may_wakeup(&sw->dev)) { in tb_switch_suspend()
3607 tb_switch_set_wake(sw, flags, runtime); in tb_switch_suspend()
3609 if (tb_switch_is_usb4(sw)) in tb_switch_suspend()
3610 usb4_switch_set_sleep(sw); in tb_switch_suspend()
3612 tb_lc_set_sleep(sw); in tb_switch_suspend()
3617 * @sw: Switch whose DP resource is queried
3623 bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_query_dp_resource() argument
3625 if (tb_switch_is_usb4(sw)) in tb_switch_query_dp_resource()
3626 return usb4_switch_query_dp_resource(sw, in); in tb_switch_query_dp_resource()
3627 return tb_lc_dp_sink_query(sw, in); in tb_switch_query_dp_resource()
3632 * @sw: Switch whose DP resource is allocated
3639 int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_alloc_dp_resource() argument
3643 if (tb_switch_is_usb4(sw)) in tb_switch_alloc_dp_resource()
3644 ret = usb4_switch_alloc_dp_resource(sw, in); in tb_switch_alloc_dp_resource()
3646 ret = tb_lc_dp_sink_alloc(sw, in); in tb_switch_alloc_dp_resource()
3649 tb_sw_warn(sw, "failed to allocate DP resource for port %d\n", in tb_switch_alloc_dp_resource()
3652 tb_sw_dbg(sw, "allocated DP resource for port %d\n", in->port); in tb_switch_alloc_dp_resource()
3659 * @sw: Switch whose DP resource is de-allocated
3665 void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in tb_switch_dealloc_dp_resource() argument
3669 if (tb_switch_is_usb4(sw)) in tb_switch_dealloc_dp_resource()
3670 ret = usb4_switch_dealloc_dp_resource(sw, in); in tb_switch_dealloc_dp_resource()
3672 ret = tb_lc_dp_sink_dealloc(sw, in); in tb_switch_dealloc_dp_resource()
3675 tb_sw_warn(sw, "failed to de-allocate DP resource for port %d\n", in tb_switch_dealloc_dp_resource()
3678 tb_sw_dbg(sw, "released DP resource for port %d\n", in->port); in tb_switch_dealloc_dp_resource()
3691 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_match() local
3694 if (!sw) in tb_switch_match()
3696 if (sw->tb != lookup->tb) in tb_switch_match()
3700 return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid)); in tb_switch_match()
3703 return sw->config.route_lo == lower_32_bits(lookup->route) && in tb_switch_match()
3704 sw->config.route_hi == upper_32_bits(lookup->route); in tb_switch_match()
3709 return !sw->depth; in tb_switch_match()
3711 return sw->link == lookup->link && sw->depth == lookup->depth; in tb_switch_match()
3792 * tb_switch_find_port() - return the first port of @type on @sw or NULL
3793 * @sw: Switch to find the port from
3796 struct tb_port *tb_switch_find_port(struct tb_switch *sw, in tb_switch_find_port() argument
3801 tb_switch_for_each_port(sw, port) { in tb_switch_find_port()
3813 static int tb_switch_pcie_bridge_write(struct tb_switch *sw, unsigned int bridge, in tb_switch_pcie_bridge_write() argument
3819 if (sw->generation != 3) in tb_switch_pcie_bridge_write()
3822 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_WR_DATA; in tb_switch_pcie_bridge_write()
3823 ret = tb_sw_write(sw, &value, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3834 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_CMD; in tb_switch_pcie_bridge_write()
3836 ret = tb_sw_write(sw, &command, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3840 ret = tb_switch_wait_for_bit(sw, offset, in tb_switch_pcie_bridge_write()
3845 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_pcie_bridge_write()
3857 * @sw: Router to enable PCIe L1
3864 int tb_switch_pcie_l1_enable(struct tb_switch *sw) in tb_switch_pcie_l1_enable() argument
3866 struct tb_switch *parent = tb_switch_parent(sw); in tb_switch_pcie_l1_enable()
3869 if (!tb_route(sw)) in tb_switch_pcie_l1_enable()
3872 if (!tb_switch_is_titan_ridge(sw)) in tb_switch_pcie_l1_enable()
3880 ret = tb_switch_pcie_bridge_write(sw, 5, 0x143, 0x0c7806b1); in tb_switch_pcie_l1_enable()
3885 return tb_switch_pcie_bridge_write(sw, 0, 0x143, 0x0c5806b1); in tb_switch_pcie_l1_enable()
3890 * @sw: Router whose xHCI to connect
3898 int tb_switch_xhci_connect(struct tb_switch *sw) in tb_switch_xhci_connect() argument
3903 if (sw->generation != 3) in tb_switch_xhci_connect()
3906 port1 = &sw->ports[1]; in tb_switch_xhci_connect()
3907 port3 = &sw->ports[3]; in tb_switch_xhci_connect()
3909 if (tb_switch_is_alpine_ridge(sw)) { in tb_switch_xhci_connect()
3925 } else if (tb_switch_is_titan_ridge(sw)) { in tb_switch_xhci_connect()
3937 * @sw: Router whose xHCI to disconnect
3942 void tb_switch_xhci_disconnect(struct tb_switch *sw) in tb_switch_xhci_disconnect() argument
3944 if (sw->generation == 3) { in tb_switch_xhci_disconnect()
3945 struct tb_port *port1 = &sw->ports[1]; in tb_switch_xhci_disconnect()
3946 struct tb_port *port3 = &sw->ports[3]; in tb_switch_xhci_disconnect()