Lines Matching +full:check +full:- +full:system +full:- +full:alpine
1 // SPDX-License-Identifier: GPL-2.0
4 * the Thunderbolt host controller performing most of the low-level
53 * struct usb4_switch_nvm_auth - Holds USB4 NVM_AUTH status
65 * struct icm - Internal connection manager private data
158 if (!ep->len) in parse_intel_vss()
160 if (ep_name + ep->len > end) in parse_intel_vss()
163 if (ep->type == EP_NAME_INTEL_VSS) in parse_intel_vss()
164 return (const struct intel_vss *)ep->data; in parse_intel_vss()
166 ep_name += ep->len; in parse_intel_vss()
178 return !!(vss->flags & INTEL_VSS_FLAGS_RTD3); in intel_vss_is_rtd3()
185 return ((void *)icm - sizeof(struct tb)); in icm_to_tb()
192 link = depth ? route >> ((depth - 1) * 8) : route; in phy_port_from_route()
198 return link ? ((link - 1) ^ 0x01) + 1 : 0; in dual_link_from_link()
209 return depth ? route & ~(0xffULL << (depth - 1) * TB_ROUTE_SHIFT) : 0; in get_parent_route()
218 pci_read_config_dword(icm->upstream_port, in pci2cio_wait_completion()
219 icm->vnd_cap + PCIE2CIO_CMD, &cmd); in pci2cio_wait_completion()
229 return -ETIMEDOUT; in pci2cio_wait_completion()
235 struct pci_dev *pdev = icm->upstream_port; in pcie2cio_read()
236 int ret, vnd_cap = icm->vnd_cap; in pcie2cio_read()
256 struct pci_dev *pdev = icm->upstream_port; in pcie2cio_write()
257 int vnd_cap = icm->vnd_cap; in pcie2cio_write()
274 const struct icm_pkg_header *res_hdr = pkg->buffer; in icm_match()
275 const struct icm_pkg_header *req_hdr = req->request; in icm_match()
277 if (pkg->frame.eof != req->response_type) in icm_match()
279 if (res_hdr->code != req_hdr->code) in icm_match()
287 const struct icm_pkg_header *hdr = pkg->buffer; in icm_copy()
289 if (hdr->packet_id < req->npackets) { in icm_copy()
290 size_t offset = hdr->packet_id * req->response_size; in icm_copy()
292 memcpy(req->response + offset, pkg->buffer, req->response_size); in icm_copy()
295 return hdr->packet_id == hdr->total_packets - 1; in icm_copy()
310 return -ENOMEM; in icm_request()
312 req->match = icm_match; in icm_request()
313 req->copy = icm_copy; in icm_request()
314 req->request = request; in icm_request()
315 req->request_size = request_size; in icm_request()
316 req->request_type = TB_CFG_PKG_ICM_CMD; in icm_request()
317 req->response = response; in icm_request()
318 req->npackets = npackets; in icm_request()
319 req->response_size = response_size; in icm_request()
320 req->response_type = TB_CFG_PKG_ICM_RESP; in icm_request()
322 mutex_lock(&icm->request_lock); in icm_request()
323 res = tb_cfg_request_sync(tb->ctl, req, timeout_msec); in icm_request()
324 mutex_unlock(&icm->request_lock); in icm_request()
328 if (res.err != -ETIMEDOUT) in icm_request()
329 return res.err == 1 ? -EIO : res.err; in icm_request()
332 } while (retries--); in icm_request()
334 return -ETIMEDOUT; in icm_request()
346 if (delayed_work_pending(&icm->rescan_work)) in icm_postpone_rescan()
347 mod_delayed_work(tb->wq, &icm->rescan_work, in icm_postpone_rescan()
355 if (!icm->veto) { in icm_veto_begin()
356 icm->veto = true; in icm_veto_begin()
358 pm_runtime_get(&tb->dev); in icm_veto_begin()
366 if (icm->veto) { in icm_veto_end()
367 icm->veto = false; in icm_veto_end()
369 pm_runtime_mark_last_busy(&tb->dev); in icm_veto_end()
370 pm_runtime_put_autosuspend(&tb->dev); in icm_veto_end()
378 val = ioread32(nhi->iobase + REG_FW_STS); in icm_firmware_running()
410 return -ENOMEM; in icm_fr_get_route()
418 index = icm_fr_get_switch_index(sw->ports[link]); in icm_fr_get_route()
420 ret = -ENODEV; in icm_fr_get_route()
428 if (!(sw->first_data & ICM_SWITCH_USED)) { in icm_fr_get_route()
429 ret = -ENODEV; in icm_fr_get_route()
433 for (j = 0; j < ARRAY_SIZE(sw->ports); j++) { in icm_fr_get_route()
434 index = icm_fr_get_switch_index(sw->ports[j]); in icm_fr_get_route()
435 if (index > sw->switch_index) { in icm_fr_get_route()
442 *route = get_route(sw->route_hi, sw->route_lo); in icm_fr_get_route()
451 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_SAVE_DEVS, 0); in icm_fr_save_devices()
483 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_fr_approve_switch()
485 request.connection_id = sw->connection_id; in icm_fr_approve_switch()
486 request.connection_key = sw->connection_key; in icm_fr_approve_switch()
497 return -EIO; in icm_fr_approve_switch()
510 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_fr_add_switch_key()
512 request.connection_id = sw->connection_id; in icm_fr_add_switch_key()
513 request.connection_key = sw->connection_key; in icm_fr_add_switch_key()
514 memcpy(request.key, sw->key, TB_SWITCH_KEY_SIZE); in icm_fr_add_switch_key()
524 return -EIO; in icm_fr_add_switch_key()
538 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_fr_challenge_switch_key()
540 request.connection_id = sw->connection_id; in icm_fr_challenge_switch_key()
541 request.connection_key = sw->connection_key; in icm_fr_challenge_switch_key()
551 return -EKEYREJECTED; in icm_fr_challenge_switch_key()
553 return -ENOKEY; in icm_fr_challenge_switch_key()
570 request.link_info = xd->depth << ICM_LINK_INFO_DEPTH_SHIFT | xd->link; in icm_fr_approve_xdomain_paths()
571 memcpy(&request.remote_uuid, xd->remote_uuid, sizeof(*xd->remote_uuid)); in icm_fr_approve_xdomain_paths()
585 return -EIO; in icm_fr_approve_xdomain_paths()
597 phy_port = tb_phy_port_from_link(xd->link); in icm_fr_disconnect_xdomain_paths()
603 nhi_mailbox_cmd(tb->nhi, cmd, 1); in icm_fr_disconnect_xdomain_paths()
605 nhi_mailbox_cmd(tb->nhi, cmd, 2); in icm_fr_disconnect_xdomain_paths()
612 struct tb *tb = parent_sw->tb; in alloc_switch()
615 sw = tb_switch_alloc(tb, &parent_sw->dev, route); in alloc_switch()
621 sw->uuid = kmemdup(uuid, sizeof(*uuid), GFP_KERNEL); in alloc_switch()
622 if (!sw->uuid) { in alloc_switch()
624 return ERR_PTR(-ENOMEM); in alloc_switch()
627 init_completion(&sw->rpm_complete); in alloc_switch()
637 tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw); in add_switch()
638 tb_upstream_port(sw)->remote = tb_port_at(route, parent_sw); in add_switch()
642 tb_port_at(tb_route(sw), parent_sw)->remote = NULL; in add_switch()
653 tb_switch_downstream_port(sw)->remote = NULL; in update_switch()
654 /* Re-connect via updated port */ in update_switch()
655 tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw); in update_switch()
658 sw->config.route_hi = upper_32_bits(route); in update_switch()
659 sw->config.route_lo = lower_32_bits(route); in update_switch()
660 sw->connection_id = connection_id; in update_switch()
661 sw->connection_key = connection_key; in update_switch()
662 sw->link = link; in update_switch()
663 sw->depth = depth; in update_switch()
664 sw->boot = boot; in update_switch()
667 sw->is_unplugged = false; in update_switch()
670 complete(&sw->rpm_complete); in update_switch()
675 tb_switch_downstream_port(sw)->remote = NULL; in remove_switch()
685 pm_runtime_get_sync(&sw->dev); in add_xdomain()
687 xd = tb_xdomain_alloc(sw->tb, &sw->dev, route, local_uuid, remote_uuid); in add_xdomain()
691 xd->link = link; in add_xdomain()
692 xd->depth = depth; in add_xdomain()
694 tb_port_at(route, sw)->xdomain = xd; in add_xdomain()
699 pm_runtime_mark_last_busy(&sw->dev); in add_xdomain()
700 pm_runtime_put_autosuspend(&sw->dev); in add_xdomain()
705 xd->link = link; in update_xdomain()
706 xd->route = route; in update_xdomain()
707 xd->is_unplugged = false; in update_xdomain()
714 sw = tb_to_switch(xd->dev.parent); in remove_xdomain()
715 tb_port_at(xd->route, sw)->xdomain = NULL; in remove_xdomain()
736 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK; in icm_fr_device_connected()
737 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> in icm_fr_device_connected()
739 authorized = pkg->link_info & ICM_LINK_INFO_APPROVED; in icm_fr_device_connected()
740 security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >> in icm_fr_device_connected()
742 boot = pkg->link_info & ICM_LINK_INFO_BOOT; in icm_fr_device_connected()
743 dual_lane = pkg->hdr.flags & ICM_FLAGS_DUAL_LANE; in icm_fr_device_connected()
744 speed_gen3 = pkg->hdr.flags & ICM_FLAGS_SPEED_GEN3; in icm_fr_device_connected()
746 if (pkg->link_info & ICM_LINK_INFO_REJECTED) { in icm_fr_device_connected()
752 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in icm_fr_device_connected()
756 sw_phy_port = tb_phy_port_from_link(sw->link); in icm_fr_device_connected()
763 * fact that a switch on a dual-link connection might in icm_fr_device_connected()
767 if (sw->depth == depth && sw_phy_port == phy_port && in icm_fr_device_connected()
768 !!sw->authorized == authorized) { in icm_fr_device_connected()
773 if (sw->link != link) { in icm_fr_device_connected()
774 ret = icm->get_route(tb, link, depth, &route); in icm_fr_device_connected()
785 update_switch(sw, route, pkg->connection_id, in icm_fr_device_connected()
786 pkg->connection_key, link, depth, boot); in icm_fr_device_connected()
826 parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1); in icm_fr_device_connected()
833 ret = icm->get_route(tb, link, depth, &route); in icm_fr_device_connected()
841 pm_runtime_get_sync(&parent_sw->dev); in icm_fr_device_connected()
843 sw = alloc_switch(parent_sw, route, &pkg->ep_uuid); in icm_fr_device_connected()
845 sw->connection_id = pkg->connection_id; in icm_fr_device_connected()
846 sw->connection_key = pkg->connection_key; in icm_fr_device_connected()
847 sw->link = link; in icm_fr_device_connected()
848 sw->depth = depth; in icm_fr_device_connected()
849 sw->authorized = authorized; in icm_fr_device_connected()
850 sw->security_level = security_level; in icm_fr_device_connected()
851 sw->boot = boot; in icm_fr_device_connected()
852 sw->link_speed = speed_gen3 ? 20 : 10; in icm_fr_device_connected()
853 sw->link_width = dual_lane ? TB_LINK_WIDTH_DUAL : in icm_fr_device_connected()
855 sw->rpm = intel_vss_is_rtd3(pkg->ep_name, sizeof(pkg->ep_name)); in icm_fr_device_connected()
861 pm_runtime_mark_last_busy(&parent_sw->dev); in icm_fr_device_connected()
862 pm_runtime_put_autosuspend(&parent_sw->dev); in icm_fr_device_connected()
875 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK; in icm_fr_device_disconnected()
876 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> in icm_fr_device_disconnected()
891 pm_runtime_get_sync(sw->dev.parent); in icm_fr_device_disconnected()
895 pm_runtime_mark_last_busy(sw->dev.parent); in icm_fr_device_disconnected()
896 pm_runtime_put_autosuspend(sw->dev.parent); in icm_fr_device_disconnected()
911 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK; in icm_fr_xdomain_connected()
912 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >> in icm_fr_xdomain_connected()
920 route = get_route(pkg->local_route_hi, pkg->local_route_lo); in icm_fr_xdomain_connected()
922 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_fr_xdomain_connected()
926 xd_phy_port = phy_port_from_route(xd->route, xd->depth); in icm_fr_xdomain_connected()
929 if (xd->depth == depth && xd_phy_port == phy_port) { in icm_fr_xdomain_connected()
938 * everything anyway to be able to re-establish the in icm_fr_xdomain_connected()
982 add_xdomain(sw, route, &pkg->local_uuid, &pkg->remote_uuid, link, in icm_fr_xdomain_connected()
999 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_fr_xdomain_disconnected()
1048 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_tr_approve_switch()
1050 request.route_lo = sw->config.route_lo; in icm_tr_approve_switch()
1051 request.route_hi = sw->config.route_hi; in icm_tr_approve_switch()
1052 request.connection_id = sw->connection_id; in icm_tr_approve_switch()
1062 return -EIO; in icm_tr_approve_switch()
1075 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_tr_add_switch_key()
1077 request.route_lo = sw->config.route_lo; in icm_tr_add_switch_key()
1078 request.route_hi = sw->config.route_hi; in icm_tr_add_switch_key()
1079 request.connection_id = sw->connection_id; in icm_tr_add_switch_key()
1080 memcpy(request.key, sw->key, TB_SWITCH_KEY_SIZE); in icm_tr_add_switch_key()
1090 return -EIO; in icm_tr_add_switch_key()
1104 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid)); in icm_tr_challenge_switch_key()
1106 request.route_lo = sw->config.route_lo; in icm_tr_challenge_switch_key()
1107 request.route_hi = sw->config.route_hi; in icm_tr_challenge_switch_key()
1108 request.connection_id = sw->connection_id; in icm_tr_challenge_switch_key()
1118 return -EKEYREJECTED; in icm_tr_challenge_switch_key()
1120 return -ENOKEY; in icm_tr_challenge_switch_key()
1137 request.route_hi = upper_32_bits(xd->route); in icm_tr_approve_xdomain_paths()
1138 request.route_lo = lower_32_bits(xd->route); in icm_tr_approve_xdomain_paths()
1143 memcpy(&request.remote_uuid, xd->remote_uuid, sizeof(*xd->remote_uuid)); in icm_tr_approve_xdomain_paths()
1152 return -EIO; in icm_tr_approve_xdomain_paths()
1167 request.route_hi = upper_32_bits(xd->route); in icm_tr_xdomain_tear_down()
1168 request.route_lo = lower_32_bits(xd->route); in icm_tr_xdomain_tear_down()
1169 memcpy(&request.remote_uuid, xd->remote_uuid, sizeof(*xd->remote_uuid)); in icm_tr_xdomain_tear_down()
1178 return -EIO; in icm_tr_xdomain_tear_down()
1216 if (pkg->hdr.packet_id) in __icm_tr_device_connected()
1219 route = get_route(pkg->route_hi, pkg->route_lo); in __icm_tr_device_connected()
1220 authorized = pkg->link_info & ICM_LINK_INFO_APPROVED; in __icm_tr_device_connected()
1221 security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >> in __icm_tr_device_connected()
1223 boot = pkg->link_info & ICM_LINK_INFO_BOOT; in __icm_tr_device_connected()
1224 dual_lane = pkg->hdr.flags & ICM_FLAGS_DUAL_LANE; in __icm_tr_device_connected()
1225 speed_gen3 = pkg->hdr.flags & ICM_FLAGS_SPEED_GEN3; in __icm_tr_device_connected()
1227 if (pkg->link_info & ICM_LINK_INFO_REJECTED) { in __icm_tr_device_connected()
1233 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid); in __icm_tr_device_connected()
1236 if (tb_route(sw) == route && !!sw->authorized == authorized) { in __icm_tr_device_connected()
1237 update_switch(sw, route, pkg->connection_id, 0, 0, 0, in __icm_tr_device_connected()
1267 pm_runtime_get_sync(&parent_sw->dev); in __icm_tr_device_connected()
1269 sw = alloc_switch(parent_sw, route, &pkg->ep_uuid); in __icm_tr_device_connected()
1271 sw->connection_id = pkg->connection_id; in __icm_tr_device_connected()
1272 sw->authorized = authorized; in __icm_tr_device_connected()
1273 sw->security_level = security_level; in __icm_tr_device_connected()
1274 sw->boot = boot; in __icm_tr_device_connected()
1275 sw->link_speed = speed_gen3 ? 20 : 10; in __icm_tr_device_connected()
1276 sw->link_width = dual_lane ? TB_LINK_WIDTH_DUAL : in __icm_tr_device_connected()
1278 sw->rpm = force_rtd3; in __icm_tr_device_connected()
1279 if (!sw->rpm) in __icm_tr_device_connected()
1280 sw->rpm = intel_vss_is_rtd3(pkg->ep_name, in __icm_tr_device_connected()
1281 sizeof(pkg->ep_name)); in __icm_tr_device_connected()
1287 pm_runtime_mark_last_busy(&parent_sw->dev); in __icm_tr_device_connected()
1288 pm_runtime_put_autosuspend(&parent_sw->dev); in __icm_tr_device_connected()
1307 route = get_route(pkg->route_hi, pkg->route_lo); in icm_tr_device_disconnected()
1314 pm_runtime_get_sync(sw->dev.parent); in icm_tr_device_disconnected()
1318 pm_runtime_mark_last_busy(sw->dev.parent); in icm_tr_device_disconnected()
1319 pm_runtime_put_autosuspend(sw->dev.parent); in icm_tr_device_disconnected()
1333 if (!tb->root_switch) in icm_tr_xdomain_connected()
1336 route = get_route(pkg->local_route_hi, pkg->local_route_lo); in icm_tr_xdomain_connected()
1338 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid); in icm_tr_xdomain_connected()
1340 if (xd->route == route) { in icm_tr_xdomain_connected()
1374 add_xdomain(sw, route, &pkg->local_uuid, &pkg->remote_uuid, 0, 0); in icm_tr_xdomain_connected()
1386 route = get_route(pkg->route_hi, pkg->route_lo); in icm_tr_xdomain_disconnected()
1411 switch (parent->device) { in get_upstream_port()
1431 * Starting from Alpine Ridge we can use ICM on Apple machines in icm_ar_is_supported()
1432 * as well. We just need to reset and re-enable it first. in icm_ar_is_supported()
1435 if (icm_firmware_running(tb->nhi)) in icm_ar_is_supported()
1444 upstream_port = get_upstream_port(tb->nhi->pdev); in icm_ar_is_supported()
1451 icm->upstream_port = upstream_port; in icm_ar_is_supported()
1452 icm->vnd_cap = cap; in icm_ar_is_supported()
1468 struct tb_nhi *nhi = tb->nhi; in icm_ar_get_mode()
1473 val = ioread32(nhi->iobase + REG_FW_STS); in icm_ar_get_mode()
1477 } while (--retries); in icm_ar_get_mode()
1480 dev_err(&nhi->pdev->dev, "ICM firmware not authenticated\n"); in icm_ar_get_mode()
1481 return -ENODEV; in icm_ar_get_mode()
1530 return -EIO; in icm_ar_get_route()
1551 return -EIO; in icm_ar_get_boot_acl()
1598 return -EINVAL; in icm_ar_set_boot_acl()
1612 return -EIO; in icm_ar_set_boot_acl()
1646 struct tb_nhi *nhi = tb->nhi; in icm_icl_set_uuid()
1649 pci_read_config_dword(nhi->pdev, VS_CAP_10, &uuid[0]); in icm_icl_set_uuid()
1650 pci_read_config_dword(nhi->pdev, VS_CAP_11, &uuid[1]); in icm_icl_set_uuid()
1654 tb->root_switch->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL); in icm_icl_set_uuid()
1668 tb_dbg(tb, "ICM rtd3 veto=0x%08x\n", pkg->veto_reason); in icm_icl_rtd3_veto()
1670 if (pkg->veto_reason) in icm_icl_rtd3_veto()
1683 val = ioread32(tb->nhi->iobase + REG_FW_STS); in icm_tgl_is_supported()
1695 struct tb *tb = n->tb; in icm_handle_notification()
1698 mutex_lock(&tb->lock); in icm_handle_notification()
1705 if (tb->root_switch) { in icm_handle_notification()
1706 switch (n->pkg->code) { in icm_handle_notification()
1708 icm->device_connected(tb, n->pkg); in icm_handle_notification()
1711 icm->device_disconnected(tb, n->pkg); in icm_handle_notification()
1715 icm->xdomain_connected(tb, n->pkg); in icm_handle_notification()
1719 icm->xdomain_disconnected(tb, n->pkg); in icm_handle_notification()
1722 icm->rtd3_veto(tb, n->pkg); in icm_handle_notification()
1727 mutex_unlock(&tb->lock); in icm_handle_notification()
1729 kfree(n->pkg); in icm_handle_notification()
1742 n->pkg = kmemdup(buf, size, GFP_KERNEL); in icm_handle_event()
1743 if (!n->pkg) { in icm_handle_event()
1748 INIT_WORK(&n->work, icm_handle_notification); in icm_handle_event()
1749 n->tb = tb; in icm_handle_event()
1751 queue_work(tb->wq, &n->work); in icm_handle_event()
1762 ret = icm->driver_ready(tb, security_level, proto_version, nboot_acl, in __icm_driver_ready()
1777 res = tb_cfg_read_raw(tb->ctl, &tmp, 0, 0, TB_CFG_SWITCH, in __icm_driver_ready()
1783 } while (--retries); in __icm_driver_ready()
1786 return -ETIMEDOUT; in __icm_driver_ready()
1794 if (!icm->upstream_port) in icm_firmware_reset()
1795 return -ENODEV; in icm_firmware_reset()
1798 val = ioread32(nhi->iobase + REG_FW_STS); in icm_firmware_reset()
1800 iowrite32(val, nhi->iobase + REG_FW_STS); in icm_firmware_reset()
1802 /* Re-start ARC */ in icm_firmware_reset()
1803 val = ioread32(nhi->iobase + REG_FW_STS); in icm_firmware_reset()
1806 iowrite32(val, nhi->iobase + REG_FW_STS); in icm_firmware_reset()
1809 return icm->cio_reset(tb); in icm_firmware_reset()
1818 /* Check if the ICM firmware is already running */ in icm_firmware_start()
1822 dev_dbg(&nhi->pdev->dev, "starting ICM firmware\n"); in icm_firmware_start()
1830 /* Check that the ICM firmware is running */ in icm_firmware_start()
1831 val = ioread32(nhi->iobase + REG_FW_STS); in icm_firmware_start()
1836 } while (--retries); in icm_firmware_start()
1838 return -ETIMEDOUT; in icm_firmware_start()
1849 if (!icm->upstream_port) in icm_reset_phy_port()
1890 /* Wait a bit and then re-enable both ports */ in icm_reset_phy_port()
1912 struct tb_nhi *nhi = tb->nhi; in icm_firmware_init()
1917 dev_err(&nhi->pdev->dev, "could not start ICM firmware\n"); in icm_firmware_init()
1921 if (icm->get_mode) { in icm_firmware_init()
1922 ret = icm->get_mode(tb); in icm_firmware_init()
1926 icm->safe_mode = true; in icm_firmware_init()
1939 return -ENODEV; in icm_firmware_init()
1949 dev_warn(&nhi->pdev->dev, "failed to reset links on port0\n"); in icm_firmware_init()
1952 dev_warn(&nhi->pdev->dev, "failed to reset links on port1\n"); in icm_firmware_init()
1966 if (icm->safe_mode) { in icm_driver_ready()
1969 tb_info(tb, "For latest updates check https://thunderbolttechnology.net/updates.\n"); in icm_driver_ready()
1973 ret = __icm_driver_ready(tb, &tb->security_level, &icm->proto_version, in icm_driver_ready()
1974 &tb->nboot_acl, &icm->rpm); in icm_driver_ready()
1982 if (tb->nboot_acl > icm->max_boot_acl) in icm_driver_ready()
1983 tb->nboot_acl = 0; in icm_driver_ready()
1985 if (icm->proto_version >= 3) in icm_driver_ready()
1995 if (icm->save_devices) in icm_suspend()
1996 icm->save_devices(tb); in icm_suspend()
1998 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_suspend()
2013 sw->is_unplugged = true; in icm_unplug_children()
2016 if (port->xdomain) in icm_unplug_children()
2017 port->xdomain->is_unplugged = true; in icm_unplug_children()
2019 icm_unplug_children(port->remote->sw); in icm_unplug_children()
2028 complete(&sw->rpm_complete); in complete_rpm()
2034 struct device *parent = get_device(sw->dev.parent); in remove_unplugged_switch()
2043 complete_rpm(&sw->dev, NULL); in remove_unplugged_switch()
2044 bus_for_each_dev(&tb_bus_type, &sw->dev, NULL, complete_rpm); in remove_unplugged_switch()
2058 if (port->xdomain && port->xdomain->is_unplugged) { in icm_free_unplugged_children()
2059 tb_xdomain_remove(port->xdomain); in icm_free_unplugged_children()
2060 port->xdomain = NULL; in icm_free_unplugged_children()
2062 if (port->remote->sw->is_unplugged) { in icm_free_unplugged_children()
2063 remove_unplugged_switch(port->remote->sw); in icm_free_unplugged_children()
2064 port->remote = NULL; in icm_free_unplugged_children()
2066 icm_free_unplugged_children(port->remote->sw); in icm_free_unplugged_children()
2077 mutex_lock(&tb->lock); in icm_rescan_work()
2078 if (tb->root_switch) in icm_rescan_work()
2079 icm_free_unplugged_children(tb->root_switch); in icm_rescan_work()
2080 mutex_unlock(&tb->lock); in icm_rescan_work()
2087 if (tb->nhi->going_away) in icm_complete()
2091 * If RTD3 was vetoed before we entered system suspend allow it in icm_complete()
2097 icm_unplug_children(tb->root_switch); in icm_complete()
2110 queue_delayed_work(tb->wq, &icm->rescan_work, msecs_to_jiffies(500)); in icm_complete()
2115 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_runtime_suspend()
2122 reinit_completion(&sw->rpm_complete); in icm_runtime_suspend_switch()
2129 if (!wait_for_completion_timeout(&sw->rpm_complete, in icm_runtime_resume_switch()
2131 dev_dbg(&sw->dev, "runtime resuming timed out\n"); in icm_runtime_resume_switch()
2140 * We can reuse the same resume functionality than with system in icm_runtime_resume()
2152 if (icm->safe_mode) in icm_start()
2153 tb->root_switch = tb_switch_alloc_safe_mode(tb, &tb->dev, 0); in icm_start()
2155 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); in icm_start()
2156 if (IS_ERR(tb->root_switch)) in icm_start()
2157 return PTR_ERR(tb->root_switch); in icm_start()
2159 tb->root_switch->no_nvm_upgrade = !icm->can_upgrade_nvm; in icm_start()
2160 tb->root_switch->rpm = icm->rpm; in icm_start()
2162 if (icm->set_uuid) in icm_start()
2163 icm->set_uuid(tb); in icm_start()
2165 ret = tb_switch_add(tb->root_switch); in icm_start()
2167 tb_switch_put(tb->root_switch); in icm_start()
2168 tb->root_switch = NULL; in icm_start()
2178 cancel_delayed_work(&icm->rescan_work); in icm_stop()
2179 tb_switch_remove(tb->root_switch); in icm_stop()
2180 tb->root_switch = NULL; in icm_stop()
2181 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0); in icm_stop()
2182 kfree(icm->last_nvm_auth); in icm_stop()
2183 icm->last_nvm_auth = NULL; in icm_stop()
2188 return nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DISCONNECT_PCIE_PATHS, 0); in icm_disconnect_pcie_paths()
2194 struct icm *icm = auth->icm; in icm_usb4_switch_nvm_auth_complete()
2198 get_route(auth->reply.route_hi, auth->reply.route_lo), in icm_usb4_switch_nvm_auth_complete()
2199 auth->reply.hdr.flags, auth->reply.status); in icm_usb4_switch_nvm_auth_complete()
2201 mutex_lock(&tb->lock); in icm_usb4_switch_nvm_auth_complete()
2202 if (WARN_ON(icm->last_nvm_auth)) in icm_usb4_switch_nvm_auth_complete()
2203 kfree(icm->last_nvm_auth); in icm_usb4_switch_nvm_auth_complete()
2204 icm->last_nvm_auth = auth; in icm_usb4_switch_nvm_auth_complete()
2205 mutex_unlock(&tb->lock); in icm_usb4_switch_nvm_auth_complete()
2217 return -ENOMEM; in icm_usb4_switch_nvm_authenticate()
2219 auth->icm = icm; in icm_usb4_switch_nvm_authenticate()
2220 auth->request.hdr.code = ICM_USB4_SWITCH_OP; in icm_usb4_switch_nvm_authenticate()
2221 auth->request.route_hi = upper_32_bits(route); in icm_usb4_switch_nvm_authenticate()
2222 auth->request.route_lo = lower_32_bits(route); in icm_usb4_switch_nvm_authenticate()
2223 auth->request.opcode = USB4_SWITCH_OP_NVM_AUTH; in icm_usb4_switch_nvm_authenticate()
2227 ret = -ENOMEM; in icm_usb4_switch_nvm_authenticate()
2231 req->match = icm_match; in icm_usb4_switch_nvm_authenticate()
2232 req->copy = icm_copy; in icm_usb4_switch_nvm_authenticate()
2233 req->request = &auth->request; in icm_usb4_switch_nvm_authenticate()
2234 req->request_size = sizeof(auth->request); in icm_usb4_switch_nvm_authenticate()
2235 req->request_type = TB_CFG_PKG_ICM_CMD; in icm_usb4_switch_nvm_authenticate()
2236 req->response = &auth->reply; in icm_usb4_switch_nvm_authenticate()
2237 req->npackets = 1; in icm_usb4_switch_nvm_authenticate()
2238 req->response_size = sizeof(auth->reply); in icm_usb4_switch_nvm_authenticate()
2239 req->response_type = TB_CFG_PKG_ICM_RESP; in icm_usb4_switch_nvm_authenticate()
2243 mutex_lock(&icm->request_lock); in icm_usb4_switch_nvm_authenticate()
2244 ret = tb_cfg_request(tb->ctl, req, icm_usb4_switch_nvm_auth_complete, in icm_usb4_switch_nvm_authenticate()
2246 mutex_unlock(&icm->request_lock); in icm_usb4_switch_nvm_authenticate()
2264 struct tb *tb = sw->tb; in icm_usb4_switch_op()
2273 if (icm->proto_version < 3) in icm_usb4_switch_op()
2274 return -EOPNOTSUPP; in icm_usb4_switch_op()
2306 return -EIO; in icm_usb4_switch_op()
2324 struct tb *tb = sw->tb; in icm_usb4_switch_nvm_authenticate_status()
2328 if (icm->proto_version < 3) in icm_usb4_switch_nvm_authenticate_status()
2329 return -EOPNOTSUPP; in icm_usb4_switch_nvm_authenticate_status()
2331 auth = icm->last_nvm_auth; in icm_usb4_switch_nvm_authenticate_status()
2332 icm->last_nvm_auth = NULL; in icm_usb4_switch_nvm_authenticate_status()
2334 if (auth && auth->reply.route_hi == sw->config.route_hi && in icm_usb4_switch_nvm_authenticate_status()
2335 auth->reply.route_lo == sw->config.route_lo) { in icm_usb4_switch_nvm_authenticate_status()
2337 tb_route(sw), auth->reply.hdr.flags, auth->reply.status); in icm_usb4_switch_nvm_authenticate_status()
2338 if (auth->reply.hdr.flags & ICM_FLAGS_ERROR) in icm_usb4_switch_nvm_authenticate_status()
2339 ret = -EIO; in icm_usb4_switch_nvm_authenticate_status()
2341 *status = auth->reply.status; in icm_usb4_switch_nvm_authenticate_status()
2366 /* Alpine Ridge */
2439 INIT_DELAYED_WORK(&icm->rescan_work, icm_rescan_work); in icm_probe()
2440 mutex_init(&icm->request_lock); in icm_probe()
2442 switch (nhi->pdev->device) { in icm_probe()
2445 icm->can_upgrade_nvm = true; in icm_probe()
2446 icm->is_supported = icm_fr_is_supported; in icm_probe()
2447 icm->get_route = icm_fr_get_route; in icm_probe()
2448 icm->save_devices = icm_fr_save_devices; in icm_probe()
2449 icm->driver_ready = icm_fr_driver_ready; in icm_probe()
2450 icm->device_connected = icm_fr_device_connected; in icm_probe()
2451 icm->device_disconnected = icm_fr_device_disconnected; in icm_probe()
2452 icm->xdomain_connected = icm_fr_xdomain_connected; in icm_probe()
2453 icm->xdomain_disconnected = icm_fr_xdomain_disconnected; in icm_probe()
2454 tb->cm_ops = &icm_fr_ops; in icm_probe()
2462 icm->max_boot_acl = ICM_AR_PREBOOT_ACL_ENTRIES; in icm_probe()
2469 icm->can_upgrade_nvm = !x86_apple_machine; in icm_probe()
2470 icm->is_supported = icm_ar_is_supported; in icm_probe()
2471 icm->cio_reset = icm_ar_cio_reset; in icm_probe()
2472 icm->get_mode = icm_ar_get_mode; in icm_probe()
2473 icm->get_route = icm_ar_get_route; in icm_probe()
2474 icm->save_devices = icm_fr_save_devices; in icm_probe()
2475 icm->driver_ready = icm_ar_driver_ready; in icm_probe()
2476 icm->device_connected = icm_fr_device_connected; in icm_probe()
2477 icm->device_disconnected = icm_fr_device_disconnected; in icm_probe()
2478 icm->xdomain_connected = icm_fr_xdomain_connected; in icm_probe()
2479 icm->xdomain_disconnected = icm_fr_xdomain_disconnected; in icm_probe()
2480 tb->cm_ops = &icm_ar_ops; in icm_probe()
2485 icm->max_boot_acl = ICM_AR_PREBOOT_ACL_ENTRIES; in icm_probe()
2486 icm->can_upgrade_nvm = !x86_apple_machine; in icm_probe()
2487 icm->is_supported = icm_ar_is_supported; in icm_probe()
2488 icm->cio_reset = icm_tr_cio_reset; in icm_probe()
2489 icm->get_mode = icm_ar_get_mode; in icm_probe()
2490 icm->driver_ready = icm_tr_driver_ready; in icm_probe()
2491 icm->device_connected = icm_tr_device_connected; in icm_probe()
2492 icm->device_disconnected = icm_tr_device_disconnected; in icm_probe()
2493 icm->xdomain_connected = icm_tr_xdomain_connected; in icm_probe()
2494 icm->xdomain_disconnected = icm_tr_xdomain_disconnected; in icm_probe()
2495 tb->cm_ops = &icm_tr_ops; in icm_probe()
2500 icm->is_supported = icm_fr_is_supported; in icm_probe()
2501 icm->driver_ready = icm_icl_driver_ready; in icm_probe()
2502 icm->set_uuid = icm_icl_set_uuid; in icm_probe()
2503 icm->device_connected = icm_icl_device_connected; in icm_probe()
2504 icm->device_disconnected = icm_tr_device_disconnected; in icm_probe()
2505 icm->xdomain_connected = icm_tr_xdomain_connected; in icm_probe()
2506 icm->xdomain_disconnected = icm_tr_xdomain_disconnected; in icm_probe()
2507 icm->rtd3_veto = icm_icl_rtd3_veto; in icm_probe()
2508 tb->cm_ops = &icm_icl_ops; in icm_probe()
2522 icm->is_supported = icm_tgl_is_supported; in icm_probe()
2523 icm->driver_ready = icm_icl_driver_ready; in icm_probe()
2524 icm->set_uuid = icm_icl_set_uuid; in icm_probe()
2525 icm->device_connected = icm_icl_device_connected; in icm_probe()
2526 icm->device_disconnected = icm_tr_device_disconnected; in icm_probe()
2527 icm->xdomain_connected = icm_tr_xdomain_connected; in icm_probe()
2528 icm->xdomain_disconnected = icm_tr_xdomain_disconnected; in icm_probe()
2529 icm->rtd3_veto = icm_icl_rtd3_veto; in icm_probe()
2530 tb->cm_ops = &icm_icl_ops; in icm_probe()
2535 icm->is_supported = icm_tgl_is_supported; in icm_probe()
2536 icm->get_mode = icm_ar_get_mode; in icm_probe()
2537 icm->driver_ready = icm_tr_driver_ready; in icm_probe()
2538 icm->device_connected = icm_tr_device_connected; in icm_probe()
2539 icm->device_disconnected = icm_tr_device_disconnected; in icm_probe()
2540 icm->xdomain_connected = icm_tr_xdomain_connected; in icm_probe()
2541 icm->xdomain_disconnected = icm_tr_xdomain_disconnected; in icm_probe()
2542 tb->cm_ops = &icm_tr_ops; in icm_probe()
2546 if (!icm->is_supported || !icm->is_supported(tb)) { in icm_probe()
2547 dev_dbg(&nhi->pdev->dev, "ICM not supported on this controller\n"); in icm_probe()