Skip to content

Commit 57e50f4

Browse files
committed
Merge tag 'thunderbolt-for-v6.6-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-linus
Mika writes: thunderbolt: Fixes for v6.6-rc3 This includes following fixes for v6.6-rc3: - Add a workaround for IOMMU faults for certain systems with Intel Maple Ridge - Make sure lane 1 is in CL0 before bonding lanes - Correct TMU mode initialization from hardware - Restart XDomain discovery handshake after failure. All these have been in linux-next with no reported issues. * tag 'thunderbolt-for-v6.6-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt: thunderbolt: Restart XDomain discovery handshake after failure thunderbolt: Correct TMU mode initialization from hardware thunderbolt: Check that lane 1 is in CL0 before enabling lane bonding thunderbolt: Workaround an IOMMU fault on certain systems with Intel Maple Ridge
2 parents 8a749fd + 308092d commit 57e50f4

File tree

4 files changed

+69
-38
lines changed

4 files changed

+69
-38
lines changed

drivers/thunderbolt/icm.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define PHY_PORT_CS1_LINK_STATE_SHIFT 26
4242

4343
#define ICM_TIMEOUT 5000 /* ms */
44+
#define ICM_RETRIES 3
4445
#define ICM_APPROVE_TIMEOUT 10000 /* ms */
4546
#define ICM_MAX_LINK 4
4647

@@ -296,10 +297,9 @@ static bool icm_copy(struct tb_cfg_request *req, const struct ctl_pkg *pkg)
296297

297298
static int icm_request(struct tb *tb, const void *request, size_t request_size,
298299
void *response, size_t response_size, size_t npackets,
299-
unsigned int timeout_msec)
300+
int retries, unsigned int timeout_msec)
300301
{
301302
struct icm *icm = tb_priv(tb);
302-
int retries = 3;
303303

304304
do {
305305
struct tb_cfg_request *req;
@@ -410,7 +410,7 @@ static int icm_fr_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
410410
return -ENOMEM;
411411

412412
ret = icm_request(tb, &request, sizeof(request), switches,
413-
sizeof(*switches), npackets, ICM_TIMEOUT);
413+
sizeof(*switches), npackets, ICM_RETRIES, ICM_TIMEOUT);
414414
if (ret)
415415
goto err_free;
416416

@@ -463,7 +463,7 @@ icm_fr_driver_ready(struct tb *tb, enum tb_security_level *security_level,
463463

464464
memset(&reply, 0, sizeof(reply));
465465
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
466-
1, ICM_TIMEOUT);
466+
1, ICM_RETRIES, ICM_TIMEOUT);
467467
if (ret)
468468
return ret;
469469

@@ -488,7 +488,7 @@ static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw)
488488
memset(&reply, 0, sizeof(reply));
489489
/* Use larger timeout as establishing tunnels can take some time */
490490
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
491-
1, ICM_APPROVE_TIMEOUT);
491+
1, ICM_RETRIES, ICM_APPROVE_TIMEOUT);
492492
if (ret)
493493
return ret;
494494

@@ -515,7 +515,7 @@ static int icm_fr_add_switch_key(struct tb *tb, struct tb_switch *sw)
515515

516516
memset(&reply, 0, sizeof(reply));
517517
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
518-
1, ICM_TIMEOUT);
518+
1, ICM_RETRIES, ICM_TIMEOUT);
519519
if (ret)
520520
return ret;
521521

@@ -543,7 +543,7 @@ static int icm_fr_challenge_switch_key(struct tb *tb, struct tb_switch *sw,
543543

544544
memset(&reply, 0, sizeof(reply));
545545
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
546-
1, ICM_TIMEOUT);
546+
1, ICM_RETRIES, ICM_TIMEOUT);
547547
if (ret)
548548
return ret;
549549

@@ -577,7 +577,7 @@ static int icm_fr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
577577

578578
memset(&reply, 0, sizeof(reply));
579579
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
580-
1, ICM_TIMEOUT);
580+
1, ICM_RETRIES, ICM_TIMEOUT);
581581
if (ret)
582582
return ret;
583583

@@ -1020,7 +1020,7 @@ icm_tr_driver_ready(struct tb *tb, enum tb_security_level *security_level,
10201020

10211021
memset(&reply, 0, sizeof(reply));
10221022
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1023-
1, 20000);
1023+
1, 10, 2000);
10241024
if (ret)
10251025
return ret;
10261026

@@ -1053,7 +1053,7 @@ static int icm_tr_approve_switch(struct tb *tb, struct tb_switch *sw)
10531053

10541054
memset(&reply, 0, sizeof(reply));
10551055
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1056-
1, ICM_APPROVE_TIMEOUT);
1056+
1, ICM_RETRIES, ICM_APPROVE_TIMEOUT);
10571057
if (ret)
10581058
return ret;
10591059

@@ -1081,7 +1081,7 @@ static int icm_tr_add_switch_key(struct tb *tb, struct tb_switch *sw)
10811081

