Lines Matching +full:use +full:- +full:sw +full:- +full:pm
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)");
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()
60 *status = st ? st->status : 0; 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()
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()
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()
95 list_del(&st->list); 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()
149 if (!ret || ret == -ETIMEDOUT) 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()
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()
189 * to the new NVM to be taken into use. 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()
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()
209 } while (--retries); in nvm_authenticate_device_dma_port()
211 return -ETIMEDOUT; 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()
226 pm_runtime_get_noresume(&root_port->dev); 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()
235 pm_runtime_put(&root_port->dev); 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()
274 return -EOPNOTSUPP; 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()
289 * tb_switch_nvm_read() - Read router NVM
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()
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()
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()
409 if (!nvm->authenticating) in tb_switch_nvm_remove()
410 nvm_clear_auth_status(sw); 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
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()
820 const struct tb_switch *sw) in tb_switch_is_reachable() argument
822 u64 mask = (1ULL << parent->config.depth * 8) - 1; in tb_switch_is_reachable()
823 return (tb_route(parent) & mask) == (tb_route(sw) & mask); 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
995 * cases one should use tb_port_lane_bonding_enable() instead to enable
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()
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
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()
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()
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
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()
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
1619 * Returns %0 in case of success, %-ETIMEDOUT if the @value was not reached
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()
1641 return -ETIMEDOUT; in tb_switch_wait_for_bit()
1645 * tb_plug_events_active() - enable/disable plug events on a switch
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
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()
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
1791 return -EINVAL; in authorized_store()
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
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()
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()
1944 ret = -EOPNOTSUPP; in nvm_authenticate_sysfs()
1949 if (!sw->nvm) { in nvm_authenticate_sysfs()
1950 ret = -EAGAIN; in nvm_authenticate_sysfs()
1959 nvm_clear_auth_status(sw); in nvm_authenticate_sysfs()
1964 ret = -EINVAL; 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()
1970 ret = -EINVAL; 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()
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()
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()
2117 return attr->mode; in switch_attr_is_visible()
2123 if (tb_route(sw)) in switch_attr_is_visible()
2124 return attr->mode; in switch_attr_is_visible()
2127 if (nvm_upgradeable(sw)) in switch_attr_is_visible()
2128 return attr->mode; in switch_attr_is_visible()
2131 if (nvm_readable(sw)) in switch_attr_is_visible()
2132 return attr->mode; in switch_attr_is_visible()
2135 if (tb_route(sw)) 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()
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()
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()
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()
2185 return -ENOMEM; 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()
2196 if (!port->disabled && !tb_is_upstream_port(port) && in tb_switch_uevent()
2207 return -ENOMEM; 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()
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()
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()
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()
2245 .pm = &tb_switch_pm_ops,
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()
2306 * tb_switch_alloc() - allocate a switch
2322 struct tb_switch *sw; in tb_switch_alloc() local
2337 upstream_port = tb_cfg_get_upstream_port(tb->ctl, route); in tb_switch_alloc()
2341 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc()
2342 if (!sw) 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()
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()
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()
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()
2425 * tb_switch_alloc_safe_mode() - allocate a switch that is in safe mode
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()
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()
2460 return sw; in tb_switch_alloc_safe_mode()
2464 * tb_switch_configure() - Uploads configuration to the switch
2465 * @sw: Switch to configure
2469 * connection manager to use. Can be called to the switch again after
2470 * resume from low power states to re-initialize it.
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()
2511 return -ENODEV; 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()
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()
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()
2627 * is to unblock runtime PM of the root 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()
2661 return -ESHUTDOWN; 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()
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()
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()
2698 if (!up->dual_link_port || !up->dual_link_port->remote) 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()
2739 * tb_switch_lane_bonding_enable() - Enable lane bonding
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()
2794 * tb_switch_lane_bonding_disable() - Disable lane bonding
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()
2809 if (!up->bonded) in tb_switch_lane_bonding_disable()
2812 down = tb_port_at(tb_route(sw), parent); in tb_switch_lane_bonding_disable()
2821 if (tb_port_wait_for_link_width(down, 1, 100) == -ETIMEDOUT) 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()
2832 * tb_switch_configure_link() - Set link configured
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()
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
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()
2887 down = up->remote; 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()
2914 if (!port->cap_usb4) in tb_switch_port_hotplug_enable()
2925 * tb_switch_add() - Add a switch to the domain
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()
3051 * tb_switch_remove() - Remove and release a switch
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()
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()
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()
3095 * tb_sw_set_unplugged() - set is_unplugged on switch and downstream switches
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()
3114 else if (port->xdomain) in tb_sw_set_unplugged()
3115 port->xdomain->is_unplugged = true; 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()
3158 return -ENODEV; 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()
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()
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()
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
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()
3239 * done for USB4 device too as CLx is re-enabled at resume. 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()
3275 * tb_switch_query_dp_resource() - Query availability of DP resource
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()
3290 * tb_switch_alloc_dp_resource() - Allocate available 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()
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
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()
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()
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()
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
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()
3461 if (port->config.type == type) 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()
3523 return -EOPNOTSUPP; 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()
3549 * tb_switch_enable_clx() - Enable CLx on upstream port of specified router
3550 * @sw: Router to enable CLx for
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
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()
3573 if (root_sw->generation < 4 || tb_switch_is_tiger_lake(root_sw)) in tb_switch_enable_clx()
3579 return __tb_switch_enable_clx(sw, clx); in tb_switch_enable_clx()
3582 return -EOPNOTSUPP; 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()
3623 * tb_switch_disable_clx() - Disable CLx on upstream port of specified router
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()
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
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()
3658 /* Only Titan Ridge of pre-USB4 devices support CLx states */ 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()
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()
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()
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()
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()
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
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()
3776 * tb_switch_xhci_connect() - Connect internal xHCI
3777 * @sw: Router whose xHCI to connect
3781 * connected to the type-C port. Call only after PCIe tunnel has been
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()
3823 * tb_switch_xhci_disconnect() - Disconnect internal xHCI
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()