blob: 1183321586c5aa75b514b49f70b5347da222934c [file] [log] [blame]
Mika Westerbergf67cf492017-06-06 15:25:16 +03001/*
2 * Internal Thunderbolt Connection Manager. This is a firmware running on
3 * the Thunderbolt host controller performing most of the low-level
4 * handling.
5 *
6 * Copyright (C) 2017, Intel Corporation
7 * Authors: Michael Jamet <michael.jamet@intel.com>
8 * Mika Westerberg <mika.westerberg@linux.intel.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/delay.h>
Mika Westerbergf67cf492017-06-06 15:25:16 +030016#include <linux/mutex.h>
17#include <linux/pci.h>
Lukas Wunner630b3af2017-08-01 14:10:41 +020018#include <linux/platform_data/x86/apple.h>
Mika Westerbergf67cf492017-06-06 15:25:16 +030019#include <linux/sizes.h>
20#include <linux/slab.h>
21#include <linux/workqueue.h>
22
23#include "ctl.h"
24#include "nhi_regs.h"
25#include "tb.h"
26
27#define PCIE2CIO_CMD 0x30
28#define PCIE2CIO_CMD_TIMEOUT BIT(31)
29#define PCIE2CIO_CMD_START BIT(30)
30#define PCIE2CIO_CMD_WRITE BIT(21)
31#define PCIE2CIO_CMD_CS_MASK GENMASK(20, 19)
32#define PCIE2CIO_CMD_CS_SHIFT 19
33#define PCIE2CIO_CMD_PORT_MASK GENMASK(18, 13)
34#define PCIE2CIO_CMD_PORT_SHIFT 13
35
36#define PCIE2CIO_WRDATA 0x34
37#define PCIE2CIO_RDDATA 0x38
38
39#define PHY_PORT_CS1 0x37
40#define PHY_PORT_CS1_LINK_DISABLE BIT(14)
41#define PHY_PORT_CS1_LINK_STATE_MASK GENMASK(29, 26)
42#define PHY_PORT_CS1_LINK_STATE_SHIFT 26
43
44#define ICM_TIMEOUT 5000 /* ms */
45#define ICM_MAX_LINK 4
46#define ICM_MAX_DEPTH 6
47
48/**
49 * struct icm - Internal connection manager private data
50 * @request_lock: Makes sure only one message is send to ICM at time
51 * @rescan_work: Work used to rescan the surviving switches after resume
52 * @upstream_port: Pointer to the PCIe upstream port this host
53 * controller is connected. This is only set for systems
54 * where ICM needs to be started manually
55 * @vnd_cap: Vendor defined capability where PCIe2CIO mailbox resides
56 * (only set when @upstream_port is not %NULL)
Mika Westerberge6b245c2017-06-06 15:25:17 +030057 * @safe_mode: ICM is in safe mode
Mika Westerbergf67cf492017-06-06 15:25:16 +030058 * @is_supported: Checks if we can support ICM on this controller
59 * @get_mode: Read and return the ICM firmware mode (optional)
60 * @get_route: Find a route string for given switch
61 * @device_connected: Handle device connected ICM message
62 * @device_disconnected: Handle device disconnected ICM message
Mika Westerbergd1ff7022017-10-02 13:38:34 +030063 * @xdomain_connected - Handle XDomain connected ICM message
64 * @xdomain_disconnected - Handle XDomain disconnected ICM message
Mika Westerbergf67cf492017-06-06 15:25:16 +030065 */
66struct icm {
67 struct mutex request_lock;
68 struct delayed_work rescan_work;
69 struct pci_dev *upstream_port;
70 int vnd_cap;
Mika Westerberge6b245c2017-06-06 15:25:17 +030071 bool safe_mode;
Mika Westerbergf67cf492017-06-06 15:25:16 +030072 bool (*is_supported)(struct tb *tb);
73 int (*get_mode)(struct tb *tb);
74 int (*get_route)(struct tb *tb, u8 link, u8 depth, u64 *route);
75 void (*device_connected)(struct tb *tb,
76 const struct icm_pkg_header *hdr);
77 void (*device_disconnected)(struct tb *tb,
78 const struct icm_pkg_header *hdr);
Mika Westerbergd1ff7022017-10-02 13:38:34 +030079 void (*xdomain_connected)(struct tb *tb,
80 const struct icm_pkg_header *hdr);
81 void (*xdomain_disconnected)(struct tb *tb,
82 const struct icm_pkg_header *hdr);
Mika Westerbergf67cf492017-06-06 15:25:16 +030083};
84
85struct icm_notification {
86 struct work_struct work;
87 struct icm_pkg_header *pkg;
88 struct tb *tb;
89};
90
91static inline struct tb *icm_to_tb(struct icm *icm)
92{
93 return ((void *)icm - sizeof(struct tb));
94}
95
96static inline u8 phy_port_from_route(u64 route, u8 depth)
97{
Mika Westerbergd1ff7022017-10-02 13:38:34 +030098 u8 link;
99
100 link = depth ? route >> ((depth - 1) * 8) : route;
101 return tb_phy_port_from_link(link);
Mika Westerbergf67cf492017-06-06 15:25:16 +0300102}
103
104static inline u8 dual_link_from_link(u8 link)
105{
106 return link ? ((link - 1) ^ 0x01) + 1 : 0;
107}
108
109static inline u64 get_route(u32 route_hi, u32 route_lo)
110{
111 return (u64)route_hi << 32 | route_lo;
112}
113
Mika Westerbergf67cf492017-06-06 15:25:16 +0300114static bool icm_match(const struct tb_cfg_request *req,
115 const struct ctl_pkg *pkg)
116{
117 const struct icm_pkg_header *res_hdr = pkg->buffer;
118 const struct icm_pkg_header *req_hdr = req->request;
119
120 if (pkg->frame.eof != req->response_type)
121 return false;
122 if (res_hdr->code != req_hdr->code)
123 return false;
124
125 return true;
126}
127
128static bool icm_copy(struct tb_cfg_request *req, const struct ctl_pkg *pkg)
129{
130 const struct icm_pkg_header *hdr = pkg->buffer;
131
132 if (hdr->packet_id < req->npackets) {
133 size_t offset = hdr->packet_id * req->response_size;
134
135 memcpy(req->response + offset, pkg->buffer, req->response_size);
136 }
137
138 return hdr->packet_id == hdr->total_packets - 1;
139}
140
141static int icm_request(struct tb *tb, const void *request, size_t request_size,
142 void *response, size_t response_size, size_t npackets,
143 unsigned int timeout_msec)
144{
145 struct icm *icm = tb_priv(tb);
146 int retries = 3;
147
148 do {
149 struct tb_cfg_request *req;
150 struct tb_cfg_result res;
151
152 req = tb_cfg_request_alloc();
153 if (!req)
154 return -ENOMEM;
155
156 req->match = icm_match;
157 req->copy = icm_copy;
158 req->request = request;
159 req->request_size = request_size;
160 req->request_type = TB_CFG_PKG_ICM_CMD;
161 req->response = response;
162 req->npackets = npackets;
163 req->response_size = response_size;
164 req->response_type = TB_CFG_PKG_ICM_RESP;
165
166 mutex_lock(&icm->request_lock);
167 res = tb_cfg_request_sync(tb->ctl, req, timeout_msec);
168 mutex_unlock(&icm->request_lock);
169
170 tb_cfg_request_put(req);
171
172 if (res.err != -ETIMEDOUT)
173 return res.err == 1 ? -EIO : res.err;
174
175 usleep_range(20, 50);
176 } while (retries--);
177
178 return -ETIMEDOUT;
179}
180
181static bool icm_fr_is_supported(struct tb *tb)
182{
Lukas Wunner630b3af2017-08-01 14:10:41 +0200183 return !x86_apple_machine;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300184}
185
186static inline int icm_fr_get_switch_index(u32 port)
187{
188 int index;
189
190 if ((port & ICM_PORT_TYPE_MASK) != TB_TYPE_PORT)
191 return 0;
192
193 index = port >> ICM_PORT_INDEX_SHIFT;
194 return index != 0xff ? index : 0;
195}
196
197static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
198{
199 struct icm_fr_pkg_get_topology_response *switches, *sw;
200 struct icm_fr_pkg_get_topology request = {
201 .hdr = { .code = ICM_GET_TOPOLOGY },
202 };
203 size_t npackets = ICM_GET_TOPOLOGY_PACKETS;
204 int ret, index;
205 u8 i;
206
207 switches = kcalloc(npackets, sizeof(*switches), GFP_KERNEL);
208 if (!switches)
209 return -ENOMEM;
210
211 ret = icm_request(tb, &request, sizeof(request), switches,
212 sizeof(*switches), npackets, ICM_TIMEOUT);
213 if (ret)
214 goto err_free;
215
216 sw = &switches[0];
217 index = icm_fr_get_switch_index(sw->ports[link]);
218 if (!index) {
219 ret = -ENODEV;
220 goto err_free;
221 }
222
223 sw = &switches[index];
224 for (i = 1; i < depth; i++) {
225 unsigned int j;
226
227 if (!(sw->first_data & ICM_SWITCH_USED)) {
228 ret = -ENODEV;
229 goto err_free;
230 }
231
232 for (j = 0; j < ARRAY_SIZE(sw->ports); j++) {
233 index = icm_fr_get_switch_index(sw->ports[j]);
234 if (index > sw->switch_index) {
235 sw = &switches[index];
236 break;
237 }
238 }
239 }
240
241 *route = get_route(sw->route_hi, sw->route_lo);
242
243err_free:
244 kfree(switches);
245 return ret;
246}
247
248static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw)
249{
250 struct icm_fr_pkg_approve_device request;
251 struct icm_fr_pkg_approve_device reply;
252 int ret;
253
254 memset(&request, 0, sizeof(request));
255 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
256 request.hdr.code = ICM_APPROVE_DEVICE;
257 request.connection_id = sw->connection_id;
258 request.connection_key = sw->connection_key;
259
260 memset(&reply, 0, sizeof(reply));
261 /* Use larger timeout as establishing tunnels can take some time */
262 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
263 1, 10000);
264 if (ret)
265 return ret;
266
267 if (reply.hdr.flags & ICM_FLAGS_ERROR) {
268 tb_warn(tb, "PCIe tunnel creation failed\n");
269 return -EIO;
270 }
271
272 return 0;
273}
274
275static int icm_fr_add_switch_key(struct tb *tb, struct tb_switch *sw)
276{
277 struct icm_fr_pkg_add_device_key request;
278 struct icm_fr_pkg_add_device_key_response reply;
279 int ret;
280
281 memset(&request, 0, sizeof(request));
282 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
283 request.hdr.code = ICM_ADD_DEVICE_KEY;
284 request.connection_id = sw->connection_id;
285 request.connection_key = sw->connection_key;
286 memcpy(request.key, sw->key, TB_SWITCH_KEY_SIZE);
287
288 memset(&reply, 0, sizeof(reply));
289 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
290 1, ICM_TIMEOUT);
291 if (ret)
292 return ret;
293
294 if (reply.hdr.flags & ICM_FLAGS_ERROR) {
295 tb_warn(tb, "Adding key to switch failed\n");
296 return -EIO;
297 }
298
299 return 0;
300}
301
302static int icm_fr_challenge_switch_key(struct tb *tb, struct tb_switch *sw,
303 const u8 *challenge, u8 *response)
304{
305 struct icm_fr_pkg_challenge_device request;
306 struct icm_fr_pkg_challenge_device_response reply;
307 int ret;
308
309 memset(&request, 0, sizeof(request));
310 memcpy(&request.ep_uuid, sw->uuid, sizeof(request.ep_uuid));
311 request.hdr.code = ICM_CHALLENGE_DEVICE;
312 request.connection_id = sw->connection_id;
313 request.connection_key = sw->connection_key;
314 memcpy(request.challenge, challenge, TB_SWITCH_KEY_SIZE);
315
316 memset(&reply, 0, sizeof(reply));
317 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
318 1, ICM_TIMEOUT);
319 if (ret)
320 return ret;
321
322 if (reply.hdr.flags & ICM_FLAGS_ERROR)
323 return -EKEYREJECTED;
324 if (reply.hdr.flags & ICM_FLAGS_NO_KEY)
325 return -ENOKEY;
326
327 memcpy(response, reply.response, TB_SWITCH_KEY_SIZE);
328
329 return 0;
330}
331
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300332static int icm_fr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd)
333{
334 struct icm_fr_pkg_approve_xdomain_response reply;
335 struct icm_fr_pkg_approve_xdomain request;
336 int ret;
337
338 memset(&request, 0, sizeof(request));
339 request.hdr.code = ICM_APPROVE_XDOMAIN;
340 request.link_info = xd->depth << ICM_LINK_INFO_DEPTH_SHIFT | xd->link;
341 memcpy(&request.remote_uuid, xd->remote_uuid, sizeof(*xd->remote_uuid));
342
343 request.transmit_path = xd->transmit_path;
344 request.transmit_ring = xd->transmit_ring;
345 request.receive_path = xd->receive_path;
346 request.receive_ring = xd->receive_ring;
347
348 memset(&reply, 0, sizeof(reply));
349 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
350 1, ICM_TIMEOUT);
351 if (ret)
352 return ret;
353
354 if (reply.hdr.flags & ICM_FLAGS_ERROR)
355 return -EIO;
356
357 return 0;
358}
359
360static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd)
361{
362 u8 phy_port;
363 u8 cmd;
364
365 phy_port = tb_phy_port_from_link(xd->link);
366 if (phy_port == 0)
367 cmd = NHI_MAILBOX_DISCONNECT_PA;
368 else
369 cmd = NHI_MAILBOX_DISCONNECT_PB;
370
371 nhi_mailbox_cmd(tb->nhi, cmd, 1);
372 usleep_range(10, 50);
373 nhi_mailbox_cmd(tb->nhi, cmd, 2);
374 return 0;
375}
376
Mika Westerbergf67cf492017-06-06 15:25:16 +0300377static void remove_switch(struct tb_switch *sw)
378{
379 struct tb_switch *parent_sw;
380
381 parent_sw = tb_to_switch(sw->dev.parent);
382 tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
383 tb_switch_remove(sw);
384}
385
Mika Westerberg79fae982018-02-09 17:29:38 +0300386static void remove_xdomain(struct tb_xdomain *xd)
387{
388 struct tb_switch *sw;
389
390 sw = tb_to_switch(xd->dev.parent);
391 tb_port_at(xd->route, sw)->xdomain = NULL;
392 tb_xdomain_remove(xd);
393}
394
Mika Westerbergf67cf492017-06-06 15:25:16 +0300395static void
396icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
397{
398 const struct icm_fr_event_device_connected *pkg =
399 (const struct icm_fr_event_device_connected *)hdr;
400 struct tb_switch *sw, *parent_sw;
401 struct icm *icm = tb_priv(tb);
402 bool authorized = false;
Mika Westerberg79fae982018-02-09 17:29:38 +0300403 struct tb_xdomain *xd;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300404 u8 link, depth;
405 u64 route;
406 int ret;
407
408 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK;
409 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
410 ICM_LINK_INFO_DEPTH_SHIFT;
411 authorized = pkg->link_info & ICM_LINK_INFO_APPROVED;
412
413 ret = icm->get_route(tb, link, depth, &route);
414 if (ret) {
415 tb_err(tb, "failed to find route string for switch at %u.%u\n",
416 link, depth);
417 return;
418 }
419
420 sw = tb_switch_find_by_uuid(tb, &pkg->ep_uuid);
421 if (sw) {
422 u8 phy_port, sw_phy_port;
423
424 parent_sw = tb_to_switch(sw->dev.parent);
425 sw_phy_port = phy_port_from_route(tb_route(sw), sw->depth);
426 phy_port = phy_port_from_route(route, depth);
427
428 /*
429 * On resume ICM will send us connected events for the
430 * devices that still are present. However, that
431 * information might have changed for example by the
432 * fact that a switch on a dual-link connection might
433 * have been enumerated using the other link now. Make
434 * sure our book keeping matches that.
435 */
436 if (sw->depth == depth && sw_phy_port == phy_port &&
437 !!sw->authorized == authorized) {
438 tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
439 tb_port_at(route, parent_sw)->remote =
440 tb_upstream_port(sw);
441 sw->config.route_hi = upper_32_bits(route);
442 sw->config.route_lo = lower_32_bits(route);
443 sw->connection_id = pkg->connection_id;
444 sw->connection_key = pkg->connection_key;
445 sw->link = link;
446 sw->depth = depth;
447 sw->is_unplugged = false;
448 tb_switch_put(sw);
449 return;
450 }
451
452 /*
453 * User connected the same switch to another physical
454 * port or to another part of the topology. Remove the
455 * existing switch now before adding the new one.
456 */
457 remove_switch(sw);
458 tb_switch_put(sw);
459 }
460
461 /*
462 * If the switch was not found by UUID, look for a switch on
463 * same physical port (taking possible link aggregation into
464 * account) and depth. If we found one it is definitely a stale
465 * one so remove it first.
466 */
467 sw = tb_switch_find_by_link_depth(tb, link, depth);
468 if (!sw) {
469 u8 dual_link;
470
471 dual_link = dual_link_from_link(link);
472 if (dual_link)
473 sw = tb_switch_find_by_link_depth(tb, dual_link, depth);
474 }
475 if (sw) {
476 remove_switch(sw);
477 tb_switch_put(sw);
478 }
479
Mika Westerberg79fae982018-02-09 17:29:38 +0300480 /* Remove existing XDomain connection if found */
481 xd = tb_xdomain_find_by_link_depth(tb, link, depth);
482 if (xd) {
483 remove_xdomain(xd);
484 tb_xdomain_put(xd);
485 }
486
Mika Westerbergf67cf492017-06-06 15:25:16 +0300487 parent_sw = tb_switch_find_by_link_depth(tb, link, depth - 1);
488 if (!parent_sw) {
489 tb_err(tb, "failed to find parent switch for %u.%u\n",
490 link, depth);
491 return;
492 }
493
494 sw = tb_switch_alloc(tb, &parent_sw->dev, route);
495 if (!sw) {
496 tb_switch_put(parent_sw);
497 return;
498 }
499
500 sw->uuid = kmemdup(&pkg->ep_uuid, sizeof(pkg->ep_uuid), GFP_KERNEL);
501 sw->connection_id = pkg->connection_id;
502 sw->connection_key = pkg->connection_key;
503 sw->link = link;
504 sw->depth = depth;
505 sw->authorized = authorized;
506 sw->security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >>
507 ICM_FLAGS_SLEVEL_SHIFT;
508
509 /* Link the two switches now */
510 tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw);
511 tb_upstream_port(sw)->remote = tb_port_at(route, parent_sw);
512
513 ret = tb_switch_add(sw);
514 if (ret) {
515 tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
516 tb_switch_put(sw);
517 }
518 tb_switch_put(parent_sw);
519}
520
521static void
522icm_fr_device_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
523{
524 const struct icm_fr_event_device_disconnected *pkg =
525 (const struct icm_fr_event_device_disconnected *)hdr;
526 struct tb_switch *sw;
527 u8 link, depth;
528
529 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK;
530 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
531 ICM_LINK_INFO_DEPTH_SHIFT;
532
533 if (link > ICM_MAX_LINK || depth > ICM_MAX_DEPTH) {
534 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth);
535 return;
536 }
537
538 sw = tb_switch_find_by_link_depth(tb, link, depth);
539 if (!sw) {
540 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link,
541 depth);
542 return;
543 }
544
545 remove_switch(sw);
546 tb_switch_put(sw);
547}
548
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300549static void
550icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
551{
552 const struct icm_fr_event_xdomain_connected *pkg =
553 (const struct icm_fr_event_xdomain_connected *)hdr;
554 struct tb_xdomain *xd;
555 struct tb_switch *sw;
556 u8 link, depth;
557 bool approved;
558 u64 route;
559
560 /*
561 * After NVM upgrade adding root switch device fails because we
562 * initiated reset. During that time ICM might still send
563 * XDomain connected message which we ignore here.
564 */
565 if (!tb->root_switch)
566 return;
567
568 link = pkg->link_info & ICM_LINK_INFO_LINK_MASK;
569 depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
570 ICM_LINK_INFO_DEPTH_SHIFT;
571 approved = pkg->link_info & ICM_LINK_INFO_APPROVED;
572
573 if (link > ICM_MAX_LINK || depth > ICM_MAX_DEPTH) {
574 tb_warn(tb, "invalid topology %u.%u, ignoring\n", link, depth);
575 return;
576 }
577
578 route = get_route(pkg->local_route_hi, pkg->local_route_lo);
579
580 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
581 if (xd) {
582 u8 xd_phy_port, phy_port;
583
584 xd_phy_port = phy_port_from_route(xd->route, xd->depth);
585 phy_port = phy_port_from_route(route, depth);
586
587 if (xd->depth == depth && xd_phy_port == phy_port) {
588 xd->link = link;
589 xd->route = route;
590 xd->is_unplugged = false;
591 tb_xdomain_put(xd);
592 return;
593 }
594
595 /*
596 * If we find an existing XDomain connection remove it
597 * now. We need to go through login handshake and
598 * everything anyway to be able to re-establish the
599 * connection.
600 */
601 remove_xdomain(xd);
602 tb_xdomain_put(xd);
603 }
604
605 /*
606 * Look if there already exists an XDomain in the same place
607 * than the new one and in that case remove it because it is
608 * most likely another host that got disconnected.
609 */
610 xd = tb_xdomain_find_by_link_depth(tb, link, depth);
611 if (!xd) {
612 u8 dual_link;
613
614 dual_link = dual_link_from_link(link);
615 if (dual_link)
616 xd = tb_xdomain_find_by_link_depth(tb, dual_link,
617 depth);
618 }
619 if (xd) {
620 remove_xdomain(xd);
621 tb_xdomain_put(xd);
622 }
623
624 /*
625 * If the user disconnected a switch during suspend and
626 * connected another host to the same port, remove the switch
627 * first.
628 */
629 sw = get_switch_at_route(tb->root_switch, route);
630 if (sw)
631 remove_switch(sw);
632
633 sw = tb_switch_find_by_link_depth(tb, link, depth);
634 if (!sw) {
635 tb_warn(tb, "no switch exists at %u.%u, ignoring\n", link,
636 depth);
637 return;
638 }
639
640 xd = tb_xdomain_alloc(sw->tb, &sw->dev, route,
641 &pkg->local_uuid, &pkg->remote_uuid);
642 if (!xd) {
643 tb_switch_put(sw);
644 return;
645 }
646
647 xd->link = link;
648 xd->depth = depth;
649
650 tb_port_at(route, sw)->xdomain = xd;
651
652 tb_xdomain_add(xd);
653 tb_switch_put(sw);
654}
655
656static void
657icm_fr_xdomain_disconnected(struct tb *tb, const struct icm_pkg_header *hdr)
658{
659 const struct icm_fr_event_xdomain_disconnected *pkg =
660 (const struct icm_fr_event_xdomain_disconnected *)hdr;
661 struct tb_xdomain *xd;
662
663 /*
664 * If the connection is through one or multiple devices, the
665 * XDomain device is removed along with them so it is fine if we
666 * cannot find it here.
667 */
668 xd = tb_xdomain_find_by_uuid(tb, &pkg->remote_uuid);
669 if (xd) {
670 remove_xdomain(xd);
671 tb_xdomain_put(xd);
672 }
673}
674
Mika Westerbergf67cf492017-06-06 15:25:16 +0300675static struct pci_dev *get_upstream_port(struct pci_dev *pdev)
676{
677 struct pci_dev *parent;
678
679 parent = pci_upstream_bridge(pdev);
680 while (parent) {
681 if (!pci_is_pcie(parent))
682 return NULL;
683 if (pci_pcie_type(parent) == PCI_EXP_TYPE_UPSTREAM)
684 break;
685 parent = pci_upstream_bridge(parent);
686 }
687
688 if (!parent)
689 return NULL;
690
691 switch (parent->device) {
692 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE:
693 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_BRIDGE:
694 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE:
695 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE:
696 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE:
697 return parent;
698 }
699
700 return NULL;
701}
702
703static bool icm_ar_is_supported(struct tb *tb)
704{
705 struct pci_dev *upstream_port;
706 struct icm *icm = tb_priv(tb);
707
708 /*
709 * Starting from Alpine Ridge we can use ICM on Apple machines
710 * as well. We just need to reset and re-enable it first.
711 */
Lukas Wunner630b3af2017-08-01 14:10:41 +0200712 if (!x86_apple_machine)
Mika Westerbergf67cf492017-06-06 15:25:16 +0300713 return true;
714
715 /*
716 * Find the upstream PCIe port in case we need to do reset
717 * through its vendor specific registers.
718 */
719 upstream_port = get_upstream_port(tb->nhi->pdev);
720 if (upstream_port) {
721 int cap;
722
723 cap = pci_find_ext_capability(upstream_port,
724 PCI_EXT_CAP_ID_VNDR);
725 if (cap > 0) {
726 icm->upstream_port = upstream_port;
727 icm->vnd_cap = cap;
728
729 return true;
730 }
731 }
732
733 return false;
734}
735
736static int icm_ar_get_mode(struct tb *tb)
737{
738 struct tb_nhi *nhi = tb->nhi;
739 int retries = 5;
740 u32 val;
741
742 do {
743 val = ioread32(nhi->iobase + REG_FW_STS);
744 if (val & REG_FW_STS_NVM_AUTH_DONE)
745 break;
746 msleep(30);
747 } while (--retries);
748
749 if (!retries) {
750 dev_err(&nhi->pdev->dev, "ICM firmware not authenticated\n");
751 return -ENODEV;
752 }
753
754 return nhi_mailbox_mode(nhi);
755}
756
757static int icm_ar_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
758{
759 struct icm_ar_pkg_get_route_response reply;
760 struct icm_ar_pkg_get_route request = {
761 .hdr = { .code = ICM_GET_ROUTE },
762 .link_info = depth << ICM_LINK_INFO_DEPTH_SHIFT | link,
763 };
764 int ret;
765
766 memset(&reply, 0, sizeof(reply));
767 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
768 1, ICM_TIMEOUT);
769 if (ret)
770 return ret;
771
772 if (reply.hdr.flags & ICM_FLAGS_ERROR)
773 return -EIO;
774
775 *route = get_route(reply.route_hi, reply.route_lo);
776 return 0;
777}
778
779static void icm_handle_notification(struct work_struct *work)
780{
781 struct icm_notification *n = container_of(work, typeof(*n), work);
782 struct tb *tb = n->tb;
783 struct icm *icm = tb_priv(tb);
784
785 mutex_lock(&tb->lock);
786
787 switch (n->pkg->code) {
788 case ICM_EVENT_DEVICE_CONNECTED:
789 icm->device_connected(tb, n->pkg);
790 break;
791 case ICM_EVENT_DEVICE_DISCONNECTED:
792 icm->device_disconnected(tb, n->pkg);
793 break;
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300794 case ICM_EVENT_XDOMAIN_CONNECTED:
795 icm->xdomain_connected(tb, n->pkg);
796 break;
797 case ICM_EVENT_XDOMAIN_DISCONNECTED:
798 icm->xdomain_disconnected(tb, n->pkg);
799 break;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300800 }
801
802 mutex_unlock(&tb->lock);
803
804 kfree(n->pkg);
805 kfree(n);
806}
807
808static void icm_handle_event(struct tb *tb, enum tb_cfg_pkg_type type,
809 const void *buf, size_t size)
810{
811 struct icm_notification *n;
812
813 n = kmalloc(sizeof(*n), GFP_KERNEL);
814 if (!n)
815 return;
816
817 INIT_WORK(&n->work, icm_handle_notification);
818 n->pkg = kmemdup(buf, size, GFP_KERNEL);
819 n->tb = tb;
820
821 queue_work(tb->wq, &n->work);
822}
823
824static int
825__icm_driver_ready(struct tb *tb, enum tb_security_level *security_level)
826{
827 struct icm_pkg_driver_ready_response reply;
828 struct icm_pkg_driver_ready request = {
829 .hdr.code = ICM_DRIVER_READY,
830 };
Mika Westerberg44b51bb2017-09-14 13:44:07 +0300831 unsigned int retries = 50;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300832 int ret;
833
834 memset(&reply, 0, sizeof(reply));
835 ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
836 1, ICM_TIMEOUT);
837 if (ret)
838 return ret;
839
840 if (security_level)
841 *security_level = reply.security_level & 0xf;
842
843 /*
844 * Hold on here until the switch config space is accessible so
845 * that we can read root switch config successfully.
846 */
847 do {
848 struct tb_cfg_result res;
849 u32 tmp;
850
851 res = tb_cfg_read_raw(tb->ctl, &tmp, 0, 0, TB_CFG_SWITCH,
852 0, 1, 100);
853 if (!res.err)
854 return 0;
855
856 msleep(50);
857 } while (--retries);
858
Mika Westerberg44b51bb2017-09-14 13:44:07 +0300859 tb_err(tb, "failed to read root switch config space, giving up\n");
Mika Westerbergf67cf492017-06-06 15:25:16 +0300860 return -ETIMEDOUT;
861}
862
863static int pci2cio_wait_completion(struct icm *icm, unsigned long timeout_msec)
864{
865 unsigned long end = jiffies + msecs_to_jiffies(timeout_msec);
866 u32 cmd;
867
868 do {
869 pci_read_config_dword(icm->upstream_port,
870 icm->vnd_cap + PCIE2CIO_CMD, &cmd);
871 if (!(cmd & PCIE2CIO_CMD_START)) {
872 if (cmd & PCIE2CIO_CMD_TIMEOUT)
873 break;
874 return 0;
875 }
876
877 msleep(50);
878 } while (time_before(jiffies, end));
879
880 return -ETIMEDOUT;
881}
882
883static int pcie2cio_read(struct icm *icm, enum tb_cfg_space cs,
884 unsigned int port, unsigned int index, u32 *data)
885{
886 struct pci_dev *pdev = icm->upstream_port;
887 int ret, vnd_cap = icm->vnd_cap;
888 u32 cmd;
889
890 cmd = index;
891 cmd |= (port << PCIE2CIO_CMD_PORT_SHIFT) & PCIE2CIO_CMD_PORT_MASK;
892 cmd |= (cs << PCIE2CIO_CMD_CS_SHIFT) & PCIE2CIO_CMD_CS_MASK;
893 cmd |= PCIE2CIO_CMD_START;
894 pci_write_config_dword(pdev, vnd_cap + PCIE2CIO_CMD, cmd);
895
896 ret = pci2cio_wait_completion(icm, 5000);
897 if (ret)
898 return ret;
899
900 pci_read_config_dword(pdev, vnd_cap + PCIE2CIO_RDDATA, data);
901 return 0;
902}
903
904static int pcie2cio_write(struct icm *icm, enum tb_cfg_space cs,
905 unsigned int port, unsigned int index, u32 data)
906{
907 struct pci_dev *pdev = icm->upstream_port;
908 int vnd_cap = icm->vnd_cap;
909 u32 cmd;
910
911 pci_write_config_dword(pdev, vnd_cap + PCIE2CIO_WRDATA, data);
912
913 cmd = index;
914 cmd |= (port << PCIE2CIO_CMD_PORT_SHIFT) & PCIE2CIO_CMD_PORT_MASK;
915 cmd |= (cs << PCIE2CIO_CMD_CS_SHIFT) & PCIE2CIO_CMD_CS_MASK;
916 cmd |= PCIE2CIO_CMD_WRITE | PCIE2CIO_CMD_START;
917 pci_write_config_dword(pdev, vnd_cap + PCIE2CIO_CMD, cmd);
918
919 return pci2cio_wait_completion(icm, 5000);
920}
921
922static int icm_firmware_reset(struct tb *tb, struct tb_nhi *nhi)
923{
924 struct icm *icm = tb_priv(tb);
925 u32 val;
926
927 /* Put ARC to wait for CIO reset event to happen */
928 val = ioread32(nhi->iobase + REG_FW_STS);
929 val |= REG_FW_STS_CIO_RESET_REQ;
930 iowrite32(val, nhi->iobase + REG_FW_STS);
931
932 /* Re-start ARC */
933 val = ioread32(nhi->iobase + REG_FW_STS);
934 val |= REG_FW_STS_ICM_EN_INVERT;
935 val |= REG_FW_STS_ICM_EN_CPU;
936 iowrite32(val, nhi->iobase + REG_FW_STS);
937
938 /* Trigger CIO reset now */
939 return pcie2cio_write(icm, TB_CFG_SWITCH, 0, 0x50, BIT(9));
940}
941
942static int icm_firmware_start(struct tb *tb, struct tb_nhi *nhi)
943{
944 unsigned int retries = 10;
945 int ret;
946 u32 val;
947
948 /* Check if the ICM firmware is already running */
949 val = ioread32(nhi->iobase + REG_FW_STS);
950 if (val & REG_FW_STS_ICM_EN)
951 return 0;
952
953 dev_info(&nhi->pdev->dev, "starting ICM firmware\n");
954
955 ret = icm_firmware_reset(tb, nhi);
956 if (ret)
957 return ret;
958
959 /* Wait until the ICM firmware tells us it is up and running */
960 do {
961 /* Check that the ICM firmware is running */
962 val = ioread32(nhi->iobase + REG_FW_STS);
963 if (val & REG_FW_STS_NVM_AUTH_DONE)
964 return 0;
965
966 msleep(300);
967 } while (--retries);
968
969 return -ETIMEDOUT;
970}
971
972static int icm_reset_phy_port(struct tb *tb, int phy_port)
973{
974 struct icm *icm = tb_priv(tb);
975 u32 state0, state1;
976 int port0, port1;
977 u32 val0, val1;
978 int ret;
979
980 if (!icm->upstream_port)
981 return 0;
982
983 if (phy_port) {
984 port0 = 3;
985 port1 = 4;
986 } else {
987 port0 = 1;
988 port1 = 2;
989 }
990
991 /*
992 * Read link status of both null ports belonging to a single
993 * physical port.
994 */
995 ret = pcie2cio_read(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, &val0);
996 if (ret)
997 return ret;
998 ret = pcie2cio_read(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, &val1);
999 if (ret)
1000 return ret;
1001
1002 state0 = val0 & PHY_PORT_CS1_LINK_STATE_MASK;
1003 state0 >>= PHY_PORT_CS1_LINK_STATE_SHIFT;
1004 state1 = val1 & PHY_PORT_CS1_LINK_STATE_MASK;
1005 state1 >>= PHY_PORT_CS1_LINK_STATE_SHIFT;
1006
1007 /* If they are both up we need to reset them now */
1008 if (state0 != TB_PORT_UP || state1 != TB_PORT_UP)
1009 return 0;
1010
1011 val0 |= PHY_PORT_CS1_LINK_DISABLE;
1012 ret = pcie2cio_write(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, val0);
1013 if (ret)
1014 return ret;
1015
1016 val1 |= PHY_PORT_CS1_LINK_DISABLE;
1017 ret = pcie2cio_write(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, val1);
1018 if (ret)
1019 return ret;
1020
1021 /* Wait a bit and then re-enable both ports */
1022 usleep_range(10, 100);
1023
1024 ret = pcie2cio_read(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, &val0);
1025 if (ret)
1026 return ret;
1027 ret = pcie2cio_read(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, &val1);
1028 if (ret)
1029 return ret;
1030
1031 val0 &= ~PHY_PORT_CS1_LINK_DISABLE;
1032 ret = pcie2cio_write(icm, TB_CFG_PORT, port0, PHY_PORT_CS1, val0);
1033 if (ret)
1034 return ret;
1035
1036 val1 &= ~PHY_PORT_CS1_LINK_DISABLE;
1037 return pcie2cio_write(icm, TB_CFG_PORT, port1, PHY_PORT_CS1, val1);
1038}
1039
1040static int icm_firmware_init(struct tb *tb)
1041{
1042 struct icm *icm = tb_priv(tb);
1043 struct tb_nhi *nhi = tb->nhi;
1044 int ret;
1045
1046 ret = icm_firmware_start(tb, nhi);
1047 if (ret) {
1048 dev_err(&nhi->pdev->dev, "could not start ICM firmware\n");
1049 return ret;
1050 }
1051
1052 if (icm->get_mode) {
1053 ret = icm->get_mode(tb);
1054
1055 switch (ret) {
Mika Westerberge6b245c2017-06-06 15:25:17 +03001056 case NHI_FW_SAFE_MODE:
1057 icm->safe_mode = true;
1058 break;
1059
Mika Westerbergf67cf492017-06-06 15:25:16 +03001060 case NHI_FW_CM_MODE:
1061 /* Ask ICM to accept all Thunderbolt devices */
1062 nhi_mailbox_cmd(nhi, NHI_MAILBOX_ALLOW_ALL_DEVS, 0);
1063 break;
1064
1065 default:
1066 tb_err(tb, "ICM firmware is in wrong mode: %u\n", ret);
1067 return -ENODEV;
1068 }
1069 }
1070
1071 /*
1072 * Reset both physical ports if there is anything connected to
1073 * them already.
1074 */
1075 ret = icm_reset_phy_port(tb, 0);
1076 if (ret)
1077 dev_warn(&nhi->pdev->dev, "failed to reset links on port0\n");
1078 ret = icm_reset_phy_port(tb, 1);
1079 if (ret)
1080 dev_warn(&nhi->pdev->dev, "failed to reset links on port1\n");
1081
1082 return 0;
1083}
1084
1085static int icm_driver_ready(struct tb *tb)
1086{
Mika Westerberge6b245c2017-06-06 15:25:17 +03001087 struct icm *icm = tb_priv(tb);
Mika Westerbergf67cf492017-06-06 15:25:16 +03001088 int ret;
1089
1090 ret = icm_firmware_init(tb);
1091 if (ret)
1092 return ret;
1093
Mika Westerberge6b245c2017-06-06 15:25:17 +03001094 if (icm->safe_mode) {
1095 tb_info(tb, "Thunderbolt host controller is in safe mode.\n");
1096 tb_info(tb, "You need to update NVM firmware of the controller before it can be used.\n");
1097 tb_info(tb, "For latest updates check https://thunderbolttechnology.net/updates.\n");
1098 return 0;
1099 }
1100
Mika Westerbergf67cf492017-06-06 15:25:16 +03001101 return __icm_driver_ready(tb, &tb->security_level);
1102}
1103
1104static int icm_suspend(struct tb *tb)
1105{
Rafael J. Wysockia684c5b2017-07-25 01:31:00 +02001106 int ret;
1107
1108 ret = nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_SAVE_DEVS, 0);
1109 if (ret)
1110 tb_info(tb, "Ignoring mailbox command error (%d) in %s\n",
1111 ret, __func__);
1112
1113 return 0;
Mika Westerbergf67cf492017-06-06 15:25:16 +03001114}
1115
1116/*
1117 * Mark all switches (except root switch) below this one unplugged. ICM
1118 * firmware will send us an updated list of switches after we have send
1119 * it driver ready command. If a switch is not in that list it will be
1120 * removed when we perform rescan.
1121 */
1122static void icm_unplug_children(struct tb_switch *sw)
1123{
1124 unsigned int i;
1125
1126 if (tb_route(sw))
1127 sw->is_unplugged = true;
1128
1129 for (i = 1; i <= sw->config.max_port_number; i++) {
1130 struct tb_port *port = &sw->ports[i];
1131
1132 if (tb_is_upstream_port(port))
1133 continue;
Mika Westerbergd1ff7022017-10-02 13:38:34 +03001134 if (port->xdomain) {
1135 port->xdomain->is_unplugged = true;
1136 continue;
1137 }
Mika Westerbergf67cf492017-06-06 15:25:16 +03001138 if (!port->remote)
1139 continue;
1140
1141 icm_unplug_children(port->remote->sw);
1142 }
1143}
1144
1145static void icm_free_unplugged_children(struct tb_switch *sw)
1146{
1147 unsigned int i;
1148
1149 for (i = 1; i <= sw->config.max_port_number; i++) {
1150 struct tb_port *port = &sw->ports[i];
1151
1152 if (tb_is_upstream_port(port))
1153 continue;
Mika Westerbergd1ff7022017-10-02 13:38:34 +03001154
1155 if (port->xdomain && port->xdomain->is_unplugged) {
1156 tb_xdomain_remove(port->xdomain);
1157 port->xdomain = NULL;
1158 continue;
1159 }
1160
Mika Westerbergf67cf492017-06-06 15:25:16 +03001161 if (!port->remote)
1162 continue;
1163
1164 if (port->remote->sw->is_unplugged) {
1165 tb_switch_remove(port->remote->sw);
1166 port->remote = NULL;
1167 } else {
1168 icm_free_unplugged_children(port->remote->sw);
1169 }
1170 }
1171}
1172
1173static void icm_rescan_work(struct work_struct *work)
1174{
1175 struct icm *icm = container_of(work, struct icm, rescan_work.work);
1176 struct tb *tb = icm_to_tb(icm);
1177
1178 mutex_lock(&tb->lock);
1179 if (tb->root_switch)
1180 icm_free_unplugged_children(tb->root_switch);
1181 mutex_unlock(&tb->lock);
1182}
1183
1184static void icm_complete(struct tb *tb)
1185{
1186 struct icm *icm = tb_priv(tb);
1187
1188 if (tb->nhi->going_away)
1189 return;
1190
1191 icm_unplug_children(tb->root_switch);
1192
1193 /*
1194 * Now all existing children should be resumed, start events
1195 * from ICM to get updated status.
1196 */
1197 __icm_driver_ready(tb, NULL);
1198
1199 /*
1200 * We do not get notifications of devices that have been
1201 * unplugged during suspend so schedule rescan to clean them up
1202 * if any.
1203 */
1204 queue_delayed_work(tb->wq, &icm->rescan_work, msecs_to_jiffies(500));
1205}
1206
1207static int icm_start(struct tb *tb)
1208{
Mika Westerberge6b245c2017-06-06 15:25:17 +03001209 struct icm *icm = tb_priv(tb);
Mika Westerbergf67cf492017-06-06 15:25:16 +03001210 int ret;
1211
Mika Westerberge6b245c2017-06-06 15:25:17 +03001212 if (icm->safe_mode)
1213 tb->root_switch = tb_switch_alloc_safe_mode(tb, &tb->dev, 0);
1214 else
1215 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0);
Mika Westerbergf67cf492017-06-06 15:25:16 +03001216 if (!tb->root_switch)
1217 return -ENODEV;
1218
Mika Westerberge6b245c2017-06-06 15:25:17 +03001219 /*
1220 * NVM upgrade has not been tested on Apple systems and they
1221 * don't provide images publicly either. To be on the safe side
1222 * prevent root switch NVM upgrade on Macs for now.
1223 */
Lukas Wunner630b3af2017-08-01 14:10:41 +02001224 tb->root_switch->no_nvm_upgrade = x86_apple_machine;
Mika Westerberge6b245c2017-06-06 15:25:17 +03001225
Mika Westerbergf67cf492017-06-06 15:25:16 +03001226 ret = tb_switch_add(tb->root_switch);
Mika Westerbergd1ff7022017-10-02 13:38:34 +03001227 if (ret) {
Mika Westerbergf67cf492017-06-06 15:25:16 +03001228 tb_switch_put(tb->root_switch);
Mika Westerbergd1ff7022017-10-02 13:38:34 +03001229 tb->root_switch = NULL;
1230 }
Mika Westerbergf67cf492017-06-06 15:25:16 +03001231
1232 return ret;
1233}
1234
1235static void icm_stop(struct tb *tb)
1236{
1237 struct icm *icm = tb_priv(tb);
1238
1239 cancel_delayed_work(&icm->rescan_work);
1240 tb_switch_remove(tb->root_switch);
1241 tb->root_switch = NULL;
1242 nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DRV_UNLOADS, 0);
1243}
1244
Mika Westerberge6b245c2017-06-06 15:25:17 +03001245static int icm_disconnect_pcie_paths(struct tb *tb)
1246{
1247 return nhi_mailbox_cmd(tb->nhi, NHI_MAILBOX_DISCONNECT_PCIE_PATHS, 0);
1248}
1249
Mika Westerbergf67cf492017-06-06 15:25:16 +03001250/* Falcon Ridge and Alpine Ridge */
1251static const struct tb_cm_ops icm_fr_ops = {
1252 .driver_ready = icm_driver_ready,
1253 .start = icm_start,
1254 .stop = icm_stop,
1255 .suspend = icm_suspend,
1256 .complete = icm_complete,
1257 .handle_event = icm_handle_event,
1258 .approve_switch = icm_fr_approve_switch,
1259 .add_switch_key = icm_fr_add_switch_key,
1260 .challenge_switch_key = icm_fr_challenge_switch_key,
Mika Westerberge6b245c2017-06-06 15:25:17 +03001261 .disconnect_pcie_paths = icm_disconnect_pcie_paths,
Mika Westerbergd1ff7022017-10-02 13:38:34 +03001262 .approve_xdomain_paths = icm_fr_approve_xdomain_paths,
1263 .disconnect_xdomain_paths = icm_fr_disconnect_xdomain_paths,
Mika Westerbergf67cf492017-06-06 15:25:16 +03001264};
1265
1266struct tb *icm_probe(struct tb_nhi *nhi)
1267{
1268 struct icm *icm;
1269 struct tb *tb;
1270
1271 tb = tb_domain_alloc(nhi, sizeof(struct icm));
1272 if (!tb)
1273 return NULL;
1274
1275 icm = tb_priv(tb);
1276 INIT_DELAYED_WORK(&icm->rescan_work, icm_rescan_work);
1277 mutex_init(&icm->request_lock);
1278
1279 switch (nhi->pdev->device) {
1280 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI:
1281 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI:
1282 icm->is_supported = icm_fr_is_supported;
1283 icm->get_route = icm_fr_get_route;
1284 icm->device_connected = icm_fr_device_connected;
1285 icm->device_disconnected = icm_fr_device_disconnected;
Mika Westerbergd1ff7022017-10-02 13:38:34 +03001286 icm->xdomain_connected = icm_fr_xdomain_connected;
1287 icm->xdomain_disconnected = icm_fr_xdomain_disconnected;
Mika Westerbergf67cf492017-06-06 15:25:16 +03001288 tb->cm_ops = &icm_fr_ops;
1289 break;
1290
1291 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_NHI:
1292 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_4C_NHI:
1293 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_NHI:
1294 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_NHI:
1295 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_NHI:
1296 icm->is_supported = icm_ar_is_supported;
1297 icm->get_mode = icm_ar_get_mode;
1298 icm->get_route = icm_ar_get_route;
1299 icm->device_connected = icm_fr_device_connected;
1300 icm->device_disconnected = icm_fr_device_disconnected;
Mika Westerbergd1ff7022017-10-02 13:38:34 +03001301 icm->xdomain_connected = icm_fr_xdomain_connected;
1302 icm->xdomain_disconnected = icm_fr_xdomain_disconnected;
Mika Westerbergf67cf492017-06-06 15:25:16 +03001303 tb->cm_ops = &icm_fr_ops;
1304 break;
1305 }
1306
1307 if (!icm->is_supported || !icm->is_supported(tb)) {
1308 dev_dbg(&nhi->pdev->dev, "ICM not supported on this controller\n");
1309 tb_domain_put(tb);
1310 return NULL;
1311 }
1312
1313 return tb;
1314}