Lines Matching refs:tb

88 	bool (*is_supported)(struct tb *tb);
89 int (*cio_reset)(struct tb *tb);
90 int (*get_mode)(struct tb *tb);
91 int (*get_route)(struct tb *tb, u8 link, u8 depth, u64 *route);
92 void (*save_devices)(struct tb *tb);
93 int (*driver_ready)(struct tb *tb,
96 void (*set_uuid)(struct tb *tb);
97 void (*device_connected)(struct tb *tb,
99 void (*device_disconnected)(struct tb *tb,
101 void (*xdomain_connected)(struct tb *tb,
103 void (*xdomain_disconnected)(struct tb *tb,
105 void (*rtd3_veto)(struct tb *tb, const struct icm_pkg_header *hdr);
111 struct tb *tb; member
166 static inline struct tb *icm_to_tb(struct icm *icm) in icm_to_tb()
168 return ((void *)icm - sizeof(struct tb)); in icm_to_tb()
281 static int icm_request(struct tb *tb, const void *request, size_t request_size, in icm_request() argument
285 struct icm *icm = tb_priv(tb); in icm_request()
307 res = tb_cfg_request_sync(tb->ctl, req, timeout_msec); in icm_request()
326 static void icm_postpone_rescan(struct tb *tb) in icm_postpone_rescan() argument
328 struct icm *icm = tb_priv(tb); in icm_postpone_rescan()
331 mod_delayed_work(tb->wq, &icm->rescan_work, in icm_postpone_rescan()
335 static void icm_veto_begin(struct tb *tb) in icm_veto_begin() argument
337 struct icm *icm = tb_priv(tb); in icm_veto_begin()
342 pm_runtime_get(&tb->dev); in icm_veto_begin()
346 static void icm_veto_end(struct tb *tb) in icm_veto_end() argument
348 struct icm *icm = tb_priv(tb); in icm_veto_end()
353 pm_runtime_mark_last_busy(&tb->dev); in icm_veto_end()
354 pm_runtime_put_autosuspend(&tb->dev); in icm_veto_end()
366 static bool icm_fr_is_supported(struct tb *tb) in icm_fr_is_supported() argument
382 static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route) in icm_fr_get_route() argument
396 ret = icm_request(tb, &request, sizeof(request), switches, in icm_fr_get_route()
433 static void icm_fr_save_devices(struct tb *tb) in icm_fr_save_devices() argument
435 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_SAVE_DEVS, 0); in icm_fr_save_devices()
439 icm_fr_driver_ready(struct tb *tb, enum tb_security_level *security_level, in icm_fr_driver_ready() argument
449 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_driver_ready()
460 static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw) in icm_fr_approve_switch() argument
474 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_approve_switch()
480 tb_warn(tb, "PCIe tunnel creation failed\n"); in icm_fr_approve_switch()
487 static int icm_fr_add_switch_key(struct tb *tb, struct tb_switch *sw) in icm_fr_add_switch_key() argument
501 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_add_switch_key()
507 tb_warn(tb, "Adding key to switch failed\n"); in icm_fr_add_switch_key()
514 static int icm_fr_challenge_switch_key(struct tb *tb, struct tb_switch *sw, in icm_fr_challenge_switch_key() argument
529 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_challenge_switch_key()
544 static int icm_fr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_fr_approve_xdomain_paths() argument
561 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_approve_xdomain_paths()
572 static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_fr_disconnect_xdomain_paths() argument
583 nhi_mailbox_cmd(tb->nhi, cmd, 1); in icm_fr_disconnect_xdomain_paths()
585 nhi_mailbox_cmd(tb->nhi, cmd, 2); in icm_fr_disconnect_xdomain_paths()
592 struct tb *tb = parent_sw->tb; in alloc_switch() local
595 sw = tb_switch_alloc(tb, &parent_sw->dev, route); in alloc_switch()
597 tb_warn(tb, "failed to allocate switch at %llx\n", route); in alloc_switch()
669 xd = tb_xdomain_alloc(sw->tb, &sw->dev, route, local_uuid, remote_uuid); in add_xdomain()
702 icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_device_connected() argument
709 struct icm *icm = tb_priv(tb); in icm_fr_device_connected()
716 icm_postpone_rescan(tb); in icm_fr_device_connected()
729 tb_info(tb, "switch at %u.%u was rejected by ICM firmware because topology limit exceeded\n", in icm_fr_device_connected()
734 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in icm_fr_device_connected()
757 ret = icm->get_route(tb, link, depth, &route); in icm_fr_device_connected()
759 tb_err(tb, "failed to update route string for switch at %u.%u\n", in icm_fr_device_connected()
789 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_device_connected()
795 sw = tb_switch_find_by_link_depth(tb, dual_link, depth); in icm_fr_device_connected()
803 xd = tb_xdomain_find_by_link_depth(tb, link, depth); in icm_fr_device_connected()
809 parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1); in icm_fr_device_connected()
811 tb_err(tb, "failed to find parent switch for %u.%u\n", in icm_fr_device_connected()
816 ret = icm->get_route(tb, link, depth, &route); in icm_fr_device_connected()
818 tb_err(tb, "failed to find route string for switch at %u.%u\n", in icm_fr_device_connected()
850 icm_fr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_device_disconnected() argument
862 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); in icm_fr_device_disconnected()
866 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_device_disconnected()
868 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link, in icm_fr_device_disconnected()
878 icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_xdomain_connected() argument
892 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); in icm_fr_xdomain_connected()
898 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_fr_xdomain_connected()
926 xd = tb_xdomain_find_by_link_depth(tb, link, depth); in icm_fr_xdomain_connected()
932 xd = tb_xdomain_find_by_link_depth(tb, dual_link, in icm_fr_xdomain_connected()
945 sw = tb_switch_find_by_route(tb, route); in icm_fr_xdomain_connected()
951 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_xdomain_connected()
953 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link, in icm_fr_xdomain_connected()
964 icm_fr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_xdomain_disconnected() argument
975 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_fr_xdomain_disconnected()
982 static int icm_tr_cio_reset(struct tb *tb) in icm_tr_cio_reset() argument
984 return pcie2cio_write(tb_priv(tb), TB_CFG_SWITCH, 0, 0x777, BIT(1)); in icm_tr_cio_reset()
988 icm_tr_driver_ready(struct tb *tb, enum tb_security_level *security_level, in icm_tr_driver_ready() argument
998 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_driver_ready()
1014 static int icm_tr_approve_switch(struct tb *tb, struct tb_switch *sw) in icm_tr_approve_switch() argument
1028 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_approve_switch()
1034 tb_warn(tb, "PCIe tunnel creation failed\n"); in icm_tr_approve_switch()
1041 static int icm_tr_add_switch_key(struct tb *tb, struct tb_switch *sw) in icm_tr_add_switch_key() argument
1056 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_add_switch_key()
1062 tb_warn(tb, "Adding key to switch failed\n"); in icm_tr_add_switch_key()
1069 static int icm_tr_challenge_switch_key(struct tb *tb, struct tb_switch *sw, in icm_tr_challenge_switch_key() argument
1085 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_challenge_switch_key()
1100 static int icm_tr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_tr_approve_xdomain_paths() argument
1117 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_approve_xdomain_paths()
1128 static int icm_tr_xdomain_tear_down(struct tb *tb, struct tb_xdomain *xd, in icm_tr_xdomain_tear_down() argument
1143 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_xdomain_tear_down()
1154 static int icm_tr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_tr_disconnect_xdomain_paths() argument
1158 ret = icm_tr_xdomain_tear_down(tb, xd, 1); in icm_tr_disconnect_xdomain_paths()
1163 return icm_tr_xdomain_tear_down(tb, xd, 2); in icm_tr_disconnect_xdomain_paths()
1167 __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, in __icm_tr_device_connected() argument
1178 icm_postpone_rescan(tb); in __icm_tr_device_connected()
1197 tb_info(tb, "switch at %llx was rejected by ICM firmware because topology limit exceeded\n", in __icm_tr_device_connected()
1202 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in __icm_tr_device_connected()
1218 sw = tb_switch_find_by_route(tb, route); in __icm_tr_device_connected()
1225 xd = tb_xdomain_find_by_route(tb, route); in __icm_tr_device_connected()
1231 parent_sw = tb_switch_find_by_route(tb, get_parent_route(route)); in __icm_tr_device_connected()
1233 tb_err(tb, "failed to find parent switch for %llx\n", route); in __icm_tr_device_connected()
1263 icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_device_connected() argument
1265 __icm_tr_device_connected(tb, hdr, false); in icm_tr_device_connected()
1269 icm_tr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_device_disconnected() argument
1278 sw = tb_switch_find_by_route(tb, route); in icm_tr_device_disconnected()
1280 tb_warn(tb, "no switch exists at %llx, ignoring\n", route); in icm_tr_device_disconnected()
1289 icm_tr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_xdomain_connected() argument
1297 if (!tb->root_switch) in icm_tr_xdomain_connected()
1302 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_tr_xdomain_connected()
1315 xd = tb_xdomain_find_by_route(tb, route); in icm_tr_xdomain_connected()
1326 sw = tb_switch_find_by_route(tb, route); in icm_tr_xdomain_connected()
1332 sw = tb_switch_find_by_route(tb, get_parent_route(route)); in icm_tr_xdomain_connected()
1334 tb_warn(tb, "no switch exists at %llx, ignoring\n", route); in icm_tr_xdomain_connected()
1343 icm_tr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_xdomain_disconnected() argument
1352 xd = tb_xdomain_find_by_route(tb, route); in icm_tr_xdomain_disconnected()
1389 static bool icm_ar_is_supported(struct tb *tb) in icm_ar_is_supported() argument
1392 struct icm *icm = tb_priv(tb); in icm_ar_is_supported()
1399 if (icm_firmware_running(tb->nhi)) in icm_ar_is_supported()
1408 upstream_port = get_upstream_port(tb->nhi->pdev); in icm_ar_is_supported()
1425 static int icm_ar_cio_reset(struct tb *tb) in icm_ar_cio_reset() argument
1427 return pcie2cio_write(tb_priv(tb), TB_CFG_SWITCH, 0, 0x50, BIT(9)); in icm_ar_cio_reset()
1430 static int icm_ar_get_mode(struct tb *tb) in icm_ar_get_mode() argument
1432 struct tb_nhi *nhi = tb->nhi; in icm_ar_get_mode()
1452 icm_ar_driver_ready(struct tb *tb, enum tb_security_level *security_level, in icm_ar_driver_ready() argument
1462 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_driver_ready()
1478 static int icm_ar_get_route(struct tb *tb, u8 link, u8 depth, u64 *route) in icm_ar_get_route() argument
1488 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_get_route()
1500 static int icm_ar_get_boot_acl(struct tb *tb, uuid_t *uuids, size_t nuuids) in icm_ar_get_boot_acl() argument
1509 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_get_boot_acl()
1537 static int icm_ar_set_boot_acl(struct tb *tb, const uuid_t *uuids, in icm_ar_set_boot_acl() argument
1570 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_set_boot_acl()
1582 icm_icl_driver_ready(struct tb *tb, enum tb_security_level *security_level, in icm_icl_driver_ready() argument
1592 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_icl_driver_ready()
1604 static void icm_icl_set_uuid(struct tb *tb) in icm_icl_set_uuid() argument
1606 struct tb_nhi *nhi = tb->nhi; in icm_icl_set_uuid()
1614 tb->root_switch->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL); in icm_icl_set_uuid()
1618 icm_icl_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_icl_device_connected() argument
1620 __icm_tr_device_connected(tb, hdr, true); in icm_icl_device_connected()
1623 static void icm_icl_rtd3_veto(struct tb *tb, const struct icm_pkg_header *hdr) in icm_icl_rtd3_veto() argument
1628 tb_dbg(tb, "ICM rtd3 veto=0x%08x\n", pkg->veto_reason); in icm_icl_rtd3_veto()
1631 icm_veto_begin(tb); in icm_icl_rtd3_veto()
1633 icm_veto_end(tb); in icm_icl_rtd3_veto()
1636 static bool icm_tgl_is_supported(struct tb *tb) in icm_tgl_is_supported() argument
1644 val = ioread32(tb->nhi->iobase + REG_FW_STS); in icm_tgl_is_supported()
1651 struct tb *tb = n->tb; in icm_handle_notification() local
1652 struct icm *icm = tb_priv(tb); in icm_handle_notification()
1654 mutex_lock(&tb->lock); in icm_handle_notification()
1661 if (tb->root_switch) { in icm_handle_notification()
1664 icm->device_connected(tb, n->pkg); in icm_handle_notification()
1667 icm->device_disconnected(tb, n->pkg); in icm_handle_notification()
1670 icm->xdomain_connected(tb, n->pkg); in icm_handle_notification()
1673 icm->xdomain_disconnected(tb, n->pkg); in icm_handle_notification()
1676 icm->rtd3_veto(tb, n->pkg); in icm_handle_notification()
1681 mutex_unlock(&tb->lock); in icm_handle_notification()
1687 static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type, in icm_handle_event() argument
1698 n->tb = tb; in icm_handle_event()
1700 queue_work(tb->wq, &n->work); in icm_handle_event()
1704 __icm_driver_ready(struct tb *tb, enum tb_security_level *security_level, in __icm_driver_ready() argument
1707 struct icm *icm = tb_priv(tb); in __icm_driver_ready()
1711 ret = icm->driver_ready(tb, security_level, nboot_acl, rpm); in __icm_driver_ready()
1713 tb_err(tb, "failed to send driver ready to ICM\n"); in __icm_driver_ready()
1725 res = tb_cfg_read_raw(tb->ctl, &tmp, 0, 0, TB_CFG_SWITCH, in __icm_driver_ready()
1733 tb_err(tb, "failed to read root switch config space, giving up\n"); in __icm_driver_ready()
1737 static int icm_firmware_reset(struct tb *tb, struct tb_nhi *nhi) in icm_firmware_reset() argument
1739 struct icm *icm = tb_priv(tb); in icm_firmware_reset()
1757 return icm->cio_reset(tb); in icm_firmware_reset()
1760 static int icm_firmware_start(struct tb *tb, struct tb_nhi *nhi) in icm_firmware_start() argument
1772 ret = icm_firmware_reset(tb, nhi); in icm_firmware_start()
1789 static int icm_reset_phy_port(struct tb *tb, int phy_port) in icm_reset_phy_port() argument
1791 struct icm *icm = tb_priv(tb); in icm_reset_phy_port()
1857 static int icm_firmware_init(struct tb *tb) in icm_firmware_init() argument
1859 struct icm *icm = tb_priv(tb); in icm_firmware_init()
1860 struct tb_nhi *nhi = tb->nhi; in icm_firmware_init()
1863 ret = icm_firmware_start(tb, nhi); in icm_firmware_init()
1870 ret = icm->get_mode(tb); in icm_firmware_init()
1886 tb_err(tb, "ICM firmware is in wrong mode: %u\n", ret); in icm_firmware_init()
1895 ret = icm_reset_phy_port(tb, 0); in icm_firmware_init()
1898 ret = icm_reset_phy_port(tb, 1); in icm_firmware_init()
1905 static int icm_driver_ready(struct tb *tb) in icm_driver_ready() argument
1907 struct icm *icm = tb_priv(tb); in icm_driver_ready()
1910 ret = icm_firmware_init(tb); in icm_driver_ready()
1915 tb_info(tb, "Thunderbolt host controller is in safe mode.\n"); in icm_driver_ready()
1916 tb_info(tb, "You need to update NVM firmware of the controller before it can be used.\n"); in icm_driver_ready()
1917 tb_info(tb, "For latest updates check https://thunderbolttechnology.net/updates.\n"); in icm_driver_ready()
1921 ret = __icm_driver_ready(tb, &tb->security_level, &tb->nboot_acl, in icm_driver_ready()
1930 if (tb->nboot_acl > icm->max_boot_acl) in icm_driver_ready()
1931 tb->nboot_acl = 0; in icm_driver_ready()
1936 static int icm_suspend(struct tb *tb) in icm_suspend() argument
1938 struct icm *icm = tb_priv(tb); in icm_suspend()
1941 icm->save_devices(tb); in icm_suspend()
1943 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_suspend()
2020 struct tb *tb = icm_to_tb(icm); in icm_rescan_work() local
2022 mutex_lock(&tb->lock); in icm_rescan_work()
2023 if (tb->root_switch) in icm_rescan_work()
2024 icm_free_unplugged_children(tb->root_switch); in icm_rescan_work()
2025 mutex_unlock(&tb->lock); in icm_rescan_work()
2028 static void icm_complete(struct tb *tb) in icm_complete() argument
2030 struct icm *icm = tb_priv(tb); in icm_complete()
2032 if (tb->nhi->going_away) in icm_complete()
2041 icm_veto_end(tb); in icm_complete()
2042 icm_unplug_children(tb->root_switch); in icm_complete()
2048 __icm_driver_ready(tb, NULL, NULL, NULL); in icm_complete()
2055 queue_delayed_work(tb->wq, &icm->rescan_work, msecs_to_jiffies(500)); in icm_complete()
2058 static int icm_runtime_suspend(struct tb *tb) in icm_runtime_suspend() argument
2060 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_runtime_suspend()
2082 static int icm_runtime_resume(struct tb *tb) in icm_runtime_resume() argument
2088 icm_complete(tb); in icm_runtime_resume()
2092 static int icm_start(struct tb *tb) in icm_start() argument
2094 struct icm *icm = tb_priv(tb); in icm_start()
2098 tb->root_switch = tb_switch_alloc_safe_mode(tb, &tb->dev, 0); in icm_start()
2100 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); in icm_start()
2101 if (IS_ERR(tb->root_switch)) in icm_start()
2102 return PTR_ERR(tb->root_switch); in icm_start()
2104 tb->root_switch->no_nvm_upgrade = !icm->can_upgrade_nvm; in icm_start()
2105 tb->root_switch->rpm = icm->rpm; in icm_start()
2108 icm->set_uuid(tb); in icm_start()
2110 ret = tb_switch_add(tb->root_switch); in icm_start()
2112 tb_switch_put(tb->root_switch); in icm_start()
2113 tb->root_switch = NULL; in icm_start()
2119 static void icm_stop(struct tb *tb) in icm_stop() argument
2121 struct icm *icm = tb_priv(tb); in icm_stop()
2124 tb_switch_remove(tb->root_switch); in icm_stop()
2125 tb->root_switch = NULL; in icm_stop()
2126 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_stop()
2129 static int icm_disconnect_pcie_paths(struct tb *tb) in icm_disconnect_pcie_paths() argument
2131 return nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DISCONNECT_PCIE_PATHS, 0); in icm_disconnect_pcie_paths()
2207 struct tb *icm_probe(struct tb_nhi *nhi) in icm_probe()
2210 struct tb *tb; in icm_probe() local
2212 tb = tb_domain_alloc(nhi, sizeof(struct icm)); in icm_probe()
2213 if (!tb) in icm_probe()
2216 icm = tb_priv(tb); in icm_probe()
2232 tb->cm_ops = &icm_fr_ops; in icm_probe()
2258 tb->cm_ops = &icm_ar_ops; in icm_probe()
2273 tb->cm_ops = &icm_tr_ops; in icm_probe()
2286 tb->cm_ops = &icm_icl_ops; in icm_probe()
2301 tb->cm_ops = &icm_icl_ops; in icm_probe()
2313 tb->cm_ops = &icm_tr_ops; in icm_probe()
2317 if (!icm->is_supported || !icm->is_supported(tb)) { in icm_probe()
2319 tb_domain_put(tb); in icm_probe()
2323 return tb; in icm_probe()