10821082
memset(&reply, 0, sizeof(reply));
10831083
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1084-
1, ICM_TIMEOUT);
1084+
1, ICM_RETRIES, ICM_TIMEOUT);
10851085
if (ret)
10861086
return ret;
10871087

@@ -1110,7 +1110,7 @@ static int icm_tr_challenge_switch_key(struct tb *tb, struct tb_switch *sw,
11101110

11111111
memset(&reply, 0, sizeof(reply));
11121112
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1113-
1, ICM_TIMEOUT);
1113+
1, ICM_RETRIES, ICM_TIMEOUT);
11141114
if (ret)
11151115
return ret;
11161116

@@ -1144,7 +1144,7 @@ static int icm_tr_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
11441144

11451145
memset(&reply, 0, sizeof(reply));
11461146
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1147-
1, ICM_TIMEOUT);
1147+
1, ICM_RETRIES, ICM_TIMEOUT);
11481148
if (ret)
11491149
return ret;
11501150

@@ -1170,7 +1170,7 @@ static int icm_tr_xdomain_tear_down(struct tb *tb, struct tb_xdomain *xd,
11701170

11711171
memset(&reply, 0, sizeof(reply));
11721172
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1173-
1, ICM_TIMEOUT);
1173+
1, ICM_RETRIES, ICM_TIMEOUT);
11741174
if (ret)
11751175
return ret;
11761176

@@ -1496,7 +1496,7 @@ icm_ar_driver_ready(struct tb *tb, enum tb_security_level *security_level,
14961496

14971497
memset(&reply, 0, sizeof(reply));
14981498
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1499-
1, ICM_TIMEOUT);
1499+
1, ICM_RETRIES, ICM_TIMEOUT);
15001500
if (ret)
15011501
return ret;
15021502

@@ -1522,7 +1522,7 @@ static int icm_ar_get_route(struct tb *tb, u8 link, u8 depth, u64 *route)
15221522

15231523
memset(&reply, 0, sizeof(reply));
15241524
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1525-
1, ICM_TIMEOUT);
1525+
1, ICM_RETRIES, ICM_TIMEOUT);
15261526
if (ret)
15271527
return ret;
15281528

@@ -1543,7 +1543,7 @@ static int icm_ar_get_boot_acl(struct tb *tb, uuid_t *uuids, size_t nuuids)
15431543

15441544
memset(&reply, 0, sizeof(reply));
15451545
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1546-
1, ICM_TIMEOUT);
1546+
1, ICM_RETRIES, ICM_TIMEOUT);
15471547
if (ret)
15481548
return ret;
15491549

@@ -1604,7 +1604,7 @@ static int icm_ar_set_boot_acl(struct tb *tb, const uuid_t *uuids,
16041604

16051605
memset(&reply, 0, sizeof(reply));
16061606
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1607-
1, ICM_TIMEOUT);
1607+
1, ICM_RETRIES, ICM_TIMEOUT);
16081608
if (ret)
16091609
return ret;
16101610

@@ -1626,7 +1626,7 @@ icm_icl_driver_ready(struct tb *tb, enum tb_security_level *security_level,
16261626

16271627
memset(&reply, 0, sizeof(reply));
16281628
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
1629-
1, 20000);
1629+
1, ICM_RETRIES, 20000);
16301630
if (ret)
16311631
return ret;
16321632

@@ -2298,7 +2298,7 @@ static int icm_usb4_switch_op(struct tb_switch *sw, u16 opcode, u32 *metadata,
22982298

22992299
memset(&reply, 0, sizeof(reply));
23002300
ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply),
2301-
1, ICM_TIMEOUT);
2301+
1, ICM_RETRIES, ICM_TIMEOUT);
23022302
if (ret)
23032303
return ret;
23042304

drivers/thunderbolt/switch.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,6 +2725,13 @@ int tb_switch_lane_bonding_enable(struct tb_switch *sw)
27252725
!tb_port_is_width_supported(down, TB_LINK_WIDTH_DUAL))
27262726
return 0;
27272727

2728+
/*
2729+
* Both lanes need to be in CL0. Here we assume lane 0 already be in
2730+
* CL0 and check just for lane 1.
2731+
*/
2732+
if (tb_wait_for_port(down->dual_link_port, false) <= 0)
2733+
return -ENOTCONN;
2734+
27282735
ret = tb_port_lane_bonding_enable(up);
27292736
if (ret) {
27302737
tb_port_warn(up, "failed to enable lane bonding\n");

drivers/thunderbolt/tmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int tmu_mode_init(struct tb_switch *sw)
382382
} else if (ucap && tb_port_tmu_is_unidirectional(up)) {
383383
if (tmu_rates[TB_SWITCH_TMU_MODE_LOWRES] == rate)
384384
sw->tmu.mode = TB_SWITCH_TMU_MODE_LOWRES;
385-
else if (tmu_rates[TB_SWITCH_TMU_MODE_LOWRES] == rate)
385+
else if (tmu_rates[TB_SWITCH_TMU_MODE_HIFI_UNI] == rate)
386386
sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_UNI;
387387
} else if (rate) {
388388
sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_BI;

drivers/thunderbolt/xdomain.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,27 @@ static void update_property_block(struct tb_xdomain *xd)
703703
mutex_unlock(&xdomain_lock);
704704
}
705705

