Lines Matching refs:tb
80 bool (*is_supported)(struct tb *tb);
81 int (*get_mode)(struct tb *tb);
82 int (*get_route)(struct tb *tb, u8 link, u8 depth, u64 *route);
83 void (*save_devices)(struct tb *tb);
84 int (*driver_ready)(struct tb *tb,
87 void (*device_connected)(struct tb *tb,
89 void (*device_disconnected)(struct tb *tb,
91 void (*xdomain_connected)(struct tb *tb,
93 void (*xdomain_disconnected)(struct tb *tb,
100 struct tb *tb; member
144 static inline struct tb *icm_to_tb(struct icm *icm) in icm_to_tb()
146 return ((void *)icm - sizeof(struct tb)); in icm_to_tb()
200 static int icm_request(struct tb *tb, const void *request, size_t request_size, in icm_request() argument
204 struct icm *icm = tb_priv(tb); in icm_request()
226 res = tb_cfg_request_sync(tb->ctl, req, timeout_msec); in icm_request()
240 static bool icm_fr_is_supported(struct tb *tb) in icm_fr_is_supported() argument
256 static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route) in icm_fr_get_route() argument
270 ret = icm_request(tb, &request, sizeof(request), switches, in icm_fr_get_route()
307 static void icm_fr_save_devices(struct tb *tb) in icm_fr_save_devices() argument
309 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_SAVE_DEVS, 0); in icm_fr_save_devices()
313 icm_fr_driver_ready(struct tb *tb, enum tb_security_level *security_level, in icm_fr_driver_ready() argument
323 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_driver_ready()
334 static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw) in icm_fr_approve_switch() argument
348 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_approve_switch()
354 tb_warn(tb, "PCIe tunnel creation failed\n"); in icm_fr_approve_switch()
361 static int icm_fr_add_switch_key(struct tb *tb, struct tb_switch *sw) in icm_fr_add_switch_key() argument
375 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_add_switch_key()
381 tb_warn(tb, "Adding key to switch failed\n"); in icm_fr_add_switch_key()
388 static int icm_fr_challenge_switch_key(struct tb *tb, struct tb_switch *sw, in icm_fr_challenge_switch_key() argument
403 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_challenge_switch_key()
418 static int icm_fr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_fr_approve_xdomain_paths() argument
435 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_fr_approve_xdomain_paths()
446 static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_fr_disconnect_xdomain_paths() argument
457 nhi_mailbox_cmd(tb->nhi, cmd, 1); in icm_fr_disconnect_xdomain_paths()
459 nhi_mailbox_cmd(tb->nhi, cmd, 2); in icm_fr_disconnect_xdomain_paths()
474 sw = tb_switch_alloc(parent_sw->tb, &parent_sw->dev, route); in add_switch()
544 xd = tb_xdomain_alloc(sw->tb, &sw->dev, route, local_uuid, remote_uuid); in add_xdomain()
577 icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_device_connected() argument
583 struct icm *icm = tb_priv(tb); in icm_fr_device_connected()
600 tb_info(tb, "switch at %u.%u was rejected by ICM firmware because topology limit exceeded\n", in icm_fr_device_connected()
605 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in icm_fr_device_connected()
628 ret = icm->get_route(tb, link, depth, &route); in icm_fr_device_connected()
630 tb_err(tb, "failed to update route string for switch at %u.%u\n", in icm_fr_device_connected()
660 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_device_connected()
666 sw = tb_switch_find_by_link_depth(tb, dual_link, depth); in icm_fr_device_connected()
674 xd = tb_xdomain_find_by_link_depth(tb, link, depth); in icm_fr_device_connected()
680 parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1); in icm_fr_device_connected()
682 tb_err(tb, "failed to find parent switch for %u.%u\n", in icm_fr_device_connected()
687 ret = icm->get_route(tb, link, depth, &route); in icm_fr_device_connected()
689 tb_err(tb, "failed to find route string for switch at %u.%u\n", in icm_fr_device_connected()
704 icm_fr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_device_disconnected() argument
716 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); in icm_fr_device_disconnected()
720 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_device_disconnected()
722 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link, in icm_fr_device_disconnected()
732 icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_xdomain_connected() argument
746 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth); in icm_fr_xdomain_connected()
752 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_fr_xdomain_connected()
780 xd = tb_xdomain_find_by_link_depth(tb, link, depth); in icm_fr_xdomain_connected()
786 xd = tb_xdomain_find_by_link_depth(tb, dual_link, in icm_fr_xdomain_connected()
799 sw = get_switch_at_route(tb->root_switch, route); in icm_fr_xdomain_connected()
803 sw = tb_switch_find_by_link_depth(tb, link, depth); in icm_fr_xdomain_connected()
805 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link, in icm_fr_xdomain_connected()
816 icm_fr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_fr_xdomain_disconnected() argument
827 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_fr_xdomain_disconnected()
835 icm_tr_driver_ready(struct tb *tb, enum tb_security_level *security_level, in icm_tr_driver_ready() argument
845 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_driver_ready()
861 static int icm_tr_approve_switch(struct tb *tb, struct tb_switch *sw) in icm_tr_approve_switch() argument
875 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_approve_switch()
881 tb_warn(tb, "PCIe tunnel creation failed\n"); in icm_tr_approve_switch()
888 static int icm_tr_add_switch_key(struct tb *tb, struct tb_switch *sw) in icm_tr_add_switch_key() argument
903 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_add_switch_key()
909 tb_warn(tb, "Adding key to switch failed\n"); in icm_tr_add_switch_key()
916 static int icm_tr_challenge_switch_key(struct tb *tb, struct tb_switch *sw, in icm_tr_challenge_switch_key() argument
932 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_challenge_switch_key()
947 static int icm_tr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_tr_approve_xdomain_paths() argument
964 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_approve_xdomain_paths()
975 static int icm_tr_xdomain_tear_down(struct tb *tb, struct tb_xdomain *xd, in icm_tr_xdomain_tear_down() argument
990 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_tr_xdomain_tear_down()
1001 static int icm_tr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) in icm_tr_disconnect_xdomain_paths() argument
1005 ret = icm_tr_xdomain_tear_down(tb, xd, 1); in icm_tr_disconnect_xdomain_paths()
1010 return icm_tr_xdomain_tear_down(tb, xd, 2); in icm_tr_disconnect_xdomain_paths()
1014 icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_device_connected() argument
1039 tb_info(tb, "switch at %llx was rejected by ICM firmware because topology limit exceeded\n", in icm_tr_device_connected()
1044 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in icm_tr_device_connected()
1060 sw = tb_switch_find_by_route(tb, route); in icm_tr_device_connected()
1067 xd = tb_xdomain_find_by_route(tb, route); in icm_tr_device_connected()
1073 parent_sw = tb_switch_find_by_route(tb, get_parent_route(route)); in icm_tr_device_connected()
1075 tb_err(tb, "failed to find parent switch for %llx\n", route); in icm_tr_device_connected()
1087 icm_tr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_device_disconnected() argument
1096 sw = tb_switch_find_by_route(tb, route); in icm_tr_device_disconnected()
1098 tb_warn(tb, "no switch exists at %llx, ignoring\n", route); in icm_tr_device_disconnected()
1107 icm_tr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_xdomain_connected() argument
1115 if (!tb->root_switch) in icm_tr_xdomain_connected()
1120 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_tr_xdomain_connected()
1133 xd = tb_xdomain_find_by_route(tb, route); in icm_tr_xdomain_connected()
1144 sw = get_switch_at_route(tb->root_switch, route); in icm_tr_xdomain_connected()
1148 sw = tb_switch_find_by_route(tb, get_parent_route(route)); in icm_tr_xdomain_connected()
1150 tb_warn(tb, "no switch exists at %llx, ignoring\n", route); in icm_tr_xdomain_connected()
1159 icm_tr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr) in icm_tr_xdomain_disconnected() argument
1168 xd = tb_xdomain_find_by_route(tb, route); in icm_tr_xdomain_disconnected()
1203 static bool icm_ar_is_supported(struct tb *tb) in icm_ar_is_supported() argument
1206 struct icm *icm = tb_priv(tb); in icm_ar_is_supported()
1219 upstream_port = get_upstream_port(tb->nhi->pdev); in icm_ar_is_supported()
1236 static int icm_ar_get_mode(struct tb *tb) in icm_ar_get_mode() argument
1238 struct tb_nhi *nhi = tb->nhi; in icm_ar_get_mode()
1258 icm_ar_driver_ready(struct tb *tb, enum tb_security_level *security_level, in icm_ar_driver_ready() argument
1268 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_driver_ready()
1284 static int icm_ar_get_route(struct tb *tb, u8 link, u8 depth, u64 *route) in icm_ar_get_route() argument
1294 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_get_route()
1306 static int icm_ar_get_boot_acl(struct tb *tb, uuid_t *uuids, size_t nuuids) in icm_ar_get_boot_acl() argument
1315 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_get_boot_acl()
1343 static int icm_ar_set_boot_acl(struct tb *tb, const uuid_t *uuids, in icm_ar_set_boot_acl() argument
1376 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), in icm_ar_set_boot_acl()
1390 struct tb *tb = n->tb; in icm_handle_notification() local
1391 struct icm *icm = tb_priv(tb); in icm_handle_notification()
1393 mutex_lock(&tb->lock); in icm_handle_notification()
1400 if (tb->root_switch) { in icm_handle_notification()
1403 icm->device_connected(tb, n->pkg); in icm_handle_notification()
1406 icm->device_disconnected(tb, n->pkg); in icm_handle_notification()
1409 icm->xdomain_connected(tb, n->pkg); in icm_handle_notification()
1412 icm->xdomain_disconnected(tb, n->pkg); in icm_handle_notification()
1417 mutex_unlock(&tb->lock); in icm_handle_notification()
1423 static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type, in icm_handle_event() argument
1434 n->tb = tb; in icm_handle_event()
1436 queue_work(tb->wq, &n->work); in icm_handle_event()
1440 __icm_driver_ready(struct tb *tb, enum tb_security_level *security_level, in __icm_driver_ready() argument
1443 struct icm *icm = tb_priv(tb); in __icm_driver_ready()
1447 ret = icm->driver_ready(tb, security_level, nboot_acl, rpm); in __icm_driver_ready()
1449 tb_err(tb, "failed to send driver ready to ICM\n"); in __icm_driver_ready()
1461 res = tb_cfg_read_raw(tb->ctl, &tmp, 0, 0, TB_CFG_SWITCH, in __icm_driver_ready()
1469 tb_err(tb, "failed to read root switch config space, giving up\n"); in __icm_driver_ready()
1532 static int icm_firmware_reset(struct tb *tb, struct tb_nhi *nhi) in icm_firmware_reset() argument
1534 struct icm *icm = tb_priv(tb); in icm_firmware_reset()
1555 static int icm_firmware_start(struct tb *tb, struct tb_nhi *nhi) in icm_firmware_start() argument
1568 ret = icm_firmware_reset(tb, nhi); in icm_firmware_start()
1585 static int icm_reset_phy_port(struct tb *tb, int phy_port) in icm_reset_phy_port() argument
1587 struct icm *icm = tb_priv(tb); in icm_reset_phy_port()
1653 static int icm_firmware_init(struct tb *tb) in icm_firmware_init() argument
1655 struct icm *icm = tb_priv(tb); in icm_firmware_init()
1656 struct tb_nhi *nhi = tb->nhi; in icm_firmware_init()
1659 ret = icm_firmware_start(tb, nhi); in icm_firmware_init()
1666 ret = icm->get_mode(tb); in icm_firmware_init()
1682 tb_err(tb, "ICM firmware is in wrong mode: %u\n", ret); in icm_firmware_init()
1691 ret = icm_reset_phy_port(tb, 0); in icm_firmware_init()
1694 ret = icm_reset_phy_port(tb, 1); in icm_firmware_init()
1701 static int icm_driver_ready(struct tb *tb) in icm_driver_ready() argument
1703 struct icm *icm = tb_priv(tb); in icm_driver_ready()
1706 ret = icm_firmware_init(tb); in icm_driver_ready()
1711 tb_info(tb, "Thunderbolt host controller is in safe mode.\n"); in icm_driver_ready()
1712 tb_info(tb, "You need to update NVM firmware of the controller before it can be used.\n"); in icm_driver_ready()
1713 tb_info(tb, "For latest updates check https://thunderbolttechnology.net/updates.\n"); in icm_driver_ready()
1717 ret = __icm_driver_ready(tb, &tb->security_level, &tb->nboot_acl, in icm_driver_ready()
1726 if (tb->nboot_acl > icm->max_boot_acl) in icm_driver_ready()
1727 tb->nboot_acl = 0; in icm_driver_ready()
1732 static int icm_suspend(struct tb *tb) in icm_suspend() argument
1734 struct icm *icm = tb_priv(tb); in icm_suspend()
1737 icm->save_devices(tb); in icm_suspend()
1739 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_suspend()
1803 struct tb *tb = icm_to_tb(icm); in icm_rescan_work() local
1805 mutex_lock(&tb->lock); in icm_rescan_work()
1806 if (tb->root_switch) in icm_rescan_work()
1807 icm_free_unplugged_children(tb->root_switch); in icm_rescan_work()
1808 mutex_unlock(&tb->lock); in icm_rescan_work()
1811 static void icm_complete(struct tb *tb) in icm_complete() argument
1813 struct icm *icm = tb_priv(tb); in icm_complete()
1815 if (tb->nhi->going_away) in icm_complete()
1818 icm_unplug_children(tb->root_switch); in icm_complete()
1824 __icm_driver_ready(tb, NULL, NULL, NULL); in icm_complete()
1831 queue_delayed_work(tb->wq, &icm->rescan_work, msecs_to_jiffies(500)); in icm_complete()
1834 static int icm_runtime_suspend(struct tb *tb) in icm_runtime_suspend() argument
1836 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_runtime_suspend()
1840 static int icm_runtime_resume(struct tb *tb) in icm_runtime_resume() argument
1846 icm_complete(tb); in icm_runtime_resume()
1850 static int icm_start(struct tb *tb) in icm_start() argument
1852 struct icm *icm = tb_priv(tb); in icm_start()
1856 tb->root_switch = tb_switch_alloc_safe_mode(tb, &tb->dev, 0); in icm_start()
1858 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); in icm_start()
1859 if (!tb->root_switch) in icm_start()
1867 tb->root_switch->no_nvm_upgrade = x86_apple_machine; in icm_start()
1868 tb->root_switch->rpm = icm->rpm; in icm_start()
1870 ret = tb_switch_add(tb->root_switch); in icm_start()
1872 tb_switch_put(tb->root_switch); in icm_start()
1873 tb->root_switch = NULL; in icm_start()
1879 static void icm_stop(struct tb *tb) in icm_stop() argument
1881 struct icm *icm = tb_priv(tb); in icm_stop()
1884 tb_switch_remove(tb->root_switch); in icm_stop()
1885 tb->root_switch = NULL; in icm_stop()
1886 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_stop()
1889 static int icm_disconnect_pcie_paths(struct tb *tb) in icm_disconnect_pcie_paths() argument
1891 return nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DISCONNECT_PCIE_PATHS, 0); in icm_disconnect_pcie_paths()
1950 struct tb *icm_probe(struct tb_nhi *nhi) in icm_probe()
1953 struct tb *tb; in icm_probe() local
1955 tb = tb_domain_alloc(nhi, sizeof(struct icm)); in icm_probe()
1956 if (!tb) in icm_probe()
1959 icm = tb_priv(tb); in icm_probe()
1974 tb->cm_ops = &icm_fr_ops; in icm_probe()
1992 tb->cm_ops = &icm_ar_ops; in icm_probe()
2005 tb->cm_ops = &icm_tr_ops; in icm_probe()
2009 if (!icm->is_supported || !icm->is_supported(tb)) { in icm_probe()
2011 tb_domain_put(tb); in icm_probe()
2015 return tb; in icm_probe()