Lines Matching +full:dma +full:- +full:router
1 // SPDX-License-Identifier: GPL-2.0
3 * Thunderbolt driver - switch/port utility functions
11 #include <linux/nvmem-provider.h>
30 MODULE_PARM_DESC(clx, "allow low power states on the high-speed lanes (default: true)");
45 if (uuid_equal(&st->uuid, sw->uuid)) in __nvm_get_auth_status()
60 *status = st ? st->status : 0; in nvm_get_auth_status()
67 if (WARN_ON(!sw->uuid)) in nvm_set_auth_status()
78 memcpy(&st->uuid, sw->uuid, sizeof(st->uuid)); in nvm_set_auth_status()
79 INIT_LIST_HEAD(&st->list); in nvm_set_auth_status()
80 list_add_tail(&st->list, &nvm_auth_status_cache); in nvm_set_auth_status()
83 st->status = status; in nvm_set_auth_status()
95 list_del(&st->list); in nvm_clear_auth_status()
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()
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()
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()
149 if (!ret || ret == -ETIMEDOUT) in nvm_authenticate_host_dma_port()
154 * cycling of the host router. 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()
165 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_host_dma_port()
173 ret = dma_port_flash_update_auth(sw->dma_port); in nvm_authenticate_device_dma_port()
176 case -ETIMEDOUT: in nvm_authenticate_device_dma_port()
177 case -EACCES: in nvm_authenticate_device_dma_port()
178 case -EINVAL: in nvm_authenticate_device_dma_port()
194 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in nvm_authenticate_device_dma_port()
195 if (ret < 0 && ret != -ETIMEDOUT) in nvm_authenticate_device_dma_port()
204 dma_port_power_cycle(sw->dma_port); in nvm_authenticate_device_dma_port()
209 } while (--retries); in nvm_authenticate_device_dma_port()
211 return -ETIMEDOUT; in nvm_authenticate_device_dma_port()
219 * During host router NVM upgrade we should not allow root port to in nvm_authenticate_start_dma_port()
224 root_port = pcie_find_root_port(sw->tb->nhi->pdev); in nvm_authenticate_start_dma_port()
226 pm_runtime_get_noresume(&root_port->dev); in nvm_authenticate_start_dma_port()
233 root_port = pcie_find_root_port(sw->tb->nhi->pdev); in nvm_authenticate_complete_dma_port()
235 pm_runtime_put(&root_port->dev); in nvm_authenticate_complete_dma_port()
250 /* Thunderbolt 2 and 3 devices support NVM through DMA port */ in nvm_readable()
251 return !!sw->dma_port; in nvm_readable()
256 if (sw->no_nvm_upgrade) in nvm_upgradeable()
271 sw->nvm->authenticating = true; in nvm_authenticate()
274 return -EOPNOTSUPP; in nvm_authenticate()
277 sw->nvm->authenticating = true; in nvm_authenticate()
289 * tb_switch_nvm_read() - Read router NVM
290 * @sw: Router whose NVM to read
295 * Reads from router NVM and returns the requested data in @buf. Locking
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()
313 pm_runtime_get_sync(&sw->dev); in nvm_read()
315 if (!mutex_trylock(&sw->tb->lock)) { 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()
336 if (!mutex_trylock(&sw->tb->lock)) in nvm_write()
346 mutex_unlock(&sw->tb->lock); in nvm_write()
359 nvm = tb_nvm_alloc(&sw->dev); in tb_switch_nvm_add()
361 ret = PTR_ERR(nvm) == -EOPNOTSUPP ? 0 : PTR_ERR(nvm); in tb_switch_nvm_add()
370 * If the switch is in safe-mode the only accessible portion of in tb_switch_nvm_add()
371 * the NVM is the non-active one where userspace is expected to 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()
391 sw->no_nvm_upgrade = true; in tb_switch_nvm_add()
402 nvm = sw->nvm; in tb_switch_nvm_remove()
403 sw->nvm = NULL; in tb_switch_nvm_remove()
409 if (!nvm->authenticating) in tb_switch_nvm_remove()
419 switch (port->type >> 16) { in tb_port_type()
421 switch ((u8) port->type) { in tb_port_type()
448 const struct tb_regs_port_header *regs = &port->config; in tb_dump_port()
452 regs->port_number, regs->vendor_id, regs->device_id, in tb_dump_port()
453 regs->revision, regs->thunderbolt_version, tb_port_type(regs), in tb_dump_port()
454 regs->type); in tb_dump_port()
456 regs->max_in_hop_id, regs->max_out_hop_id); in tb_dump_port()
457 tb_dbg(tb, " Max counters: %d\n", regs->max_counters); in tb_dump_port()
458 tb_dbg(tb, " NFC Credits: %#x\n", regs->nfc_credits); in tb_dump_port()
459 tb_dbg(tb, " Credits (total/control): %u/%u\n", port->total_credits, in tb_dump_port()
460 port->ctl_credits); in tb_dump_port()
464 * tb_port_state() - get connectedness state of a port
475 if (port->cap_phy == 0) { in tb_port_state()
477 return -EINVAL; in tb_port_state()
479 res = tb_port_read(port, &phy, TB_CFG_PORT, port->cap_phy, 2); in tb_port_state()
486 * tb_wait_for_port() - wait for a port to become ready
504 if (!port->cap_phy) { in tb_wait_for_port()
506 return -EINVAL; in tb_wait_for_port()
510 return -EINVAL; in tb_wait_for_port()
513 while (retries--) { in tb_wait_for_port()
538 * After plug-in the state is TB_PORT_CONNECTING. Give it some in tb_wait_for_port()
552 * tb_port_add_nfc_credits() - add/remove non flow controlled credits to port
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()
575 nfc_credits = port->config.nfc_credits & ADP_CS_4_NFC_BUFFERS_MASK; in tb_port_add_nfc_credits()
577 credits = max_t(int, -nfc_credits, credits); in tb_port_add_nfc_credits()
582 port->config.nfc_credits & ADP_CS_4_NFC_BUFFERS_MASK); in tb_port_add_nfc_credits()
584 port->config.nfc_credits &= ~ADP_CS_4_NFC_BUFFERS_MASK; in tb_port_add_nfc_credits()
585 port->config.nfc_credits |= nfc_credits; in tb_port_add_nfc_credits()
587 return tb_port_write(port, &port->config.nfc_credits, in tb_port_add_nfc_credits()
592 * tb_port_clear_counter() - clear a counter in TB_CFG_COUNTER
606 * tb_port_unlock() - Unlock downstream port
610 * downstream router accessible for CM.
614 if (tb_switch_is_icm(port->sw)) in tb_port_unlock()
617 return -EINVAL; in tb_port_unlock()
618 if (tb_switch_is_usb4(port->sw)) in tb_port_unlock()
629 return -EINVAL; in __tb_port_enable()
632 port->cap_phy + LANE_ADP_CS_1, 1); in __tb_port_enable()
643 port->cap_phy + LANE_ADP_CS_1, 1); in __tb_port_enable()
652 * tb_port_enable() - Enable lane adapter
663 * tb_port_disable() - Disable lane adapter
674 * tb_init_port() - initialize a port
686 INIT_LIST_HEAD(&port->list); in tb_init_port()
689 if (!port->port) in tb_init_port()
692 res = tb_port_read(port, &port->config, TB_CFG_PORT, 0, 8); in tb_init_port()
694 if (res == -ENODEV) { in tb_init_port()
695 tb_dbg(port->sw->tb, " Port %d: not implemented\n", in tb_init_port()
696 port->port); in tb_init_port()
697 port->disabled = true; in tb_init_port()
704 if (port->config.type == TB_TYPE_PORT) { in tb_init_port()
708 port->cap_phy = cap; in tb_init_port()
714 port->cap_usb4 = cap; in tb_init_port()
719 * devices we use hard-coded value. in tb_init_port()
721 if (tb_switch_is_usb4(port->sw)) { in tb_init_port()
725 port->ctl_credits = hop.initial_credits; in tb_init_port()
727 if (!port->ctl_credits) in tb_init_port()
728 port->ctl_credits = 2; in tb_init_port()
733 port->cap_adap = cap; in tb_init_port()
736 port->total_credits = in tb_init_port()
737 (port->config.nfc_credits & ADP_CS_4_TOTAL_BUFFERS_MASK) >> in tb_init_port()
740 tb_dump_port(port->sw->tb, port); in tb_init_port()
751 port_max_hopid = port->config.max_in_hop_id; in tb_port_alloc_hopid()
752 ida = &port->in_hopids; in tb_port_alloc_hopid()
754 port_max_hopid = port->config.max_out_hop_id; in tb_port_alloc_hopid()
755 ida = &port->out_hopids; in tb_port_alloc_hopid()
759 * NHI can use HopIDs 1-max for other adapters HopIDs 0-7 are in tb_port_alloc_hopid()
772 * tb_port_alloc_in_hopid() - Allocate input HopID from port
786 * tb_port_alloc_out_hopid() - Allocate output HopID from port
800 * tb_port_release_in_hopid() - Release allocated input HopID from port
806 ida_simple_remove(&port->in_hopids, hopid); in tb_port_release_in_hopid()
810 * tb_port_release_out_hopid() - Release allocated output HopID from port
816 ida_simple_remove(&port->out_hopids, hopid); in tb_port_release_out_hopid()
822 u64 mask = (1ULL << parent->config.depth * 8) - 1; in tb_switch_is_reachable()
827 * tb_next_port_on_path() - Return next port for given port on a path
839 * Domain tb->lock must be held when this function is called.
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()
858 if (prev->remote && in tb_next_port_on_path()
859 (next == prev || next->dual_link_port == prev)) in tb_next_port_on_path()
860 next = prev->remote; in tb_next_port_on_path()
863 next = prev->remote; in tb_next_port_on_path()
865 next = tb_upstream_port(prev->sw); in tb_next_port_on_path()
870 if (next->dual_link_port && in tb_next_port_on_path()
871 next->link_nr != prev->link_nr) { in tb_next_port_on_path()
872 next = next->dual_link_port; in tb_next_port_on_path()
881 * tb_port_get_link_speed() - Get current link speed
891 if (!port->cap_phy) in tb_port_get_link_speed()
892 return -EINVAL; in tb_port_get_link_speed()
895 port->cap_phy + LANE_ADP_CS_1, 1); in tb_port_get_link_speed()
905 * tb_port_get_link_width() - Get current link width
908 * Returns link width. Return values can be 1 (Single-Lane), 2 (Dual-Lane)
916 if (!port->cap_phy) in tb_port_get_link_width()
917 return -EINVAL; in tb_port_get_link_width()
920 port->cap_phy + LANE_ADP_CS_1, 1); in tb_port_get_link_width()
933 if (!port->cap_phy) in tb_port_is_width_supported()
937 port->cap_phy + LANE_ADP_CS_0, 1); in tb_port_is_width_supported()
948 * tb_port_set_link_width() - Set target link width of the lane adapter
962 if (!port->cap_phy) in tb_port_set_link_width()
963 return -EINVAL; in tb_port_set_link_width()
966 port->cap_phy + LANE_ADP_CS_1, 1); in tb_port_set_link_width()
981 return -EINVAL; in tb_port_set_link_width()
985 port->cap_phy + LANE_ADP_CS_1, 1); in tb_port_set_link_width()
989 * tb_port_set_lane_bonding() - Enable/disable lane bonding
998 * As a side effect sets @port->bonding accordingly (and does the same
1008 if (!port->cap_phy) in tb_port_set_lane_bonding()
1009 return -EINVAL; in tb_port_set_lane_bonding()
1012 port->cap_phy + LANE_ADP_CS_1, 1); in tb_port_set_lane_bonding()
1022 port->cap_phy + LANE_ADP_CS_1, 1); in tb_port_set_lane_bonding()
1030 port->bonded = bonding; in tb_port_set_lane_bonding()
1031 port->dual_link_port->bonded = bonding; in tb_port_set_lane_bonding()
1037 * tb_port_lane_bonding_enable() - Enable bonding on port
1063 ret = tb_port_get_link_width(port->dual_link_port); in tb_port_lane_bonding_enable()
1065 ret = tb_port_set_link_width(port->dual_link_port, 2); in tb_port_lane_bonding_enable()
1077 tb_port_set_link_width(port->dual_link_port, 1); in tb_port_lane_bonding_enable()
1084 * tb_port_lane_bonding_disable() - Disable bonding on port
1093 tb_port_set_link_width(port->dual_link_port, 1); in tb_port_lane_bonding_disable()
1098 * tb_port_wait_for_link_width() - Wait until link reaches specific width
1105 * the expected state. Returns %-ETIMEDOUT if the @width was not reached
1122 if (ret != -EACCES) in tb_port_wait_for_link_width()
1131 return -ETIMEDOUT; in tb_port_wait_for_link_width()
1143 if (nfc_credits != port->config.nfc_credits) { in tb_port_do_update_credits()
1149 tb_port_dbg(port, "total credits changed %u -> %u\n", in tb_port_do_update_credits()
1150 port->total_credits, total); in tb_port_do_update_credits()
1152 port->config.nfc_credits = nfc_credits; in tb_port_do_update_credits()
1153 port->total_credits = total; in tb_port_do_update_credits()
1160 * tb_port_update_credits() - Re-read port total credits
1164 * credits may change, so this function needs to be called to re-read
1174 return tb_port_do_update_credits(port->dual_link_port); in tb_port_update_credits()
1183 port->cap_phy + LANE_ADP_CS_1, 1); in __tb_port_pm_secondary_set()
1193 port->cap_phy + LANE_ADP_CS_1, 1); in __tb_port_pm_secondary_set()
1212 /* Don't enable CLx in case of two single-lane links */ in tb_port_clx_supported()
1213 if (!port->bonded && port->dual_link_port) in tb_port_clx_supported()
1216 /* Don't enable CLx in case of inter-domain link */ in tb_port_clx_supported()
1217 if (port->xdomain) in tb_port_clx_supported()
1220 if (tb_switch_is_usb4(port->sw)) { in tb_port_clx_supported()
1235 port->cap_phy + LANE_ADP_CS_0, 1); in tb_port_clx_supported()
1252 return -EOPNOTSUPP; in __tb_port_clx_set()
1255 port->cap_phy + LANE_ADP_CS_1, 1); in __tb_port_clx_set()
1265 port->cap_phy + LANE_ADP_CS_1, 1); in __tb_port_clx_set()
1279 * tb_port_is_clx_enabled() - Is given CL state enabled
1299 port->cap_phy + LANE_ADP_CS_1, 1); in tb_port_is_clx_enabled()
1310 if (tb_switch_is_usb4(port->sw)) in tb_port_start_lane_initialization()
1314 return ret == -EINVAL ? 0 : ret; in tb_port_start_lane_initialization()
1318 * Returns true if the port had something (router, XDomain) connected
1325 if (port->usb4) { in tb_port_resume()
1326 usb4_port_device_resume(port->usb4); in tb_port_resume()
1333 * link gets re-established. in tb_port_resume()
1335 * This is only needed for non-USB4 ports. in tb_port_resume()
1337 if (!tb_is_upstream_port(port) || port->xdomain) in tb_port_resume()
1341 return has_remote || port->xdomain; in tb_port_resume()
1345 * tb_port_is_enabled() - Is the adapter port enabled
1350 switch (port->config.type) { in tb_port_is_enabled()
1369 * tb_usb3_port_is_enabled() - Is the USB3 adapter port enabled
1377 port->cap_adap + ADP_USB3_CS_0, 1)) in tb_usb3_port_is_enabled()
1384 * tb_usb3_port_enable() - Enable USB3 adapter port
1393 if (!port->cap_adap) in tb_usb3_port_enable()
1394 return -ENXIO; in tb_usb3_port_enable()
1396 port->cap_adap + ADP_USB3_CS_0, 1); in tb_usb3_port_enable()
1400 * tb_pci_port_is_enabled() - Is the PCIe adapter port enabled
1408 port->cap_adap + ADP_PCIE_CS_0, 1)) in tb_pci_port_is_enabled()
1415 * tb_pci_port_enable() - Enable PCIe adapter port
1422 if (!port->cap_adap) in tb_pci_port_enable()
1423 return -ENXIO; in tb_pci_port_enable()
1425 port->cap_adap + ADP_PCIE_CS_0, 1); in tb_pci_port_enable()
1429 * tb_dp_port_hpd_is_active() - Is HPD already active
1440 port->cap_adap + ADP_DP_CS_2, 1); in tb_dp_port_hpd_is_active()
1448 * tb_dp_port_hpd_clear() - Clear HPD from DP IN port
1459 port->cap_adap + ADP_DP_CS_3, 1); in tb_dp_port_hpd_clear()
1465 port->cap_adap + ADP_DP_CS_3, 1); in tb_dp_port_hpd_clear()
1469 * tb_dp_port_set_hops() - Set video/aux Hop IDs for DP port
1476 * router DP adapters too but does not program the values as the fields
1477 * are read-only.
1485 if (tb_switch_is_usb4(port->sw)) in tb_dp_port_set_hops()
1489 port->cap_adap + ADP_DP_CS_0, ARRAY_SIZE(data)); in tb_dp_port_set_hops()
1504 port->cap_adap + ADP_DP_CS_0, ARRAY_SIZE(data)); in tb_dp_port_set_hops()
1508 * tb_dp_port_is_enabled() - Is DP adapter port enabled
1515 if (tb_port_read(port, data, TB_CFG_PORT, port->cap_adap + ADP_DP_CS_0, in tb_dp_port_is_enabled()
1523 * tb_dp_port_enable() - Enables/disables DP paths of a port
1536 port->cap_adap + ADP_DP_CS_0, ARRAY_SIZE(data)); in tb_dp_port_enable()
1546 port->cap_adap + ADP_DP_CS_0, ARRAY_SIZE(data)); in tb_dp_port_enable()
1553 switch (sw->generation) { in tb_switch_generation_name()
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()
1573 regs->revision, regs->thunderbolt_version); in tb_dump_switch()
1574 tb_dbg(tb, " Max Port Number: %d\n", regs->max_port_number); in tb_dump_switch()
1578 regs->upstream_port_number, regs->depth, in tb_dump_switch()
1579 (((u64) regs->route_hi) << 32) | regs->route_lo, in tb_dump_switch()
1580 regs->enabled, regs->plug_events_delay); in tb_dump_switch()
1582 regs->__unknown1, regs->__unknown4); in tb_dump_switch()
1586 * tb_switch_reset() - reconfigure route, enable and send TB_CFG_PKG_RESET
1595 if (sw->generation > 1) 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()
1606 return -EIO; in tb_switch_reset()
1611 * tb_switch_wait_for_bit() - Wait for specified value of bits in offset
1612 * @sw: Router to read the offset value from
1613 * @offset: Offset in the router config space to read from
1619 * Returns %0 in case of success, %-ETIMEDOUT if the @value was not reached
1641 return -ETIMEDOUT; in tb_switch_wait_for_bit()
1645 * tb_plug_events_active() - enable/disable plug events on a switch
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()
1688 sw->cap_plug_events + 1, 1); in tb_plug_events_active()
1697 return sysfs_emit(buf, "%u\n", sw->authorized); in authorized_show()
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()
1728 int ret = -EINVAL; in tb_switch_set_authorized()
1731 if (!mutex_trylock(&sw->tb->lock)) in tb_switch_set_authorized()
1734 if (!!sw->authorized == !!val) 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()
1791 return -EINVAL; in authorized_store()
1793 pm_runtime_get_sync(&sw->dev); in authorized_store()
1795 pm_runtime_mark_last_busy(&sw->dev); in authorized_store()
1796 pm_runtime_put_autosuspend(&sw->dev); in authorized_store()
1807 return sysfs_emit(buf, "%u\n", sw->boot); in boot_show()
1816 return sysfs_emit(buf, "%#x\n", sw->device); in device_show()
1825 return sysfs_emit(buf, "%s\n", sw->device_name ?: ""); in device_name_show()
1834 return sysfs_emit(buf, "%u\n", sw->generation); in generation_show()
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()
1867 return -EINVAL; in key_store()
1869 if (!mutex_trylock(&sw->tb->lock)) in key_store()
1872 if (sw->authorized) { in key_store()
1873 ret = -EBUSY; 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()
1881 ret = -ENOMEM; in key_store()
1885 mutex_unlock(&sw->tb->lock); in key_store()
1895 return sysfs_emit(buf, "%u.0 Gb/s\n", sw->link_speed); in speed_show()
1910 return sysfs_emit(buf, "%u\n", sw->link_width); in lanes_show()
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()
1944 ret = -EOPNOTSUPP; in nvm_authenticate_sysfs()
1949 if (!sw->nvm) { in nvm_authenticate_sysfs()
1950 ret = -EAGAIN; in nvm_authenticate_sysfs()
1964 ret = -EINVAL; in nvm_authenticate_sysfs()
1968 if (!sw->nvm->flushed) { in nvm_authenticate_sysfs()
1969 if (!sw->nvm->buf) { in nvm_authenticate_sysfs()
1970 ret = -EINVAL; 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()
2028 if (!mutex_trylock(&sw->tb->lock)) in nvm_version_show()
2031 if (sw->safe_mode) in nvm_version_show()
2032 ret = -ENODATA; in nvm_version_show()
2033 else if (!sw->nvm) in nvm_version_show()
2034 ret = -EAGAIN; 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()
2049 return sysfs_emit(buf, "%#x\n", sw->vendor); in vendor_show()
2058 return sysfs_emit(buf, "%s\n", sw->vendor_name ?: ""); in vendor_name_show()
2067 return sysfs_emit(buf, "%pUb\n", sw->uuid); in unique_id_show()
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()
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()
2117 return attr->mode; in switch_attr_is_visible()
2124 return attr->mode; in switch_attr_is_visible()
2128 return attr->mode; in switch_attr_is_visible()
2132 return attr->mode; in switch_attr_is_visible()
2136 return attr->mode; in switch_attr_is_visible()
2139 if (sw->quirks & QUIRK_FORCE_POWER_LINK_CONTROLLER) in switch_attr_is_visible()
2140 return attr->mode; in switch_attr_is_visible()
2144 return sw->safe_mode ? 0 : attr->mode; in switch_attr_is_visible()
2162 dma_port_free(sw->dma_port); in tb_switch_release()
2165 ida_destroy(&port->in_hopids); in tb_switch_release()
2166 ida_destroy(&port->out_hopids); 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()
2183 if (sw->config.thunderbolt_version == USB4_VERSION_1_0) { in tb_switch_uevent()
2185 return -ENOMEM; in tb_switch_uevent()
2196 if (!port->disabled && !tb_is_upstream_port(port) && in tb_switch_uevent()
2207 return -ENOMEM; in tb_switch_uevent()
2218 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_suspend()
2220 if (cm_ops->runtime_suspend_switch) in tb_switch_runtime_suspend()
2221 return cm_ops->runtime_suspend_switch(sw); in tb_switch_runtime_suspend()
2229 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in tb_switch_runtime_resume()
2231 if (cm_ops->runtime_resume_switch) in tb_switch_runtime_resume()
2232 return cm_ops->runtime_resume_switch(sw); in tb_switch_runtime_resume()
2250 switch (sw->config.device_id) { in tb_switch_get_generation()
2287 sw->config.device_id); in tb_switch_get_generation()
2297 (sw->tb->root_switch && tb_switch_is_usb4(sw->tb->root_switch))) in tb_switch_exceeds_max_depth()
2306 * tb_switch_alloc() - allocate a switch
2337 upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); in tb_switch_alloc()
2343 return ERR_PTR(-ENOMEM); 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()
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()
2364 ret = -EADDRNOTAVAIL; 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()
2372 ret = -ENOMEM; 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()
2390 sw->cap_plug_events = ret; in tb_switch_alloc()
2394 sw->cap_vsec_tmu = ret; in tb_switch_alloc()
2398 sw->cap_lc = ret; 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()
2418 kfree(sw->ports); in tb_switch_alloc()
2425 * tb_switch_alloc_safe_mode() - allocate a switch that is in safe mode
2431 * lacks all capabilities except DMA configuration port before it is
2445 return ERR_PTR(-ENOMEM); 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()
2464 * tb_switch_configure() - Uploads configuration to the switch
2470 * resume from low power states to re-initialize it.
2476 struct tb *tb = sw->tb; 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()
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()
2505 if (sw->config.vendor_id != PCI_VENDOR_ID_INTEL) in tb_switch_configure()
2507 sw->config.vendor_id); in tb_switch_configure()
2509 if (!sw->cap_plug_events) { in tb_switch_configure()
2511 return -ENODEV; in tb_switch_configure()
2515 ret = tb_sw_write(sw, (u32 *)&sw->config + 1, TB_CFG_SWITCH, in tb_switch_configure()
2530 if (sw->uuid) in tb_switch_set_uuid()
2534 ret = usb4_switch_read_uid(sw, &sw->uid); in tb_switch_set_uuid()
2545 if (ret != -EINVAL) 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()
2566 return -ENOMEM; in tb_switch_set_uuid()
2575 switch (sw->generation) { in tb_switch_add_dma_port()
2591 * DMA port is the only thing available when the switch 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()
2615 /* Root switch DMA port requires running firmware */ 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()
2641 ret = dma_port_flash_update_auth_status(sw->dma_port, &status); in tb_switch_add_dma_port()
2655 dma_port_power_cycle(sw->dma_port); in tb_switch_add_dma_port()
2661 return -ESHUTDOWN; in tb_switch_add_dma_port()
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()
2682 if (!port->dual_link_port && !subordinate->dual_link_port) { in tb_switch_default_link_ports()
2683 port->link_nr = 0; in tb_switch_default_link_ports()
2684 port->dual_link_port = subordinate; in tb_switch_default_link_ports()
2685 subordinate->link_nr = 1; in tb_switch_default_link_ports()
2686 subordinate->dual_link_port = port; in tb_switch_default_link_ports()
2688 tb_sw_dbg(sw, "linked ports %d <-> %d\n", in tb_switch_default_link_ports()
2689 port->port, subordinate->port); in tb_switch_default_link_ports()
2698 if (!up->dual_link_port || !up->dual_link_port->remote) in tb_switch_lane_bonding_possible()
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()
2739 * tb_switch_lane_bonding_enable() - Enable lane bonding
2748 struct tb_switch *parent = tb_to_switch(sw->dev.parent); in tb_switch_lane_bonding_enable()
2794 * tb_switch_lane_bonding_disable() - Disable lane bonding
2802 struct tb_switch *parent = tb_to_switch(sw->dev.parent); in tb_switch_lane_bonding_disable()
2809 if (!up->bonded) in tb_switch_lane_bonding_disable()
2818 * It is fine if we get other errors as the router might have in tb_switch_lane_bonding_disable()
2821 if (tb_port_wait_for_link_width(down, 1, 100) == -ETIMEDOUT) in tb_switch_lane_bonding_disable()
2832 * tb_switch_configure_link() - Set link configured
2852 if (tb_switch_is_usb4(up->sw)) in tb_switch_configure_link()
2859 down = up->remote; in tb_switch_configure_link()
2860 if (tb_switch_is_usb4(down->sw)) in tb_switch_configure_link()
2866 * tb_switch_unconfigure_link() - Unconfigure link
2876 if (sw->is_unplugged) in tb_switch_unconfigure_link()
2882 if (tb_switch_is_usb4(up->sw)) in tb_switch_unconfigure_link()
2887 down = up->remote; in tb_switch_unconfigure_link()
2888 if (tb_switch_is_usb4(down->sw)) in tb_switch_unconfigure_link()
2914 if (!port->cap_usb4) in tb_switch_port_hotplug_enable()
2925 * tb_switch_add() - Add a switch to the domain
2941 * Initialize DMA control port now before we read DROM. Recent in tb_switch_add()
2944 * to the userspace. NVM can be accessed through DMA 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()
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()
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()
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()
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()
3013 dev_err(&sw->dev, "failed to add USB4 ports\n"); 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()
3045 device_del(&sw->dev); in tb_switch_add()
3051 * tb_switch_remove() - Remove and release a switch
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()
3072 tb_switch_remove(port->remote->sw); in tb_switch_remove()
3073 port->remote = NULL; in tb_switch_remove()
3074 } else if (port->xdomain) { in tb_switch_remove()
3075 tb_xdomain_remove(port->xdomain); in tb_switch_remove()
3076 port->xdomain = NULL; in tb_switch_remove()
3083 if (!sw->is_unplugged) 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()
3095 * tb_sw_set_unplugged() - set is_unplugged on switch and downstream switches
3096 * @sw: Router to mark unplugged
3102 if (sw == sw->tb->root_switch) { in tb_sw_set_unplugged()
3106 if (sw->is_unplugged) { in tb_sw_set_unplugged()
3110 sw->is_unplugged = true; in tb_sw_set_unplugged()
3113 tb_sw_set_unplugged(port->remote->sw); in tb_sw_set_unplugged()
3114 else if (port->xdomain) in tb_sw_set_unplugged()
3115 port->xdomain->is_unplugged = true; in tb_sw_set_unplugged()
3150 err = tb_cfg_get_upstream_port(sw->tb->ctl, tb_route(sw)); in tb_switch_resume()
3157 if (!sw->uid) in tb_switch_resume()
3158 return -ENODEV; in tb_switch_resume()
3168 if (sw->uid != uid) { in tb_switch_resume()
3170 "changed while suspended (uid %#llx -> %#llx)\n", in tb_switch_resume()
3171 sw->uid, uid); in tb_switch_resume()
3172 return -ENODEV; in tb_switch_resume()
3199 tb_sw_set_unplugged(port->remote->sw); in tb_switch_resume()
3200 else if (port->xdomain) in tb_switch_resume()
3201 port->xdomain->is_unplugged = true; 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()
3220 * tb_switch_suspend() - Put a switch to sleep
3224 * Suspends router and all its children. Enables wakes according to
3225 * value of @runtime and then sets sleep bit for the router. If @sw is
3226 * host router the domain is ready to go to sleep once this function
3239 * done for USB4 device too as CLx is re-enabled at resume. 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()
3275 * tb_switch_query_dp_resource() - Query availability of DP resource
3290 * tb_switch_alloc_dp_resource() - Allocate available DP resource
3309 in->port); 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()
3317 * tb_switch_dealloc_dp_resource() - De-allocate DP resource
3318 * @sw: Switch whose DP resource is de-allocated
3321 * De-allocates DP resource that was previously allocated for DP
3334 tb_sw_warn(sw, "failed to de-allocate DP resource for port %d\n", in tb_switch_dealloc_dp_resource()
3335 in->port); 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()
3355 if (sw->tb != lookup->tb) in tb_switch_match()
3358 if (lookup->uuid) in tb_switch_match()
3359 return !memcmp(sw->uuid, lookup->uuid, sizeof(*lookup->uuid)); in tb_switch_match()
3361 if (lookup->route) { 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()
3367 if (!lookup->depth) 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()
3374 * tb_switch_find_by_link_depth() - Find switch by link and depth
3400 * tb_switch_find_by_uuid() - Find switch by UUID
3424 * tb_switch_find_by_route() - Find switch by route string
3437 return tb_switch_get(tb->root_switch); in tb_switch_find_by_route()
3451 * tb_switch_find_port() - return the first port of @type on @sw or NULL
3461 if (port->config.type == type) in tb_switch_find_port()
3497 * Enable CLx for host router's downstream port as part of the in __tb_switch_enable_clx()
3498 * downstream router enabling procedure. in __tb_switch_enable_clx()
3503 /* Enable CLx only for first hop router (depth = 1) */ in __tb_switch_enable_clx()
3523 return -EOPNOTSUPP; in __tb_switch_enable_clx()
3542 sw->clx = clx; in __tb_switch_enable_clx()
3549 * tb_switch_enable_clx() - Enable CLx on upstream port of specified router
3550 * @sw: Router to enable CLx for
3553 * Enable CLx state only for first hop router. That is the most common
3554 * use-case, that is intended for better thermal management, and so helps
3557 * single lane links and only if the link is not inter-domain link. The
3564 struct tb_switch *root_sw = sw->tb->root_switch; in tb_switch_enable_clx()
3573 if (root_sw->generation < 4 || tb_switch_is_tiger_lake(root_sw)) in tb_switch_enable_clx()
3582 return -EOPNOTSUPP; in tb_switch_enable_clx()
3596 * Disable CLx for host router's downstream port as part of the in __tb_switch_disable_clx()
3597 * downstream router enabling procedure. in __tb_switch_disable_clx()
3602 /* Disable CLx only for first hop router (depth = 1) */ in __tb_switch_disable_clx()
3616 sw->clx = TB_CLX_DISABLE; in __tb_switch_disable_clx()
3623 * tb_switch_disable_clx() - Disable CLx on upstream port of specified router
3624 * @sw: Router to disable CLx for
3640 return -EOPNOTSUPP; in tb_switch_disable_clx()
3645 * tb_switch_mask_clx_objections() - Mask CLx objections for a router
3646 * @sw: Router to mask objections for
3654 int up_port = sw->config.upstream_port_number; in tb_switch_mask_clx_objections()
3658 /* Only Titan Ridge of pre-USB4 devices support CLx states */ in tb_switch_mask_clx_objections()
3666 * In Titan Ridge there are only 2 dual-lane Thunderbolt ports: in tb_switch_mask_clx_objections()
3670 * port B (lanes 3,4) and unmask objections from Port A and vice-versa. in tb_switch_mask_clx_objections()
3683 sw->cap_lp + offset, ARRAY_SIZE(val)); in tb_switch_mask_clx_objections()
3693 sw->cap_lp + offset, ARRAY_SIZE(val)); in tb_switch_mask_clx_objections()
3706 if (sw->generation != 3) in tb_switch_pcie_bridge_write()
3707 return -EOPNOTSUPP; in tb_switch_pcie_bridge_write()
3709 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_WR_DATA; in tb_switch_pcie_bridge_write()
3721 offset = sw->cap_plug_events + TB_PLUG_EVENTS_PCIE_CMD; in tb_switch_pcie_bridge_write()
3737 return -ETIMEDOUT; in tb_switch_pcie_bridge_write()
3743 * tb_switch_pcie_l1_enable() - Enable PCIe link to enter L1 state
3744 * @sw: Router to enable PCIe L1
3762 /* Enable PCIe L1 enable only for first hop router (depth = 1) */ in tb_switch_pcie_l1_enable()
3776 * tb_switch_xhci_connect() - Connect internal xHCI
3777 * @sw: Router whose xHCI to connect
3779 * Can be called to any router. For Alpine Ridge and Titan Ridge
3781 * connected to the type-C port. Call only after PCIe tunnel has been
3783 * so can be called several times for the same router.
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()
3823 * tb_switch_xhci_disconnect() - Disconnect internal xHCI
3824 * @sw: Router whose xHCI to disconnect
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()