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