1 // SPDX-License-Identifier: GPL-2.0
3 * Internal Thunderbolt Connection Manager. This is a firmware running on
4 * the Thunderbolt host controller performing most of the low-level
7 * Copyright (C) 2017, Intel Corporation
8 * Authors: Michael Jamet <michael.jamet@intel.com>
9 * Mika Westerberg <mika.westerberg@linux.intel.com>
12 #include <linux/delay.h>
13 #include <linux/mutex.h>
14 #include <linux/moduleparam.h>
15 #include <linux/pci.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/platform_data/x86/apple.h>
18 #include <linux/sizes.h>
19 #include <linux/slab.h>
20 #include <linux/workqueue.h>
26 #define PCIE2CIO_CMD 0x30
27 #define PCIE2CIO_CMD_TIMEOUT BIT(31)
28 #define PCIE2CIO_CMD_START BIT(30)
29 #define PCIE2CIO_CMD_WRITE BIT(21)
30 #define PCIE2CIO_CMD_CS_MASK GENMASK(20, 19)
31 #define PCIE2CIO_CMD_CS_SHIFT 19
32 #define PCIE2CIO_CMD_PORT_MASK GENMASK(18, 13)
33 #define PCIE2CIO_CMD_PORT_SHIFT 13
35 #define PCIE2CIO_WRDATA 0x34
36 #define PCIE2CIO_RDDATA 0x38
38 #define PHY_PORT_CS1 0x37
39 #define PHY_PORT_CS1_LINK_DISABLE BIT(14)
40 #define PHY_PORT_CS1_LINK_STATE_MASK GENMASK(29, 26)
41 #define PHY_PORT_CS1_LINK_STATE_SHIFT 26
43 #define ICM_TIMEOUT 5000 /* ms */
44 #define ICM_APPROVE_TIMEOUT 10000 /* ms */
45 #define ICM_MAX_LINK 4
47 static bool start_icm;
48 module_param(start_icm, bool, 0444);
49 MODULE_PARM_DESC(start_icm, "start ICM firmware if it is not running (default: false)");
52 * struct usb4_switch_nvm_auth - Holds USB4 NVM_AUTH status
53 * @reply: Reply from ICM firmware is placed here
54 * @request: Request that is sent to ICM firmware
55 * @icm: Pointer to ICM private data
57 struct usb4_switch_nvm_auth {
58 struct icm_usb4_switch_op_response reply;
59 struct icm_usb4_switch_op request;
64 * struct icm - Internal connection manager private data
65 * @request_lock: Makes sure only one message is send to ICM at time
66 * @rescan_work: Work used to rescan the surviving switches after resume
67 * @upstream_port: Pointer to the PCIe upstream port this host
68 * controller is connected. This is only set for systems
69 * where ICM needs to be started manually
70 * @vnd_cap: Vendor defined capability where PCIe2CIO mailbox resides
71 * (only set when @upstream_port is not %NULL)
72 * @safe_mode: ICM is in safe mode
73 * @max_boot_acl: Maximum number of preboot ACL entries (%0 if not supported)
74 * @rpm: Does the controller support runtime PM (RTD3)
75 * @can_upgrade_nvm: Can the NVM firmware be upgrade on this controller
76 * @proto_version: Firmware protocol version
77 * @last_nvm_auth: Last USB4 router NVM_AUTH result (or %NULL if not set)
78 * @veto: Is RTD3 veto in effect
79 * @is_supported: Checks if we can support ICM on this controller
80 * @cio_reset: Trigger CIO reset
81 * @get_mode: Read and return the ICM firmware mode (optional)
82 * @get_route: Find a route string for given switch
83 * @save_devices: Ask ICM to save devices to ACL when suspending (optional)
84 * @driver_ready: Send driver ready message to ICM
85 * @set_uuid: Set UUID for the root switch (optional)
86 * @device_connected: Handle device connected ICM message
87 * @device_disconnected: Handle device disconnected ICM message
88 * @xdomain_connected: Handle XDomain connected ICM message
89 * @xdomain_disconnected: Handle XDomain disconnected ICM message
90 * @rtd3_veto: Handle RTD3 veto notification ICM message
93 struct mutex request_lock;
94 struct delayed_work rescan_work;
95 struct pci_dev *upstream_port;
100 bool can_upgrade_nvm;
102 struct usb4_switch_nvm_auth *last_nvm_auth;
104 bool (*is_supported)(struct tb *tb);
105 int (*cio_reset)(struct tb *tb);
106 int (*get_mode)(struct tb *tb);
107 int (*get_route)(struct tb *tb, u8 link, u8 depth, u64 *route);
108 void (*save_devices)(struct tb *tb);
109 int (*driver_ready)(struct tb *tb,
110 enum tb_security_level *security_level,
111 u8 *proto_version, size_t *nboot_acl, bool *rpm);
112 void (*set_uuid)(struct tb *tb);
113 void (*device_connected)(struct tb *tb,
114 const struct icm_pkg_header *hdr);
115 void (*device_disconnected)(struct tb *tb,
116 const struct icm_pkg_header *hdr);
117 void (*xdomain_connected)(struct tb *tb,
118 const struct icm_pkg_header *hdr);
119 void (*xdomain_disconnected)(struct tb *tb,
120 const struct icm_pkg_header *hdr);
121 void (*rtd3_veto)(struct tb *tb, const struct icm_pkg_header *hdr);
124 struct icm_notification {
125 struct work_struct work;
126 struct icm_pkg_header *pkg;
130 struct ep_name_entry {
136 #define EP_NAME_INTEL_VSS 0x10
138 /* Intel Vendor specific structure */
148 #define INTEL_VSS_FLAGS_RTD3 BIT(0)
150 static const struct intel_vss *parse_intel_vss(const void *ep_name, size_t size)
152 const void *end = ep_name + size;
154 while (ep_name < end) {
155 const struct ep_name_entry *ep = ep_name;
159 if (ep_name + ep->len > end)
162 if (ep->type == EP_NAME_INTEL_VSS)
163 return (const struct intel_vss *)ep->data;
171 static bool intel_vss_is_rtd3(const void *ep_name, size_t size)
173 const struct intel_vss *vss;
175 vss = parse_intel_vss(ep_name, size);
177 return !!(vss->flags & INTEL_VSS_FLAGS_RTD3);
182 static inline struct tb *icm_to_tb(struct icm *icm)
184 return ((void *)icm - sizeof(struct tb));
187 static inline u8 phy_port_from_route(u64 route, u8 depth)
191 link = depth ? route >> ((depth - 1) * 8) : route;
192 return tb_phy_port_from_link(link);
195 static inline u8 dual_link_from_link(u8 link)
197 return link ? ((link - 1) ^ 0x01) + 1 : 0;
200 static inline u64 get_route(u32 route_hi, u32 route_lo)
202 return (u64)route_hi << 32 | route_lo;
205 static inline u64 get_parent_route(u64 route)
207 int depth = tb_route_length(route);
208 return depth ? route & ~(0xffULL << (depth - 1) * TB_ROUTE_SHIFT) : 0;
211 static int pci2cio_wait_completion(struct icm *icm, unsigned long timeout_msec)
213 unsigned long end = jiffies + msecs_to_jiffies(timeout_msec);
217 pci_read_config_dword(icm->upstream_port,
218 icm->vnd_cap + PCIE2CIO_CMD, &cmd);
219 if (!(cmd & PCIE2CIO_CMD_START)) {
220 if (cmd & PCIE2CIO_CMD_TIMEOUT)
226 } while (time_before(jiffies, end));
231 static int pcie2cio_read(struct icm *icm, enum tb_cfg_space cs,
232 unsigned int port, unsigned int index, u32 *data)
234 struct pci_dev *pdev = icm->upstream_port;
235 int ret, vnd_cap = icm->vnd_cap;
239 cmd |= (port << PCIE2CIO_CMD_PORT_SHIFT) & PCIE2CIO_CMD_PORT_MASK;
240 cmd |= (cs << PCIE2CIO_CMD_CS_SHIFT) & PCIE2CIO_CMD_CS_MASK;
241 cmd |= PCIE2CIO_CMD_START;
242 pci_write_config_dword(pdev, vnd_cap + PCIE2CIO_CMD, cmd);
244 ret = pci2cio_wait_completion(icm, 5000);
248 pci_read_config_dword(pdev, vnd_cap + PCIE2CIO_RDDATA, data);
252 static int pcie2cio_write(struct icm *icm, enum tb_cfg_space cs,
253 unsigned int port, unsigned int index, u32 data)
255 struct pci_dev *pdev = icm->upstream_port;
256 int vnd_cap = icm->vnd_cap;
259 pci_write_config_dword(pdev, vnd_cap + PCIE2CIO_WRDATA, data);
262 cmd |= (port << PCIE2CIO_CMD_PORT_SHIFT) & PCIE2CIO_CMD_PORT_MASK;
263 cmd |= (cs << PCIE2CIO_CMD_CS_SHIFT) & PCIE2CIO_CMD_CS_MASK;
264 cmd |= PCIE2CIO_CMD_WRITE | PCIE2CIO_CMD_START;
265 pci_write_config_dword(pdev, vnd_cap + PCIE2CIO_CMD, cmd);
267 return pci2cio_wait_completion(icm, 5000);
270 static bool icm_match(const struct tb_cfg_request *req,
271 const struct ctl_pkg *pkg)
273 const struct icm_pkg_header *res_hdr = pkg->buffer;
274 const struct icm_pkg_header *req_hdr = req->request;
276 if (pkg->frame.eof != req->response_type)
278 if (res_hdr->code != req_hdr->code)
284 static bool icm_copy(struct tb_cfg_request *req, const struct ctl_pkg *pkg)
286 const struct icm_pkg_header *hdr = pkg->buffer;
288 if (hdr->packet_id < req->npackets) {
289 size_t offset = hdr->packet_id * req->response_size;
291 memcpy(req->response + offset, pkg->buffer, req->response_size);
294 return hdr->packet_id == hdr->total_packets - 1;
297 static int icm_request(struct tb *tb, const void *request, size_t request_size,
298 void *response, size_t response_size, size_t npackets,
299 unsigned int timeout_msec)
301 struct icm *icm = tb_priv(tb);
305 struct tb_cfg_request *req;
306 struct tb_cfg_result res;
308 req = tb_cfg_request_alloc();
312 req->match = icm_match;
313 req->copy = icm_copy;
314 req->request = request;
315 req->request_size = request_size;
316 req->request_type = TB_CFG_PKG_ICM_CMD;
317 req->response = response;
318 req->npackets = npackets;
319 req->response_size = response_size;
320 req->response_type = TB_CFG_PKG_ICM_RESP;
322 mutex_lock(&icm->request_lock);
323 res = tb_cfg_request_sync(tb->ctl, req, timeout_msec);
324 mutex_unlock(&icm->request_lock);
326 tb_cfg_request_put(req);
328 if (res.err != -ETIMEDOUT)
329 return res.err == 1 ? -EIO : res.err;
331 usleep_range(20, 50);
338 * If rescan is queued to run (we are resuming), postpone it to give the
339 * firmware some more time to send device connected notifications for next
340 * devices in the chain.
342 static void icm_postpone_rescan(struct tb *tb)
344 struct icm *icm = tb_priv(tb);
346 if (delayed_work_pending(&icm->rescan_work))
347 mod_delayed_work(tb->wq, &icm->rescan_work,
348 msecs_to_jiffies(500));
351 static void icm_veto_begin(struct tb *tb)
353 struct icm *icm = tb_priv(tb);
357 /* Keep the domain powered while veto is in effect */
358 pm_runtime_get(&tb->dev);
362 static void icm_veto_end(struct tb *tb)
364 struct icm *icm = tb_priv(tb);
368 /* Allow the domain suspend now */
369 pm_runtime_mark_last_busy(&tb->dev);
370 pm_runtime_put_autosuspend(&tb->dev);
374 static bool icm_firmware_running(const struct tb_nhi *nhi)
378 val = ioread32(nhi->iobase + REG_FW_STS);
379 return !!(val & REG_FW_STS_ICM_EN);
382 static bool icm_fr_is_supported(struct tb *tb)
384 return !x86_apple_machine;
387 static inline int icm_fr_get_switch_index(u32 port)
391 if ((port & ICM_PORT_TYPE_MASK) != TB_TYPE_PORT)
394 index = port >> ICM_PORT_INDEX_SHIFT;
395 return index != 0xff ? index : 0;
398 static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
400 struct icm_fr_pkg_get_topology_response *switches, *sw;
401 struct icm_fr_pkg_get_topology request = {
402 .hdr = { .code = ICM_GET_TOPOLOGY },
404 size_t npackets = ICM_GET_TOPOLOGY_PACKETS;
408 switches = kcalloc(npackets, sizeof(*switches), GFP_KERNEL);
412 ret = icm_request(tb, &request, sizeof(request), switches,
413 sizeof(*switches), npackets, ICM_TIMEOUT);
418 index = icm_fr_get_switch_index(sw->ports[link]);
424 sw = &switches[index];
425 for (i = 1; i < depth; i++) {
428 if (!(sw->first_data & ICM_SWITCH_USED)) {
433 for (j = 0; j < ARRAY_SIZE(sw->ports); j++) {
434 index = icm_fr_get_switch_index(sw->ports[j]);
435 if (index > sw->switch_index) {
436 sw = &switches[index];
442 *route = get_route(sw->route_hi, sw->route_lo);
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,
456 u8 *proto_version, size_t *nboot_acl, bool *rpm)
458 struct icm_fr_pkg_driver_ready_response reply;
459 struct icm_pkg_driver_ready request = {
460 .hdr.code = ICM_DRIVER_READY,
464 memset(&reply, 0, sizeof(reply));
465 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
471 *security_level = reply.security_level & ICM_FR_SLEVEL_MASK;
476 static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw)
478 struct icm_fr_pkg_approve_device request;
479 struct icm_fr_pkg_approve_device reply;
482 memset(&request, 0, sizeof(request));
483 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
484 request.hdr.code = ICM_APPROVE_DEVICE;
485 request.connection_id = sw->connection_id;
486 request.connection_key = sw->connection_key;
488 memset(&reply, 0, sizeof(reply));
489 /* Use larger timeout as establishing tunnels can take some time */
490 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
491 1, ICM_APPROVE_TIMEOUT);
495 if (reply.hdr.flags & ICM_FLAGS_ERROR) {
496 tb_warn(tb, "PCIe tunnel creation failed\n");
503 static int icm_fr_add_switch_key(struct tb *tb, struct tb_switch *sw)
505 struct icm_fr_pkg_add_device_key request;
506 struct icm_fr_pkg_add_device_key_response reply;
509 memset(&request, 0, sizeof(request));
510 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
511 request.hdr.code = ICM_ADD_DEVICE_KEY;
512 request.connection_id = sw->connection_id;
513 request.connection_key = sw->connection_key;
514 memcpy(request.key, sw->key, TB_SWITCH_KEY_SIZE);
516 memset(&reply, 0, sizeof(reply));
517 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
522 if (reply.hdr.flags & ICM_FLAGS_ERROR) {
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,
531 const u8 *challenge, u8 *response)
533 struct icm_fr_pkg_challenge_device request;
534 struct icm_fr_pkg_challenge_device_response reply;
537 memset(&request, 0, sizeof(request));
538 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
539 request.hdr.code = ICM_CHALLENGE_DEVICE;
540 request.connection_id = sw->connection_id;
541 request.connection_key = sw->connection_key;
542 memcpy(request.challenge, challenge, TB_SWITCH_KEY_SIZE);
544 memset(&reply, 0, sizeof(reply));
545 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
550 if (reply.hdr.flags & ICM_FLAGS_ERROR)
551 return -EKEYREJECTED;
552 if (reply.hdr.flags & ICM_FLAGS_NO_KEY)
555 memcpy(response, reply.response, TB_SWITCH_KEY_SIZE);
560 static int icm_fr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
561 int transmit_path, int transmit_ring,
562 int receive_path, int receive_ring)
564 struct icm_fr_pkg_approve_xdomain_response reply;
565 struct icm_fr_pkg_approve_xdomain request;
568 memset(&request, 0, sizeof(request));
569 request.hdr.code = ICM_APPROVE_XDOMAIN;
570 request.link_info = xd->depth << ICM_LINK_INFO_DEPTH_SHIFT | xd->link;
571 memcpy(&request.remote_uuid, xd->remote_uuid, sizeof(*xd->remote_uuid));
573 request.transmit_path = transmit_path;
574 request.transmit_ring = transmit_ring;
575 request.receive_path = receive_path;
576 request.receive_ring = receive_ring;
578 memset(&reply, 0, sizeof(reply));
579 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
584 if (reply.hdr.flags & ICM_FLAGS_ERROR)
590 static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
591 int transmit_path, int transmit_ring,
592 int receive_path, int receive_ring)
597 phy_port = tb_phy_port_from_link(xd->link);
599 cmd = NHI_MAILBOX_DISCONNECT_PA;
601 cmd = NHI_MAILBOX_DISCONNECT_PB;
603 nhi_mailbox_cmd(tb->nhi, cmd, 1);
604 usleep_range(10, 50);
605 nhi_mailbox_cmd(tb->nhi, cmd, 2);
609 static struct tb_switch *alloc_switch(struct tb_switch *parent_sw, u64 route,
612 struct tb *tb = parent_sw->tb;
613 struct tb_switch *sw;
615 sw = tb_switch_alloc(tb, &parent_sw->dev, route);
617 tb_warn(tb, "failed to allocate switch at %llx\n", route);
621 sw->uuid = kmemdup(uuid, sizeof(*uuid), GFP_KERNEL);
624 return ERR_PTR(-ENOMEM);
627 init_completion(&sw->rpm_complete);
631 static int add_switch(struct tb_switch *parent_sw, struct tb_switch *sw)
633 u64 route = tb_route(sw);
636 /* Link the two switches now */
637 tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw);
638 tb_upstream_port(sw)->remote = tb_port_at(route, parent_sw);
640 ret = tb_switch_add(sw);
642 tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
647 static void update_switch(struct tb_switch *parent_sw, struct tb_switch *sw,
648 u64 route, u8 connection_id, u8 connection_key,
649 u8 link, u8 depth, bool boot)
651 /* Disconnect from parent */
652 tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
653 /* Re-connect via updated port*/
654 tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw);
656 /* Update with the new addressing information */
657 sw->config.route_hi = upper_32_bits(route);
658 sw->config.route_lo = lower_32_bits(route);
659 sw->connection_id = connection_id;
660 sw->connection_key = connection_key;
665 /* This switch still exists */
666 sw->is_unplugged = false;
668 /* Runtime resume is now complete */
669 complete(&sw->rpm_complete);
672 static void remove_switch(struct tb_switch *sw)
674 struct tb_switch *parent_sw;
676 parent_sw = tb_to_switch(sw->dev.parent);
677 tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
678 tb_switch_remove(sw);
681 static void add_xdomain(struct tb_switch *sw, u64 route,
682 const uuid_t *local_uuid, const uuid_t *remote_uuid,
685 struct tb_xdomain *xd;
687 pm_runtime_get_sync(&sw->dev);
689 xd = tb_xdomain_alloc(sw->tb, &sw->dev, route, local_uuid, remote_uuid);
696 tb_port_at(route, sw)->xdomain = xd;
701 pm_runtime_mark_last_busy(&sw->dev);
702 pm_runtime_put_autosuspend(&sw->dev);
705 static void update_xdomain(struct tb_xdomain *xd, u64 route, u8 link)
709 xd->is_unplugged = false;
712 static void remove_xdomain(struct tb_xdomain *xd)
714 struct tb_switch *sw;
716 sw = tb_to_switch(xd->dev.parent);
717 tb_port_at(xd->route, sw)->xdomain = NULL;
718 tb_xdomain_remove(xd);
722 icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
724 const struct icm_fr_event_device_connected *pkg =
725 (const struct icm_fr_event_device_connected *)hdr;
726 enum tb_security_level security_level;
727 struct tb_switch *sw, *parent_sw;
728 bool boot, dual_lane, speed_gen3;
729 struct icm *icm = tb_priv(tb);
730 bool authorized = false;
731 struct tb_xdomain *xd;
736 icm_postpone_rescan(tb);
738 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK;
739 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
740 ICM_LINK_INFO_DEPTH_SHIFT;
741 authorized = pkg->link_info & ICM_LINK_INFO_APPROVED;
742 security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >>
743 ICM_FLAGS_SLEVEL_SHIFT;
744 boot = pkg->link_info & ICM_LINK_INFO_BOOT;
745 dual_lane = pkg->hdr.flags & ICM_FLAGS_DUAL_LANE;
746 speed_gen3 = pkg->hdr.flags & ICM_FLAGS_SPEED_GEN3;
748 if (pkg->link_info & ICM_LINK_INFO_REJECTED) {
749 tb_info(tb, "switch at %u.%u was rejected by ICM firmware because topology limit exceeded\n",
754 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid);
756 u8 phy_port, sw_phy_port;
758 parent_sw = tb_to_switch(sw->dev.parent);
759 sw_phy_port = tb_phy_port_from_link(sw->link);
760 phy_port = tb_phy_port_from_link(link);
763 * On resume ICM will send us connected events for the
764 * devices that still are present. However, that
765 * information might have changed for example by the
766 * fact that a switch on a dual-link connection might
767 * have been enumerated using the other link now. Make
768 * sure our book keeping matches that.
770 if (sw->depth == depth && sw_phy_port == phy_port &&
771 !!sw->authorized == authorized) {
773 * It was enumerated through another link so update
774 * route string accordingly.
776 if (sw->link != link) {
777 ret = icm->get_route(tb, link, depth, &route);
779 tb_err(tb, "failed to update route string for switch at %u.%u\n",
785 route = tb_route(sw);
788 update_switch(parent_sw, sw, route, pkg->connection_id,
789 pkg->connection_key, link, depth, boot);
795 * User connected the same switch to another physical
796 * port or to another part of the topology. Remove the
797 * existing switch now before adding the new one.
804 * If the switch was not found by UUID, look for a switch on
805 * same physical port (taking possible link aggregation into
806 * account) and depth. If we found one it is definitely a stale
807 * one so remove it first.
809 sw = tb_switch_find_by_link_depth(tb, link, depth);
813 dual_link = dual_link_from_link(link);
815 sw = tb_switch_find_by_link_depth(tb, dual_link, depth);
822 /* Remove existing XDomain connection if found */
823 xd = tb_xdomain_find_by_link_depth(tb, link, depth);
829 parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1);
831 tb_err(tb, "failed to find parent switch for %u.%u\n",
836 ret = icm->get_route(tb, link, depth, &route);
838 tb_err(tb, "failed to find route string for switch at %u.%u\n",
840 tb_switch_put(parent_sw);
844 pm_runtime_get_sync(&parent_sw->dev);
846 sw = alloc_switch(parent_sw, route, &pkg->ep_uuid);
848 sw->connection_id = pkg->connection_id;
849 sw->connection_key = pkg->connection_key;
852 sw->authorized = authorized;
853 sw->security_level = security_level;
855 sw->link_speed = speed_gen3 ? 20 : 10;
856 sw->link_width = dual_lane ? 2 : 1;
857 sw->rpm = intel_vss_is_rtd3(pkg->ep_name, sizeof(pkg->ep_name));
859 if (add_switch(parent_sw, sw))
863 pm_runtime_mark_last_busy(&parent_sw->dev);
864 pm_runtime_put_autosuspend(&parent_sw->dev);
866 tb_switch_put(parent_sw);
870 icm_fr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
872 const struct icm_fr_event_device_disconnected *pkg =
873 (const struct icm_fr_event_device_disconnected *)hdr;
874 struct tb_switch *sw;
877 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK;
878 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
879 ICM_LINK_INFO_DEPTH_SHIFT;
881 if (link > ICM_MAX_LINK || depth > TB_SWITCH_MAX_DEPTH) {
882 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth);
886 sw = tb_switch_find_by_link_depth(tb, link, depth);
888 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link,
893 pm_runtime_get_sync(sw->dev.parent);
897 pm_runtime_mark_last_busy(sw->dev.parent);
898 pm_runtime_put_autosuspend(sw->dev.parent);
904 icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
906 const struct icm_fr_event_xdomain_connected *pkg =
907 (const struct icm_fr_event_xdomain_connected *)hdr;
908 struct tb_xdomain *xd;
909 struct tb_switch *sw;
913 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK;
914 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
915 ICM_LINK_INFO_DEPTH_SHIFT;
917 if (link > ICM_MAX_LINK || depth > TB_SWITCH_MAX_DEPTH) {
918 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth);
922 route = get_route(pkg->local_route_hi, pkg->local_route_lo);
924 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
926 u8 xd_phy_port, phy_port;
928 xd_phy_port = phy_port_from_route(xd->route, xd->depth);
929 phy_port = phy_port_from_route(route, depth);
931 if (xd->depth == depth && xd_phy_port == phy_port) {
932 update_xdomain(xd, route, link);
938 * If we find an existing XDomain connection remove it
939 * now. We need to go through login handshake and
940 * everything anyway to be able to re-establish the
948 * Look if there already exists an XDomain in the same place
949 * than the new one and in that case remove it because it is
950 * most likely another host that got disconnected.
952 xd = tb_xdomain_find_by_link_depth(tb, link, depth);
956 dual_link = dual_link_from_link(link);
958 xd = tb_xdomain_find_by_link_depth(tb, dual_link,
967 * If the user disconnected a switch during suspend and
968 * connected another host to the same port, remove the switch
971 sw = tb_switch_find_by_route(tb, route);
977 sw = tb_switch_find_by_link_depth(tb, link, depth);
979 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link,
984 add_xdomain(sw, route, &pkg->local_uuid, &pkg->remote_uuid, link,
990 icm_fr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
992 const struct icm_fr_event_xdomain_disconnected *pkg =
993 (const struct icm_fr_event_xdomain_disconnected *)hdr;
994 struct tb_xdomain *xd;
997 * If the connection is through one or multiple devices, the
998 * XDomain device is removed along with them so it is fine if we
999 * cannot find it here.
1001 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
1008 static int icm_tr_cio_reset(struct tb *tb)
1010 return pcie2cio_write(tb_priv(tb), TB_CFG_SWITCH, 0, 0x777, BIT(1));
1014 icm_tr_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1015 u8 *proto_version, size_t *nboot_acl, bool *rpm)
1017 struct icm_tr_pkg_driver_ready_response reply;
1018 struct icm_pkg_driver_ready request = {
1019 .hdr.code = ICM_DRIVER_READY,
1023 memset(&reply, 0, sizeof(reply));
1024 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1030 *security_level = reply.info & ICM_TR_INFO_SLEVEL_MASK;
1032 *proto_version = (reply.info & ICM_TR_INFO_PROTO_VERSION_MASK) >>
1033 ICM_TR_INFO_PROTO_VERSION_SHIFT;
1035 *nboot_acl = (reply.info & ICM_TR_INFO_BOOT_ACL_MASK) >>
1036 ICM_TR_INFO_BOOT_ACL_SHIFT;
1038 *rpm = !!(reply.hdr.flags & ICM_TR_FLAGS_RTD3);
1043 static int icm_tr_approve_switch(struct tb *tb, struct tb_switch *sw)
1045 struct icm_tr_pkg_approve_device request;
1046 struct icm_tr_pkg_approve_device reply;
1049 memset(&request, 0, sizeof(request));
1050 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
1051 request.hdr.code = ICM_APPROVE_DEVICE;
1052 request.route_lo = sw->config.route_lo;
1053 request.route_hi = sw->config.route_hi;
1054 request.connection_id = sw->connection_id;
1056 memset(&reply, 0, sizeof(reply));
1057 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1058 1, ICM_APPROVE_TIMEOUT);
1062 if (reply.hdr.flags & ICM_FLAGS_ERROR) {
1063 tb_warn(tb, "PCIe tunnel creation failed\n");
1070 static int icm_tr_add_switch_key(struct tb *tb, struct tb_switch *sw)
1072 struct icm_tr_pkg_add_device_key_response reply;
1073 struct icm_tr_pkg_add_device_key request;
1076 memset(&request, 0, sizeof(request));
1077 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
1078 request.hdr.code = ICM_ADD_DEVICE_KEY;
1079 request.route_lo = sw->config.route_lo;
1080 request.route_hi = sw->config.route_hi;
1081 request.connection_id = sw->connection_id;
1082 memcpy(request.key, sw->key, TB_SWITCH_KEY_SIZE);
1084 memset(&reply, 0, sizeof(reply));
1085 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1090 if (reply.hdr.flags & ICM_FLAGS_ERROR) {
1091 tb_warn(tb, "Adding key to switch failed\n");
1098 static int icm_tr_challenge_switch_key(struct tb *tb, struct tb_switch *sw,
1099 const u8 *challenge, u8 *response)
1101 struct icm_tr_pkg_challenge_device_response reply;
1102 struct icm_tr_pkg_challenge_device request;
1105 memset(&request, 0, sizeof(request));
1106 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
1107 request.hdr.code = ICM_CHALLENGE_DEVICE;
1108 request.route_lo = sw->config.route_lo;
1109 request.route_hi = sw->config.route_hi;
1110 request.connection_id = sw->connection_id;
1111 memcpy(request.challenge, challenge, TB_SWITCH_KEY_SIZE);
1113 memset(&reply, 0, sizeof(reply));
1114 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1119 if (reply.hdr.flags & ICM_FLAGS_ERROR)
1120 return -EKEYREJECTED;
1121 if (reply.hdr.flags & ICM_FLAGS_NO_KEY)
1124 memcpy(response, reply.response, TB_SWITCH_KEY_SIZE);
1129 static int icm_tr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
1130 int transmit_path, int transmit_ring,
1131 int receive_path, int receive_ring)
1133 struct icm_tr_pkg_approve_xdomain_response reply;
1134 struct icm_tr_pkg_approve_xdomain request;
1137 memset(&request, 0, sizeof(request));
1138 request.hdr.code = ICM_APPROVE_XDOMAIN;
1139 request.route_hi = upper_32_bits(xd->route);
1140 request.route_lo = lower_32_bits(xd->route);
1141 request.transmit_path = transmit_path;
1142 request.transmit_ring = transmit_ring;
1143 request.receive_path = receive_path;
1144 request.receive_ring = receive_ring;
1145 memcpy(&request.remote_uuid, xd->remote_uuid, sizeof(*xd->remote_uuid));
1147 memset(&reply, 0, sizeof(reply));
1148 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1153 if (reply.hdr.flags & ICM_FLAGS_ERROR)
1159 static int icm_tr_xdomain_tear_down(struct tb *tb, struct tb_xdomain *xd,
1162 struct icm_tr_pkg_disconnect_xdomain_response reply;
1163 struct icm_tr_pkg_disconnect_xdomain request;
1166 memset(&request, 0, sizeof(request));
1167 request.hdr.code = ICM_DISCONNECT_XDOMAIN;
1168 request.stage = stage;
1169 request.route_hi = upper_32_bits(xd->route);
1170 request.route_lo = lower_32_bits(xd->route);
1171 memcpy(&request.remote_uuid, xd->remote_uuid, sizeof(*xd->remote_uuid));
1173 memset(&reply, 0, sizeof(reply));
1174 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1179 if (reply.hdr.flags & ICM_FLAGS_ERROR)
1185 static int icm_tr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
1186 int transmit_path, int transmit_ring,
1187 int receive_path, int receive_ring)
1191 ret = icm_tr_xdomain_tear_down(tb, xd, 1);
1195 usleep_range(10, 50);
1196 return icm_tr_xdomain_tear_down(tb, xd, 2);
1200 __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr,
1203 const struct icm_tr_event_device_connected *pkg =
1204 (const struct icm_tr_event_device_connected *)hdr;
1205 bool authorized, boot, dual_lane, speed_gen3;
1206 enum tb_security_level security_level;
1207 struct tb_switch *sw, *parent_sw;
1208 struct tb_xdomain *xd;
1211 icm_postpone_rescan(tb);
1214 * Currently we don't use the QoS information coming with the
1215 * device connected message so simply just ignore that extra
1218 if (pkg->hdr.packet_id)
1221 route = get_route(pkg->route_hi, pkg->route_lo);
1222 authorized = pkg->link_info & ICM_LINK_INFO_APPROVED;
1223 security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >>
1224 ICM_FLAGS_SLEVEL_SHIFT;
1225 boot = pkg->link_info & ICM_LINK_INFO_BOOT;
1226 dual_lane = pkg->hdr.flags & ICM_FLAGS_DUAL_LANE;
1227 speed_gen3 = pkg->hdr.flags & ICM_FLAGS_SPEED_GEN3;
1229 if (pkg->link_info & ICM_LINK_INFO_REJECTED) {
1230 tb_info(tb, "switch at %llx was rejected by ICM firmware because topology limit exceeded\n",
1235 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid);
1237 /* Update the switch if it is still in the same place */
1238 if (tb_route(sw) == route && !!sw->authorized == authorized) {
1239 parent_sw = tb_to_switch(sw->dev.parent);
1240 update_switch(parent_sw, sw, route, pkg->connection_id,
1250 /* Another switch with the same address */
1251 sw = tb_switch_find_by_route(tb, route);
1257 /* XDomain connection with the same address */
1258 xd = tb_xdomain_find_by_route(tb, route);
1264 parent_sw = tb_switch_find_by_route(tb, get_parent_route(route));
1266 tb_err(tb, "failed to find parent switch for %llx\n", route);
1270 pm_runtime_get_sync(&parent_sw->dev);
1272 sw = alloc_switch(parent_sw, route, &pkg->ep_uuid);
1274 sw->connection_id = pkg->connection_id;
1275 sw->authorized = authorized;
1276 sw->security_level = security_level;
1278 sw->link_speed = speed_gen3 ? 20 : 10;
1279 sw->link_width = dual_lane ? 2 : 1;
1280 sw->rpm = force_rtd3;
1282 sw->rpm = intel_vss_is_rtd3(pkg->ep_name,
1283 sizeof(pkg->ep_name));
1285 if (add_switch(parent_sw, sw))
1289 pm_runtime_mark_last_busy(&parent_sw->dev);
1290 pm_runtime_put_autosuspend(&parent_sw->dev);
1292 tb_switch_put(parent_sw);
1296 icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
1298 __icm_tr_device_connected(tb, hdr, false);
1302 icm_tr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
1304 const struct icm_tr_event_device_disconnected *pkg =
1305 (const struct icm_tr_event_device_disconnected *)hdr;
1306 struct tb_switch *sw;
1309 route = get_route(pkg->route_hi, pkg->route_lo);
1311 sw = tb_switch_find_by_route(tb, route);
1313 tb_warn(tb, "no switch exists at %llx, ignoring\n", route);
1316 pm_runtime_get_sync(sw->dev.parent);
1320 pm_runtime_mark_last_busy(sw->dev.parent);
1321 pm_runtime_put_autosuspend(sw->dev.parent);
1327 icm_tr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
1329 const struct icm_tr_event_xdomain_connected *pkg =
1330 (const struct icm_tr_event_xdomain_connected *)hdr;
1331 struct tb_xdomain *xd;
1332 struct tb_switch *sw;
1335 if (!tb->root_switch)
1338 route = get_route(pkg->local_route_hi, pkg->local_route_lo);
1340 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
1342 if (xd->route == route) {
1343 update_xdomain(xd, route, 0);
1352 /* An existing xdomain with the same address */
1353 xd = tb_xdomain_find_by_route(tb, route);
1360 * If the user disconnected a switch during suspend and
1361 * connected another host to the same port, remove the switch
1364 sw = tb_switch_find_by_route(tb, route);
1370 sw = tb_switch_find_by_route(tb, get_parent_route(route));
1372 tb_warn(tb, "no switch exists at %llx, ignoring\n", route);
1376 add_xdomain(sw, route, &pkg->local_uuid, &pkg->remote_uuid, 0, 0);
1381 icm_tr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
1383 const struct icm_tr_event_xdomain_disconnected *pkg =
1384 (const struct icm_tr_event_xdomain_disconnected *)hdr;
1385 struct tb_xdomain *xd;
1388 route = get_route(pkg->route_hi, pkg->route_lo);
1390 xd = tb_xdomain_find_by_route(tb, route);
1397 static struct pci_dev *get_upstream_port(struct pci_dev *pdev)
1399 struct pci_dev *parent;
1401 parent = pci_upstream_bridge(pdev);
1403 if (!pci_is_pcie(parent))
1405 if (pci_pcie_type(parent) == PCI_EXP_TYPE_UPSTREAM)
1407 parent = pci_upstream_bridge(parent);
1413 switch (parent->device) {
1414 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE:
1415 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE:
1416 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE:
1417 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE:
1418 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE:
1419 case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE:
1420 case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE:
1427 static bool icm_ar_is_supported(struct tb *tb)
1429 struct pci_dev *upstream_port;
1430 struct icm *icm = tb_priv(tb);
1433 * Starting from Alpine Ridge we can use ICM on Apple machines
1434 * as well. We just need to reset and re-enable it first.
1435 * However, only start it if explicitly asked by the user.
1437 if (icm_firmware_running(tb->nhi))
1443 * Find the upstream PCIe port in case we need to do reset
1444 * through its vendor specific registers.
1446 upstream_port = get_upstream_port(tb->nhi->pdev);
1447 if (upstream_port) {
1450 cap = pci_find_ext_capability(upstream_port,
1451 PCI_EXT_CAP_ID_VNDR);
1453 icm->upstream_port = upstream_port;
1463 static int icm_ar_cio_reset(struct tb *tb)
1465 return pcie2cio_write(tb_priv(tb), TB_CFG_SWITCH, 0, 0x50, BIT(9));
1468 static int icm_ar_get_mode(struct tb *tb)
1470 struct tb_nhi *nhi = tb->nhi;
1475 val = ioread32(nhi->iobase + REG_FW_STS);
1476 if (val & REG_FW_STS_NVM_AUTH_DONE)
1479 } while (--retries);
1482 dev_err(&nhi->pdev->dev, "ICM firmware not authenticated\n");
1486 return nhi_mailbox_mode(nhi);
1490 icm_ar_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1491 u8 *proto_version, size_t *nboot_acl, bool *rpm)
1493 struct icm_ar_pkg_driver_ready_response reply;
1494 struct icm_pkg_driver_ready request = {
1495 .hdr.code = ICM_DRIVER_READY,
1499 memset(&reply, 0, sizeof(reply));
1500 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1506 *security_level = reply.info & ICM_AR_INFO_SLEVEL_MASK;
1507 if (nboot_acl && (reply.info & ICM_AR_INFO_BOOT_ACL_SUPPORTED))
1508 *nboot_acl = (reply.info & ICM_AR_INFO_BOOT_ACL_MASK) >>
1509 ICM_AR_INFO_BOOT_ACL_SHIFT;
1511 *rpm = !!(reply.hdr.flags & ICM_AR_FLAGS_RTD3);
1516 static int icm_ar_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
1518 struct icm_ar_pkg_get_route_response reply;
1519 struct icm_ar_pkg_get_route request = {
1520 .hdr = { .code = ICM_GET_ROUTE },
1521 .link_info = depth << ICM_LINK_INFO_DEPTH_SHIFT | link,
1525 memset(&reply, 0, sizeof(reply));
1526 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1531 if (reply.hdr.flags & ICM_FLAGS_ERROR)
1534 *route = get_route(reply.route_hi, reply.route_lo);
1538 static int icm_ar_get_boot_acl(struct tb *tb, uuid_t *uuids, size_t nuuids)
1540 struct icm_ar_pkg_preboot_acl_response reply;
1541 struct icm_ar_pkg_preboot_acl request = {
1542 .hdr = { .code = ICM_PREBOOT_ACL },
1546 memset(&reply, 0, sizeof(reply));
1547 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1552 if (reply.hdr.flags & ICM_FLAGS_ERROR)
1555 for (i = 0; i < nuuids; i++) {
1556 u32 *uuid = (u32 *)&uuids[i];
1558 uuid[0] = reply.acl[i].uuid_lo;
1559 uuid[1] = reply.acl[i].uuid_hi;
1561 if (uuid[0] == 0xffffffff && uuid[1] == 0xffffffff) {
1562 /* Map empty entries to null UUID */
1565 } else if (uuid[0] != 0 || uuid[1] != 0) {
1566 /* Upper two DWs are always one's */
1567 uuid[2] = 0xffffffff;
1568 uuid[3] = 0xffffffff;
1575 static int icm_ar_set_boot_acl(struct tb *tb, const uuid_t *uuids,
1578 struct icm_ar_pkg_preboot_acl_response reply;
1579 struct icm_ar_pkg_preboot_acl request = {
1581 .code = ICM_PREBOOT_ACL,
1582 .flags = ICM_FLAGS_WRITE,
1587 for (i = 0; i < nuuids; i++) {
1588 const u32 *uuid = (const u32 *)&uuids[i];
1590 if (uuid_is_null(&uuids[i])) {
1592 * Map null UUID to the empty (all one) entries
1595 request.acl[i].uuid_lo = 0xffffffff;
1596 request.acl[i].uuid_hi = 0xffffffff;
1598 /* Two high DWs need to be set to all one */
1599 if (uuid[2] != 0xffffffff || uuid[3] != 0xffffffff)
1602 request.acl[i].uuid_lo = uuid[0];
1603 request.acl[i].uuid_hi = uuid[1];
1607 memset(&reply, 0, sizeof(reply));
1608 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1613 if (reply.hdr.flags & ICM_FLAGS_ERROR)
1620 icm_icl_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1621 u8 *proto_version, size_t *nboot_acl, bool *rpm)
1623 struct icm_tr_pkg_driver_ready_response reply;
1624 struct icm_pkg_driver_ready request = {
1625 .hdr.code = ICM_DRIVER_READY,
1629 memset(&reply, 0, sizeof(reply));
1630 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1636 *proto_version = (reply.info & ICM_TR_INFO_PROTO_VERSION_MASK) >>
1637 ICM_TR_INFO_PROTO_VERSION_SHIFT;
1639 /* Ice Lake always supports RTD3 */
1646 static void icm_icl_set_uuid(struct tb *tb)
1648 struct tb_nhi *nhi = tb->nhi;
1651 pci_read_config_dword(nhi->pdev, VS_CAP_10, &uuid[0]);
1652 pci_read_config_dword(nhi->pdev, VS_CAP_11, &uuid[1]);
1653 uuid[2] = 0xffffffff;
1654 uuid[3] = 0xffffffff;
1656 tb->root_switch->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL);
1660 icm_icl_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
1662 __icm_tr_device_connected(tb, hdr, true);
1665 static void icm_icl_rtd3_veto(struct tb *tb, const struct icm_pkg_header *hdr)
1667 const struct icm_icl_event_rtd3_veto *pkg =
1668 (const struct icm_icl_event_rtd3_veto *)hdr;
1670 tb_dbg(tb, "ICM rtd3 veto=0x%08x\n", pkg->veto_reason);
1672 if (pkg->veto_reason)
1678 static bool icm_tgl_is_supported(struct tb *tb)
1680 unsigned long end = jiffies + msecs_to_jiffies(10);
1685 val = ioread32(tb->nhi->iobase + REG_FW_STS);
1686 if (val & REG_FW_STS_NVM_AUTH_DONE)
1688 usleep_range(100, 500);
1689 } while (time_before(jiffies, end));
1694 static void icm_handle_notification(struct work_struct *work)
1696 struct icm_notification *n = container_of(work, typeof(*n), work);
1697 struct tb *tb = n->tb;
1698 struct icm *icm = tb_priv(tb);
1700 mutex_lock(&tb->lock);
1703 * When the domain is stopped we flush its workqueue but before
1704 * that the root switch is removed. In that case we should treat
1705 * the queued events as being canceled.
1707 if (tb->root_switch) {
1708 switch (n->pkg->code) {
1709 case ICM_EVENT_DEVICE_CONNECTED:
1710 icm->device_connected(tb, n->pkg);
1712 case ICM_EVENT_DEVICE_DISCONNECTED:
1713 icm->device_disconnected(tb, n->pkg);
1715 case ICM_EVENT_XDOMAIN_CONNECTED:
1716 if (tb_is_xdomain_enabled())
1717 icm->xdomain_connected(tb, n->pkg);
1719 case ICM_EVENT_XDOMAIN_DISCONNECTED:
1720 if (tb_is_xdomain_enabled())
1721 icm->xdomain_disconnected(tb, n->pkg);
1723 case ICM_EVENT_RTD3_VETO:
1724 icm->rtd3_veto(tb, n->pkg);
1729 mutex_unlock(&tb->lock);
1735 static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type,
1736 const void *buf, size_t size)
1738 struct icm_notification *n;
1740 n = kmalloc(sizeof(*n), GFP_KERNEL);
1744 INIT_WORK(&n->work, icm_handle_notification);
1745 n->pkg = kmemdup(buf, size, GFP_KERNEL);
1748 queue_work(tb->wq, &n->work);
1752 __icm_driver_ready(struct tb *tb, enum tb_security_level *security_level,
1753 u8 *proto_version, size_t *nboot_acl, bool *rpm)
1755 struct icm *icm = tb_priv(tb);
1756 unsigned int retries = 50;
1759 ret = icm->driver_ready(tb, security_level, proto_version, nboot_acl,
1762 tb_err(tb, "failed to send driver ready to ICM\n");
1767 * Hold on here until the switch config space is accessible so
1768 * that we can read root switch config successfully.
1771 struct tb_cfg_result res;
1774 res = tb_cfg_read_raw(tb->ctl, &tmp, 0, 0, TB_CFG_SWITCH,
1780 } while (--retries);
1782 tb_err(tb, "failed to read root switch config space, giving up\n");
1786 static int icm_firmware_reset(struct tb *tb, struct tb_nhi *nhi)
1788 struct icm *icm = tb_priv(tb);
1791 if (!icm->upstream_port)
1794 /* Put ARC to wait for CIO reset event to happen */
1795 val = ioread32(nhi->iobase + REG_FW_STS);
1796 val |= REG_FW_STS_CIO_RESET_REQ;
1797 iowrite32(val, nhi->iobase + REG_FW_STS);
1800 val = ioread32(nhi->iobase + REG_FW_STS);
1801 val |= REG_FW_STS_ICM_EN_INVERT;
1802 val |= REG_FW_STS_ICM_EN_CPU;
1803 iowrite32(val, nhi->iobase + REG_FW_STS);
1805 /* Trigger CIO reset now */
1806 return icm->cio_reset(tb);
1809 static int icm_firmware_start(struct tb *tb, struct tb_nhi *nhi)
1811 unsigned int retries = 10;
1815 /* Check if the ICM firmware is already running */
1816 if (icm_firmware_running(nhi))
1819 dev_dbg(&nhi->pdev->dev, "starting ICM firmware\n");
1821 ret = icm_firmware_reset(tb, nhi);
1825 /* Wait until the ICM firmware tells us it is up and running */
1827 /* Check that the ICM firmware is running */
1828 val = ioread32(nhi->iobase + REG_FW_STS);
1829 if (val & REG_FW_STS_NVM_AUTH_DONE)
1833 } while (--retries);
1838 static int icm_reset_phy_port(struct tb *tb, int phy_port)
1840 struct icm *icm = tb_priv(tb);
1846 if (!icm->upstream_port)
1858 * Read link status of both null ports belonging to a single
1861 ret = pcie2cio_read(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, &val0);
1864 ret = pcie2cio_read(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, &val1);
1868 state0 = val0 & PHY_PORT_CS1_LINK_STATE_MASK;
1869 state0 >>= PHY_PORT_CS1_LINK_STATE_SHIFT;
1870 state1 = val1 & PHY_PORT_CS1_LINK_STATE_MASK;
1871 state1 >>= PHY_PORT_CS1_LINK_STATE_SHIFT;
1873 /* If they are both up we need to reset them now */
1874 if (state0 != TB_PORT_UP || state1 != TB_PORT_UP)
1877 val0 |= PHY_PORT_CS1_LINK_DISABLE;
1878 ret = pcie2cio_write(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, val0);
1882 val1 |= PHY_PORT_CS1_LINK_DISABLE;
1883 ret = pcie2cio_write(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, val1);
1887 /* Wait a bit and then re-enable both ports */
1888 usleep_range(10, 100);
1890 ret = pcie2cio_read(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, &val0);
1893 ret = pcie2cio_read(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, &val1);
1897 val0 &= ~PHY_PORT_CS1_LINK_DISABLE;
1898 ret = pcie2cio_write(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, val0);
1902 val1 &= ~PHY_PORT_CS1_LINK_DISABLE;
1903 return pcie2cio_write(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, val1);
1906 static int icm_firmware_init(struct tb *tb)
1908 struct icm *icm = tb_priv(tb);
1909 struct tb_nhi *nhi = tb->nhi;
1912 ret = icm_firmware_start(tb, nhi);
1914 dev_err(&nhi->pdev->dev, "could not start ICM firmware\n");
1918 if (icm->get_mode) {
1919 ret = icm->get_mode(tb);
1922 case NHI_FW_SAFE_MODE:
1923 icm->safe_mode = true;
1926 case NHI_FW_CM_MODE:
1927 /* Ask ICM to accept all Thunderbolt devices */
1928 nhi_mailbox_cmd(nhi, NHI_MAILBOX_ALLOW_ALL_DEVS, 0);
1935 tb_err(tb, "ICM firmware is in wrong mode: %u\n", ret);
1941 * Reset both physical ports if there is anything connected to
1944 ret = icm_reset_phy_port(tb, 0);
1946 dev_warn(&nhi->pdev->dev, "failed to reset links on port0\n");
1947 ret = icm_reset_phy_port(tb, 1);
1949 dev_warn(&nhi->pdev->dev, "failed to reset links on port1\n");
1954 static int icm_driver_ready(struct tb *tb)
1956 struct icm *icm = tb_priv(tb);
1959 ret = icm_firmware_init(tb);
1963 if (icm->safe_mode) {
1964 tb_info(tb, "Thunderbolt host controller is in safe mode.\n");
1965 tb_info(tb, "You need to update NVM firmware of the controller before it can be used.\n");
1966 tb_info(tb, "For latest updates check https://thunderbolttechnology.net/updates.\n");
1970 ret = __icm_driver_ready(tb, &tb->security_level, &icm->proto_version,
1971 &tb->nboot_acl, &icm->rpm);
1976 * Make sure the number of supported preboot ACL matches what we
1977 * expect or disable the whole feature.
1979 if (tb->nboot_acl > icm->max_boot_acl)
1982 if (icm->proto_version >= 3)
1983 tb_dbg(tb, "USB4 proxy operations supported\n");
1988 static int icm_suspend(struct tb *tb)
1990 struct icm *icm = tb_priv(tb);
1992 if (icm->save_devices)
1993 icm->save_devices(tb);
1995 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0);
2000 * Mark all switches (except root switch) below this one unplugged. ICM
2001 * firmware will send us an updated list of switches after we have send
2002 * it driver ready command. If a switch is not in that list it will be
2003 * removed when we perform rescan.
2005 static void icm_unplug_children(struct tb_switch *sw)
2007 struct tb_port *port;
2010 sw->is_unplugged = true;
2012 tb_switch_for_each_port(sw, port) {
2014 port->xdomain->is_unplugged = true;
2015 else if (tb_port_has_remote(port))
2016 icm_unplug_children(port->remote->sw);
2020 static int complete_rpm(struct device *dev, void *data)
2022 struct tb_switch *sw = tb_to_switch(dev);
2025 complete(&sw->rpm_complete);
2029 static void remove_unplugged_switch(struct tb_switch *sw)
2031 struct device *parent = get_device(sw->dev.parent);
2033 pm_runtime_get_sync(parent);
2036 * Signal this and switches below for rpm_complete because
2037 * tb_switch_remove() calls pm_runtime_get_sync() that then waits
2040 complete_rpm(&sw->dev, NULL);
2041 bus_for_each_dev(&tb_bus_type, &sw->dev, NULL, complete_rpm);
2042 tb_switch_remove(sw);
2044 pm_runtime_mark_last_busy(parent);
2045 pm_runtime_put_autosuspend(parent);
2050 static void icm_free_unplugged_children(struct tb_switch *sw)
2052 struct tb_port *port;
2054 tb_switch_for_each_port(sw, port) {
2055 if (port->xdomain && port->xdomain->is_unplugged) {
2056 tb_xdomain_remove(port->xdomain);
2057 port->xdomain = NULL;
2058 } else if (tb_port_has_remote(port)) {
2059 if (port->remote->sw->is_unplugged) {
2060 remove_unplugged_switch(port->remote->sw);
2061 port->remote = NULL;
2063 icm_free_unplugged_children(port->remote->sw);
2069 static void icm_rescan_work(struct work_struct *work)
2071 struct icm *icm = container_of(work, struct icm, rescan_work.work);
2072 struct tb *tb = icm_to_tb(icm);
2074 mutex_lock(&tb->lock);
2075 if (tb->root_switch)
2076 icm_free_unplugged_children(tb->root_switch);
2077 mutex_unlock(&tb->lock);
2080 static void icm_complete(struct tb *tb)
2082 struct icm *icm = tb_priv(tb);
2084 if (tb->nhi->going_away)
2088 * If RTD3 was vetoed before we entered system suspend allow it
2089 * again now before driver ready is sent. Firmware sends a new RTD3
2090 * veto if it is still the case after we have sent it driver ready
2094 icm_unplug_children(tb->root_switch);
2097 * Now all existing children should be resumed, start events
2098 * from ICM to get updated status.
2100 __icm_driver_ready(tb, NULL, NULL, NULL, NULL);
2103 * We do not get notifications of devices that have been
2104 * unplugged during suspend so schedule rescan to clean them up
2107 queue_delayed_work(tb->wq, &icm->rescan_work, msecs_to_jiffies(500));
2110 static int icm_runtime_suspend(struct tb *tb)
2112 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0);
2116 static int icm_runtime_suspend_switch(struct tb_switch *sw)
2119 reinit_completion(&sw->rpm_complete);
2123 static int icm_runtime_resume_switch(struct tb_switch *sw)
2126 if (!wait_for_completion_timeout(&sw->rpm_complete,
2127 msecs_to_jiffies(500))) {
2128 dev_dbg(&sw->dev, "runtime resuming timed out\n");
2134 static int icm_runtime_resume(struct tb *tb)
2137 * We can reuse the same resume functionality than with system
2144 static int icm_start(struct tb *tb)
2146 struct icm *icm = tb_priv(tb);
2150 tb->root_switch = tb_switch_alloc_safe_mode(tb, &tb->dev, 0);
2152 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0);
2153 if (IS_ERR(tb->root_switch))
2154 return PTR_ERR(tb->root_switch);
2156 tb->root_switch->no_nvm_upgrade = !icm->can_upgrade_nvm;
2157 tb->root_switch->rpm = icm->rpm;
2162 ret = tb_switch_add(tb->root_switch);
2164 tb_switch_put(tb->root_switch);
2165 tb->root_switch = NULL;
2171 static void icm_stop(struct tb *tb)
2173 struct icm *icm = tb_priv(tb);
2175 cancel_delayed_work(&icm->rescan_work);
2176 tb_switch_remove(tb->root_switch);
2177 tb->root_switch = NULL;
2178 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0);
2179 kfree(icm->last_nvm_auth);
2180 icm->last_nvm_auth = NULL;
2183 static int icm_disconnect_pcie_paths(struct tb *tb)
2185 return nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DISCONNECT_PCIE_PATHS, 0);
2188 static void icm_usb4_switch_nvm_auth_complete(void *data)
2190 struct usb4_switch_nvm_auth *auth = data;
2191 struct icm *icm = auth->icm;
2192 struct tb *tb = icm_to_tb(icm);
2194 tb_dbg(tb, "NVM_AUTH response for %llx flags %#x status %#x\n",
2195 get_route(auth->reply.route_hi, auth->reply.route_lo),
2196 auth->reply.hdr.flags, auth->reply.status);
2198 mutex_lock(&tb->lock);
2199 if (WARN_ON(icm->last_nvm_auth))
2200 kfree(icm->last_nvm_auth);
2201 icm->last_nvm_auth = auth;
2202 mutex_unlock(&tb->lock);
2205 static int icm_usb4_switch_nvm_authenticate(struct tb *tb, u64 route)
2207 struct usb4_switch_nvm_auth *auth;
2208 struct icm *icm = tb_priv(tb);
2209 struct tb_cfg_request *req;
2212 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
2217 auth->request.hdr.code = ICM_USB4_SWITCH_OP;
2218 auth->request.route_hi = upper_32_bits(route);
2219 auth->request.route_lo = lower_32_bits(route);
2220 auth->request.opcode = USB4_SWITCH_OP_NVM_AUTH;
2222 req = tb_cfg_request_alloc();
2228 req->match = icm_match;
2229 req->copy = icm_copy;
2230 req->request = &auth->request;
2231 req->request_size = sizeof(auth->request);
2232 req->request_type = TB_CFG_PKG_ICM_CMD;
2233 req->response = &auth->reply;
2235 req->response_size = sizeof(auth->reply);
2236 req->response_type = TB_CFG_PKG_ICM_RESP;
2238 tb_dbg(tb, "NVM_AUTH request for %llx\n", route);
2240 mutex_lock(&icm->request_lock);
2241 ret = tb_cfg_request(tb->ctl, req, icm_usb4_switch_nvm_auth_complete,
2243 mutex_unlock(&icm->request_lock);
2245 tb_cfg_request_put(req);
2255 static int icm_usb4_switch_op(struct tb_switch *sw, u16 opcode, u32 *metadata,
2256 u8 *status, const void *tx_data, size_t tx_data_len,
2257 void *rx_data, size_t rx_data_len)
2259 struct icm_usb4_switch_op_response reply;
2260 struct icm_usb4_switch_op request;
2261 struct tb *tb = sw->tb;
2262 struct icm *icm = tb_priv(tb);
2263 u64 route = tb_route(sw);
2267 * USB4 router operation proxy is supported in firmware if the
2268 * protocol version is 3 or higher.
2270 if (icm->proto_version < 3)
2274 * NVM_AUTH is a special USB4 proxy operation that does not
2275 * return immediately so handle it separately.
2277 if (opcode == USB4_SWITCH_OP_NVM_AUTH)
2278 return icm_usb4_switch_nvm_authenticate(tb, route);
2280 memset(&request, 0, sizeof(request));
2281 request.hdr.code = ICM_USB4_SWITCH_OP;
2282 request.route_hi = upper_32_bits(route);
2283 request.route_lo = lower_32_bits(route);
2284 request.opcode = opcode;
2286 request.metadata = *metadata;
2289 request.data_len_valid |= ICM_USB4_SWITCH_DATA_VALID;
2290 if (tx_data_len < ARRAY_SIZE(request.data))
2291 request.data_len_valid =
2292 tx_data_len & ICM_USB4_SWITCH_DATA_LEN_MASK;
2293 memcpy(request.data, tx_data, tx_data_len * sizeof(u32));
2296 memset(&reply, 0, sizeof(reply));
2297 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
2302 if (reply.hdr.flags & ICM_FLAGS_ERROR)
2306 *status = reply.status;
2309 *metadata = reply.metadata;
2312 memcpy(rx_data, reply.data, rx_data_len * sizeof(u32));
2317 static int icm_usb4_switch_nvm_authenticate_status(struct tb_switch *sw,
2320 struct usb4_switch_nvm_auth *auth;
2321 struct tb *tb = sw->tb;
2322 struct icm *icm = tb_priv(tb);
2325 if (icm->proto_version < 3)
2328 auth = icm->last_nvm_auth;
2329 icm->last_nvm_auth = NULL;
2331 if (auth && auth->reply.route_hi == sw->config.route_hi &&
2332 auth->reply.route_lo == sw->config.route_lo) {
2333 tb_dbg(tb, "NVM_AUTH found for %llx flags %#x status %#x\n",
2334 tb_route(sw), auth->reply.hdr.flags, auth->reply.status);
2335 if (auth->reply.hdr.flags & ICM_FLAGS_ERROR)
2338 *status = auth->reply.status;
2348 static const struct tb_cm_ops icm_fr_ops = {
2349 .driver_ready = icm_driver_ready,
2352 .suspend = icm_suspend,
2353 .complete = icm_complete,
2354 .handle_event = icm_handle_event,
2355 .approve_switch = icm_fr_approve_switch,
2356 .add_switch_key = icm_fr_add_switch_key,
2357 .challenge_switch_key = icm_fr_challenge_switch_key,
2358 .disconnect_pcie_paths = icm_disconnect_pcie_paths,
2359 .approve_xdomain_paths = icm_fr_approve_xdomain_paths,
2360 .disconnect_xdomain_paths = icm_fr_disconnect_xdomain_paths,
2364 static const struct tb_cm_ops icm_ar_ops = {
2365 .driver_ready = icm_driver_ready,
2368 .suspend = icm_suspend,
2369 .complete = icm_complete,
2370 .runtime_suspend = icm_runtime_suspend,
2371 .runtime_resume = icm_runtime_resume,
2372 .runtime_suspend_switch = icm_runtime_suspend_switch,
2373 .runtime_resume_switch = icm_runtime_resume_switch,
2374 .handle_event = icm_handle_event,
2375 .get_boot_acl = icm_ar_get_boot_acl,
2376 .set_boot_acl = icm_ar_set_boot_acl,
2377 .approve_switch = icm_fr_approve_switch,
2378 .add_switch_key = icm_fr_add_switch_key,
2379 .challenge_switch_key = icm_fr_challenge_switch_key,
2380 .disconnect_pcie_paths = icm_disconnect_pcie_paths,
2381 .approve_xdomain_paths = icm_fr_approve_xdomain_paths,
2382 .disconnect_xdomain_paths = icm_fr_disconnect_xdomain_paths,
2386 static const struct tb_cm_ops icm_tr_ops = {
2387 .driver_ready = icm_driver_ready,
2390 .suspend = icm_suspend,
2391 .complete = icm_complete,
2392 .runtime_suspend = icm_runtime_suspend,
2393 .runtime_resume = icm_runtime_resume,
2394 .runtime_suspend_switch = icm_runtime_suspend_switch,
2395 .runtime_resume_switch = icm_runtime_resume_switch,
2396 .handle_event = icm_handle_event,
2397 .get_boot_acl = icm_ar_get_boot_acl,
2398 .set_boot_acl = icm_ar_set_boot_acl,
2399 .approve_switch = icm_tr_approve_switch,
2400 .add_switch_key = icm_tr_add_switch_key,
2401 .challenge_switch_key = icm_tr_challenge_switch_key,
2402 .disconnect_pcie_paths = icm_disconnect_pcie_paths,
2403 .approve_xdomain_paths = icm_tr_approve_xdomain_paths,
2404 .disconnect_xdomain_paths = icm_tr_disconnect_xdomain_paths,
2405 .usb4_switch_op = icm_usb4_switch_op,
2406 .usb4_switch_nvm_authenticate_status =
2407 icm_usb4_switch_nvm_authenticate_status,
2411 static const struct tb_cm_ops icm_icl_ops = {
2412 .driver_ready = icm_driver_ready,
2415 .complete = icm_complete,
2416 .runtime_suspend = icm_runtime_suspend,
2417 .runtime_resume = icm_runtime_resume,
2418 .handle_event = icm_handle_event,
2419 .approve_xdomain_paths = icm_tr_approve_xdomain_paths,
2420 .disconnect_xdomain_paths = icm_tr_disconnect_xdomain_paths,
2421 .usb4_switch_op = icm_usb4_switch_op,
2422 .usb4_switch_nvm_authenticate_status =
2423 icm_usb4_switch_nvm_authenticate_status,
2426 struct tb *icm_probe(struct tb_nhi *nhi)
2431 tb = tb_domain_alloc(nhi, ICM_TIMEOUT, sizeof(struct icm));
2436 INIT_DELAYED_WORK(&icm->rescan_work, icm_rescan_work);
2437 mutex_init(&icm->request_lock);
2439 switch (nhi->pdev->device) {
2440 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI:
2441 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI:
2442 icm->can_upgrade_nvm = true;
2443 icm->is_supported = icm_fr_is_supported;
2444 icm->get_route = icm_fr_get_route;
2445 icm->save_devices = icm_fr_save_devices;
2446 icm->driver_ready = icm_fr_driver_ready;
2447 icm->device_connected = icm_fr_device_connected;
2448 icm->device_disconnected = icm_fr_device_disconnected;
2449 icm->xdomain_connected = icm_fr_xdomain_connected;
2450 icm->xdomain_disconnected = icm_fr_xdomain_disconnected;
2451 tb->cm_ops = &icm_fr_ops;
2454 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_NHI:
2455 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_NHI:
2456 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_NHI:
2457 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_NHI:
2458 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_NHI:
2459 icm->max_boot_acl = ICM_AR_PREBOOT_ACL_ENTRIES;
2461 * NVM upgrade has not been tested on Apple systems and
2462 * they don't provide images publicly either. To be on
2463 * the safe side prevent root switch NVM upgrade on Macs
2466 icm->can_upgrade_nvm = !x86_apple_machine;
2467 icm->is_supported = icm_ar_is_supported;
2468 icm->cio_reset = icm_ar_cio_reset;
2469 icm->get_mode = icm_ar_get_mode;
2470 icm->get_route = icm_ar_get_route;
2471 icm->save_devices = icm_fr_save_devices;
2472 icm->driver_ready = icm_ar_driver_ready;
2473 icm->device_connected = icm_fr_device_connected;
2474 icm->device_disconnected = icm_fr_device_disconnected;
2475 icm->xdomain_connected = icm_fr_xdomain_connected;
2476 icm->xdomain_disconnected = icm_fr_xdomain_disconnected;
2477 tb->cm_ops = &icm_ar_ops;
2480 case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_NHI:
2481 case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_NHI:
2482 icm->max_boot_acl = ICM_AR_PREBOOT_ACL_ENTRIES;
2483 icm->can_upgrade_nvm = !x86_apple_machine;
2484 icm->is_supported = icm_ar_is_supported;
2485 icm->cio_reset = icm_tr_cio_reset;
2486 icm->get_mode = icm_ar_get_mode;
2487 icm->driver_ready = icm_tr_driver_ready;
2488 icm->device_connected = icm_tr_device_connected;
2489 icm->device_disconnected = icm_tr_device_disconnected;
2490 icm->xdomain_connected = icm_tr_xdomain_connected;
2491 icm->xdomain_disconnected = icm_tr_xdomain_disconnected;
2492 tb->cm_ops = &icm_tr_ops;
2495 case PCI_DEVICE_ID_INTEL_ICL_NHI0:
2496 case PCI_DEVICE_ID_INTEL_ICL_NHI1:
2497 icm->is_supported = icm_fr_is_supported;
2498 icm->driver_ready = icm_icl_driver_ready;
2499 icm->set_uuid = icm_icl_set_uuid;
2500 icm->device_connected = icm_icl_device_connected;
2501 icm->device_disconnected = icm_tr_device_disconnected;
2502 icm->xdomain_connected = icm_tr_xdomain_connected;
2503 icm->xdomain_disconnected = icm_tr_xdomain_disconnected;
2504 icm->rtd3_veto = icm_icl_rtd3_veto;
2505 tb->cm_ops = &icm_icl_ops;
2508 case PCI_DEVICE_ID_INTEL_TGL_NHI0:
2509 case PCI_DEVICE_ID_INTEL_TGL_NHI1:
2510 case PCI_DEVICE_ID_INTEL_TGL_H_NHI0:
2511 case PCI_DEVICE_ID_INTEL_TGL_H_NHI1:
2512 case PCI_DEVICE_ID_INTEL_ADL_NHI0:
2513 case PCI_DEVICE_ID_INTEL_ADL_NHI1:
2514 icm->is_supported = icm_tgl_is_supported;
2515 icm->driver_ready = icm_icl_driver_ready;
2516 icm->set_uuid = icm_icl_set_uuid;
2517 icm->device_connected = icm_icl_device_connected;
2518 icm->device_disconnected = icm_tr_device_disconnected;
2519 icm->xdomain_connected = icm_tr_xdomain_connected;
2520 icm->xdomain_disconnected = icm_tr_xdomain_disconnected;
2521 icm->rtd3_veto = icm_icl_rtd3_veto;
2522 tb->cm_ops = &icm_icl_ops;
2525 case PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_4C_NHI:
2526 icm->is_supported = icm_tgl_is_supported;
2527 icm->get_mode = icm_ar_get_mode;
2528 icm->driver_ready = icm_tr_driver_ready;
2529 icm->device_connected = icm_tr_device_connected;
2530 icm->device_disconnected = icm_tr_device_disconnected;
2531 icm->xdomain_connected = icm_tr_xdomain_connected;
2532 icm->xdomain_disconnected = icm_tr_xdomain_disconnected;
2533 tb->cm_ops = &icm_tr_ops;
2537 if (!icm->is_supported || !icm->is_supported(tb)) {
2538 dev_dbg(&nhi->pdev->dev, "ICM not supported on this controller\n");
2543 tb_dbg(tb, "using firmware connection manager\n");