Lines Matching refs:tb

24 #include "tb.h"
105 bool (*is_supported)(struct tb *tb);
106 int (*cio_reset)(struct tb *tb);
107 int (*get_mode)(struct tb *tb);
108 int (*get_route)(struct tb *tb, u8 link, u8 depth, u64 *route);
109 void (*save_devices)(struct tb *tb);
110 int (*driver_ready)(struct tb *tb,
113 void (*set_uuid)(struct tb *tb);
114 void (*device_connected)(struct tb *tb,
116 void (*device_disconnected)(struct tb *tb,
118 void (*xdomain_connected)(struct tb *tb,
120 void (*xdomain_disconnected)(struct tb *tb,
122 void (*rtd3_veto)(struct tb *tb, const struct icm_pkg_header *hdr);
128 struct tb *tb;
183 static inline struct tb *icm_to_tb(struct icm *icm)
185 return ((void *)icm - sizeof(struct tb));
298 static int icm_request(struct tb *tb, const void *request, size_t request_size,
302 struct icm *icm = tb_priv(tb);
323 res = tb_cfg_request_sync(tb->ctl, req, timeout_msec);
342 static void icm_postpone_rescan(struct tb *tb)
344 struct icm *icm = tb_priv(tb);
347 mod_delayed_work(tb->wq, &icm->rescan_work,
351 static void icm_veto_begin(struct tb *tb)
353 struct icm *icm = tb_priv(tb);
358 pm_runtime_get(&tb->dev);
362 static void icm_veto_end(struct tb *tb)
364 struct icm *icm = tb_priv(tb);
369 pm_runtime_mark_last_busy(&tb->dev);
370 pm_runtime_put_autosuspend(&tb->dev);
382 static bool icm_fr_is_supported(struct tb *tb)
398 static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
412 ret = icm_request(tb, &request, sizeof(request), switches,
449 static void icm_fr_save_devices(struct tb *tb)
451 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_SAVE_DEVS, 0);
455 icm_fr_driver_ready(struct tb *tb, enum tb_security_level *security_level,
465 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
476 static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw)
490 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
496 tb_warn(tb, "PCIe tunnel creation failed\n");
503 static int icm_fr_add_switch_key(struct tb *tb, struct tb_switch *sw)
517 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
523 tb_warn(tb, "Adding key to switch failed\n");
530 static int icm_fr_challenge_switch_key(struct tb *tb, struct tb_switch *sw,
545 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
560 static int icm_fr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
579 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
590 static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
603 nhi_mailbox_cmd(tb->nhi, cmd, 1);
605 nhi_mailbox_cmd(tb->nhi, cmd, 2);
612 struct tb *tb = parent_sw->tb;
615 sw = tb_switch_alloc(tb, &parent_sw->dev, route);
617 tb_warn(tb, "failed to allocate switch at %llx\n", route);
687 xd = tb_xdomain_alloc(sw->tb, &sw->dev, route, local_uuid, remote_uuid);
720 icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
727 struct icm *icm = tb_priv(tb);
734 icm_postpone_rescan(tb);
747 tb_info(tb, "switch at %u.%u was rejected by ICM firmware because topology limit exceeded\n",
752 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid);
774 ret = icm->get_route(tb, link, depth, &route);
776 tb_err(tb, "failed to update route string for switch at %u.%u\n",
806 sw = tb_switch_find_by_link_depth(tb, link, depth);
812 sw = tb_switch_find_by_link_depth(tb, dual_link, depth);
820 xd = tb_xdomain_find_by_link_depth(tb, link, depth);
826 parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1);
828 tb_err(tb, "failed to find parent switch for %u.%u\n",
833 ret = icm->get_route(tb, link, depth, &route);
835 tb_err(tb, "failed to find route string for switch at %u.%u\n",
868 icm_fr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
880 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth);
884 sw = tb_switch_find_by_link_depth(tb, link, depth);
886 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link,
902 icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
916 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth);
922 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
950 xd = tb_xdomain_find_by_link_depth(tb, link, depth);
956 xd = tb_xdomain_find_by_link_depth(tb, dual_link,
969 sw = tb_switch_find_by_route(tb, route);
975 sw = tb_switch_find_by_link_depth(tb, link, depth);
977 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link,
988 icm_fr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
999 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
1006 static int icm_tr_cio_reset(struct tb *tb)
1008 return pcie2cio_write(tb_priv(tb), TB_CFG_SWITCH, 0, 0x777, BIT(1));
1012 icm_tr_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1022 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1041 static int icm_tr_approve_switch(struct tb *tb, struct tb_switch *sw)
1055 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1061 tb_warn(tb, "PCIe tunnel creation failed\n");
1068 static int icm_tr_add_switch_key(struct tb *tb, struct tb_switch *sw)
1083 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1089 tb_warn(tb, "Adding key to switch failed\n");
1096 static int icm_tr_challenge_switch_key(struct tb *tb, struct tb_switch *sw,
1112 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1127 static int icm_tr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
1146 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1157 static int icm_tr_xdomain_tear_down(struct tb *tb, struct tb_xdomain *xd,
1172 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1183 static int icm_tr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
1189 ret = icm_tr_xdomain_tear_down(tb, xd, 1);
1194 return icm_tr_xdomain_tear_down(tb, xd, 2);
1198 __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr,
1209 icm_postpone_rescan(tb);
1228 tb_info(tb, "switch at %llx was rejected by ICM firmware because topology limit exceeded\n",
1233 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid);
1248 sw = tb_switch_find_by_route(tb, route);
1255 xd = tb_xdomain_find_by_route(tb, route);
1261 parent_sw = tb_switch_find_by_route(tb, get_parent_route(route));
1263 tb_err(tb, "failed to find parent switch for %llx\n", route);
1294 icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
1296 __icm_tr_device_connected(tb, hdr, false);
1300 icm_tr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
1309 sw = tb_switch_find_by_route(tb, route);
1311 tb_warn(tb, "no switch exists at %llx, ignoring\n", route);
1325 icm_tr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
1333 if (!tb->root_switch)
1338 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
1351 xd = tb_xdomain_find_by_route(tb, route);
1362 sw = tb_switch_find_by_route(tb, route);
1368 sw = tb_switch_find_by_route(tb, get_parent_route(route));
1370 tb_warn(tb, "no switch exists at %llx, ignoring\n", route);
1379 icm_tr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
1388 xd = tb_xdomain_find_by_route(tb, route);
1425 static bool icm_ar_is_supported(struct tb *tb)
1428 struct icm *icm = tb_priv(tb);
1435 if (icm_firmware_running(tb->nhi))
1444 upstream_port = get_upstream_port(tb->nhi->pdev);
1461 static int icm_ar_cio_reset(struct tb *tb)
1463 return pcie2cio_write(tb_priv(tb), TB_CFG_SWITCH, 0, 0x50, BIT(9));
1466 static int icm_ar_get_mode(struct tb *tb)
1468 struct tb_nhi *nhi = tb->nhi;
1488 icm_ar_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1498 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1514 static int icm_ar_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
1524 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1536 static int icm_ar_get_boot_acl(struct tb *tb, uuid_t *uuids, size_t nuuids)
1545 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1573 static int icm_ar_set_boot_acl(struct tb *tb, const uuid_t *uuids,
1606 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1618 icm_icl_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1628 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1644 static void icm_icl_set_uuid(struct tb *tb)
1646 struct tb_nhi *nhi = tb->nhi;
1654 tb->root_switch->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL);
1658 icm_icl_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
1660 __icm_tr_device_connected(tb, hdr, true);
1663 static void icm_icl_rtd3_veto(struct tb *tb, const struct icm_pkg_header *hdr)
1668 tb_dbg(tb, "ICM rtd3 veto=0x%08x\n", pkg->veto_reason);
1671 icm_veto_begin(tb);
1673 icm_veto_end(tb);
1676 static bool icm_tgl_is_supported(struct tb *tb)
1683 val = ioread32(tb->nhi->iobase + REG_FW_STS);
1695 struct tb *tb = n->tb;
1696 struct icm *icm = tb_priv(tb);
1698 mutex_lock(&tb->lock);
1705 if (tb->root_switch) {
1708 icm->device_connected(tb, n->pkg);
1711 icm->device_disconnected(tb, n->pkg);
1715 icm->xdomain_connected(tb, n->pkg);
1719 icm->xdomain_disconnected(tb, n->pkg);
1722 icm->rtd3_veto(tb, n->pkg);
1727 mutex_unlock(&tb->lock);
1733 static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type,
1749 n->tb = tb;
1751 queue_work(tb->wq, &n->work);
1755 __icm_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1758 struct icm *icm = tb_priv(tb);
1762 ret = icm->driver_ready(tb, security_level, proto_version, nboot_acl,
1765 tb_err(tb, "failed to send driver ready to ICM\n");
1777 res = tb_cfg_read_raw(tb->ctl, &tmp, 0, 0, TB_CFG_SWITCH,
1785 tb_err(tb, "failed to read root switch config space, giving up\n");
1789 static int icm_firmware_reset(struct tb *tb, struct tb_nhi *nhi)
1791 struct icm *icm = tb_priv(tb);
1809 return icm->cio_reset(tb);
1812 static int icm_firmware_start(struct tb *tb, struct tb_nhi *nhi)
1824 ret = icm_firmware_reset(tb, nhi);
1841 static int icm_reset_phy_port(struct tb *tb, int phy_port)
1843 struct icm *icm = tb_priv(tb);
1909 static int icm_firmware_init(struct tb *tb)
1911 struct icm *icm = tb_priv(tb);
1912 struct tb_nhi *nhi = tb->nhi;
1915 ret = icm_firmware_start(tb, nhi);
1922 ret = icm->get_mode(tb);
1938 tb_err(tb, "ICM firmware is in wrong mode: %u\n", ret);
1947 ret = icm_reset_phy_port(tb, 0);
1950 ret = icm_reset_phy_port(tb, 1);
1957 static int icm_driver_ready(struct tb *tb)
1959 struct icm *icm = tb_priv(tb);
1962 ret = icm_firmware_init(tb);
1967 tb_info(tb, "Thunderbolt host controller is in safe mode.\n");
1968 tb_info(tb, "You need to update NVM firmware of the controller before it can be used.\n");
1969 tb_info(tb, "For latest updates check https://thunderbolttechnology.net/updates.\n");
1973 ret = __icm_driver_ready(tb, &tb->security_level, &icm->proto_version,
1974 &tb->nboot_acl, &icm->rpm);
1982 if (tb->nboot_acl > icm->max_boot_acl)
1983 tb->nboot_acl = 0;
1986 tb_dbg(tb, "USB4 proxy operations supported\n");
1991 static int icm_suspend(struct tb *tb)
1993 struct icm *icm = tb_priv(tb);
1996 icm->save_devices(tb);
1998 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0);
2075 struct tb *tb = icm_to_tb(icm);
2077 mutex_lock(&tb->lock);
2078 if (tb->root_switch)
2079 icm_free_unplugged_children(tb->root_switch);
2080 mutex_unlock(&tb->lock);
2083 static void icm_complete(struct tb *tb)
2085 struct icm *icm = tb_priv(tb);
2087 if (tb->nhi->going_away)
2096 icm_veto_end(tb);
2097 icm_unplug_children(tb->root_switch);
2103 __icm_driver_ready(tb, NULL, NULL, NULL, NULL);
2110 queue_delayed_work(tb->wq, &icm->rescan_work, msecs_to_jiffies(500));
2113 static int icm_runtime_suspend(struct tb *tb)
2115 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0);
2137 static int icm_runtime_resume(struct tb *tb)
2143 icm_complete(tb);
2147 static int icm_start(struct tb *tb)
2149 struct icm *icm = tb_priv(tb);
2153 tb->root_switch = tb_switch_alloc_safe_mode(tb, &tb->dev, 0);
2155 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0);
2156 if (IS_ERR(tb->root_switch))
2157 return PTR_ERR(tb->root_switch);
2159 tb->root_switch->no_nvm_upgrade = !icm->can_upgrade_nvm;
2160 tb->root_switch->rpm = icm->rpm;
2163 icm->set_uuid(tb);
2165 ret = tb_switch_add(tb->root_switch);
2167 tb_switch_put(tb->root_switch);
2168 tb->root_switch = NULL;
2174 static void icm_stop(struct tb *tb)
2176 struct icm *icm = tb_priv(tb);
2179 tb_switch_remove(tb->root_switch);
2180 tb->root_switch = NULL;
2181 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0);
2186 static int icm_disconnect_pcie_paths(struct tb *tb)
2188 return nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DISCONNECT_PCIE_PATHS, 0);
2195 struct tb *tb = icm_to_tb(icm);
2197 tb_dbg(tb, "NVM_AUTH response for %llx flags %#x status %#x\n",
2201 mutex_lock(&tb->lock);
2205 mutex_unlock(&tb->lock);
2208 static int icm_usb4_switch_nvm_authenticate(struct tb *tb, u64 route)
2211 struct icm *icm = tb_priv(tb);
2241 tb_dbg(tb, "NVM_AUTH request for %llx\n", route);
2244 ret = tb_cfg_request(tb->ctl, req, icm_usb4_switch_nvm_auth_complete,
2264 struct tb *tb = sw->tb;
2265 struct icm *icm = tb_priv(tb);
2281 return icm_usb4_switch_nvm_authenticate(tb, route);
2300 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
2324 struct tb *tb = sw->tb;
2325 struct icm *icm = tb_priv(tb);
2336 tb_dbg(tb, "NVM_AUTH found for %llx flags %#x status %#x\n",
2429 struct tb *icm_probe(struct tb_nhi *nhi)
2432 struct tb *tb;
2434 tb = tb_domain_alloc(nhi, ICM_TIMEOUT, sizeof(struct icm));
2435 if (!tb)
2438 icm = tb_priv(tb);
2454 tb->cm_ops = &icm_fr_ops;
2480 tb->cm_ops = &icm_ar_ops;
2495 tb->cm_ops = &icm_tr_ops;
2508 tb->cm_ops = &icm_icl_ops;
2530 tb->cm_ops = &icm_icl_ops;
2542 tb->cm_ops = &icm_tr_ops;
2546 if (!icm->is_supported || !icm->is_supported(tb)) {
2548 tb_domain_put(tb);
2552 tb_dbg(tb, "using firmware connection manager\n");
2554 return tb;