706+
static void start_handshake(struct tb_xdomain *xd)
707+
{
708+
xd->state = XDOMAIN_STATE_INIT;
709+
queue_delayed_work(xd->tb->wq, &xd->state_work,
710+
msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT));
711+
}
712+
713+
/* Can be called from state_work */
714+
static void __stop_handshake(struct tb_xdomain *xd)
715+
{
716+
cancel_delayed_work_sync(&xd->properties_changed_work);
717+
xd->properties_changed_retries = 0;
718+
xd->state_retries = 0;
719+
}
720+
721+
static void stop_handshake(struct tb_xdomain *xd)
722+
{
723+
cancel_delayed_work_sync(&xd->state_work);
724+
__stop_handshake(xd);
725+
}
726+
706727
static void tb_xdp_handle_request(struct work_struct *work)
707728
{
708729
struct xdomain_request_work *xw = container_of(work, typeof(*xw), work);
@@ -765,6 +786,15 @@ static void tb_xdp_handle_request(struct work_struct *work)
765786
case UUID_REQUEST:
766787
tb_dbg(tb, "%llx: received XDomain UUID request\n", route);
767788
ret = tb_xdp_uuid_response(ctl, route, sequence, uuid);
789+
/*
790+
* If we've stopped the discovery with an error such as
791+
* timing out, we will restart the handshake now that we
792+
* received UUID request from the remote host.
793+
*/
794+
if (!ret && xd && xd->state == XDOMAIN_STATE_ERROR) {
795+
dev_dbg(&xd->dev, "restarting handshake\n");
796+
start_handshake(xd);
797+
}
768798
break;
769799

770800
case LINK_STATE_STATUS_REQUEST:
@@ -1521,6 +1551,13 @@ static void tb_xdomain_queue_properties_changed(struct tb_xdomain *xd)
15211551
msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT));
15221552
}
15231553

1554+
static void tb_xdomain_failed(struct tb_xdomain *xd)
1555+
{
1556+
xd->state = XDOMAIN_STATE_ERROR;
1557+
queue_delayed_work(xd->tb->wq, &xd->state_work,
1558+
msecs_to_jiffies(XDOMAIN_DEFAULT_TIMEOUT));
1559+
}
1560+
15241561
static void tb_xdomain_state_work(struct work_struct *work)
15251562
{
15261563
struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work);
@@ -1547,7 +1584,7 @@ static void tb_xdomain_state_work(struct work_struct *work)
15471584
if (ret) {
15481585
if (ret == -EAGAIN)
15491586
goto retry_state;
1550-
xd->state = XDOMAIN_STATE_ERROR;
1587+
tb_xdomain_failed(xd);
15511588
} else {
15521589
tb_xdomain_queue_properties_changed(xd);
15531590
if (xd->bonding_possible)
@@ -1612,7 +1649,7 @@ static void tb_xdomain_state_work(struct work_struct *work)
16121649
if (ret) {
16131650
if (ret == -EAGAIN)
16141651
goto retry_state;
1615-
xd->state = XDOMAIN_STATE_ERROR;
1652+
tb_xdomain_failed(xd);
16161653
} else {
16171654
xd->state = XDOMAIN_STATE_ENUMERATED;
16181655
}
@@ -1623,6 +1660,8 @@ static void tb_xdomain_state_work(struct work_struct *work)
16231660
break;
16241661

16251662
case XDOMAIN_STATE_ERROR:
1663+
dev_dbg(&xd->dev, "discovery failed, stopping handshake\n");
1664+
__stop_handshake(xd);
16261665
break;
16271666

16281667
default:
@@ -1833,21 +1872,6 @@ static void tb_xdomain_release(struct device *dev)
18331872
kfree(xd);
18341873
}
18351874

1836-
static void start_handshake(struct tb_xdomain *xd)
1837-
{
1838-
xd->state = XDOMAIN_STATE_INIT;
1839-
queue_delayed_work(xd->tb->wq, &xd->state_work,
1840-
msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT));
1841-
}
1842-
1843-
static void stop_handshake(struct tb_xdomain *xd)
1844-
{
1845-
cancel_delayed_work_sync(&xd->properties_changed_work);
1846-
cancel_delayed_work_sync(&xd->state_work);
1847-
xd->properties_changed_retries = 0;
1848-
xd->state_retries = 0;
1849-
}
1850-
18511875
static int __maybe_unused tb_xdomain_suspend(struct device *dev)
18521876
{
18531877
stop_handshake(tb_to_xdomain(dev));

0 commit comments

Comments
 (0)