Commit 308092d0 authored by Mika Westerberg's avatar Mika Westerberg

thunderbolt: Restart XDomain discovery handshake after failure

Alex reported that after rebooting the other host the peer-to-peer link
does not come up anymore. The reason for this is that the host that was
not rebooted tries to send the UUID request only 10 times according to
the USB4 Inter-Domain spec and gives up if it does not get reply. Then
when the other side is actually ready it cannot get the link established
anymore. The USB4 Inter-Domain spec requires that the discovery protocol
is restarted in that case so implement this now.
Reported-by: default avatarAlex Balcanquall <alex@alexbal.com>
Fixes: 8e1de704 ("thunderbolt: Add support for XDomain lane bonding")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent e19f714e
...@@ -703,6 +703,27 @@ static void update_property_block(struct tb_xdomain *xd) ...@@ -703,6 +703,27 @@ static void update_property_block(struct tb_xdomain *xd)
mutex_unlock(&xdomain_lock); mutex_unlock(&xdomain_lock);
} }
static void start_handshake(struct tb_xdomain *xd)
{
xd->state = XDOMAIN_STATE_INIT;
queue_delayed_work(xd->tb->wq, &xd->state_work,
msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT));
}
/* Can be called from state_work */
static void __stop_handshake(struct tb_xdomain *xd)
{
cancel_delayed_work_sync(&xd->properties_changed_work);
xd->properties_changed_retries = 0;
xd->state_retries = 0;
}
static void stop_handshake(struct tb_xdomain *xd)
{
cancel_delayed_work_sync(&xd->state_work);
__stop_handshake(xd);
}
static void tb_xdp_handle_request(struct work_struct *work) static void tb_xdp_handle_request(struct work_struct *work)
{ {
struct xdomain_request_work *xw = container_of(work, typeof(*xw), work); 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) ...@@ -765,6 +786,15 @@ static void tb_xdp_handle_request(struct work_struct *work)
case UUID_REQUEST: case UUID_REQUEST:
tb_dbg(tb, "%llx: received XDomain UUID request\n", route); tb_dbg(tb, "%llx: received XDomain UUID request\n", route);
ret = tb_xdp_uuid_response(ctl, route, sequence, uuid); ret = tb_xdp_uuid_response(ctl, route, sequence, uuid);
/*
* If we've stopped the discovery with an error such as
* timing out, we will restart the handshake now that we
* received UUID request from the remote host.
*/
if (!ret && xd && xd->state == XDOMAIN_STATE_ERROR) {
dev_dbg(&xd->dev, "restarting handshake\n");
start_handshake(xd);
}
break; break;
case LINK_STATE_STATUS_REQUEST: case LINK_STATE_STATUS_REQUEST:
...@@ -1521,6 +1551,13 @@ static void tb_xdomain_queue_properties_changed(struct tb_xdomain *xd) ...@@ -1521,6 +1551,13 @@ static void tb_xdomain_queue_properties_changed(struct tb_xdomain *xd)
msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT)); msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT));
} }
static void tb_xdomain_failed(struct tb_xdomain *xd)
{
xd->state = XDOMAIN_STATE_ERROR;
queue_delayed_work(xd->tb->wq, &xd->state_work,
msecs_to_jiffies(XDOMAIN_DEFAULT_TIMEOUT));
}
static void tb_xdomain_state_work(struct work_struct *work) static void tb_xdomain_state_work(struct work_struct *work)
{ {
struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work); 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) ...@@ -1547,7 +1584,7 @@ static void tb_xdomain_state_work(struct work_struct *work)
if (ret) { if (ret) {
if (ret == -EAGAIN) if (ret == -EAGAIN)
goto retry_state; goto retry_state;
xd->state = XDOMAIN_STATE_ERROR; tb_xdomain_failed(xd);
} else { } else {
tb_xdomain_queue_properties_changed(xd); tb_xdomain_queue_properties_changed(xd);
if (xd->bonding_possible) if (xd->bonding_possible)
...@@ -1612,7 +1649,7 @@ static void tb_xdomain_state_work(struct work_struct *work) ...@@ -1612,7 +1649,7 @@ static void tb_xdomain_state_work(struct work_struct *work)
if (ret) { if (ret) {
if (ret == -EAGAIN) if (ret == -EAGAIN)
goto retry_state; goto retry_state;
xd->state = XDOMAIN_STATE_ERROR; tb_xdomain_failed(xd);
} else { } else {
xd->state = XDOMAIN_STATE_ENUMERATED; xd->state = XDOMAIN_STATE_ENUMERATED;
} }
...@@ -1623,6 +1660,8 @@ static void tb_xdomain_state_work(struct work_struct *work) ...@@ -1623,6 +1660,8 @@ static void tb_xdomain_state_work(struct work_struct *work)
break; break;
case XDOMAIN_STATE_ERROR: case XDOMAIN_STATE_ERROR:
dev_dbg(&xd->dev, "discovery failed, stopping handshake\n");
__stop_handshake(xd);
break; break;
default: default:
...@@ -1833,21 +1872,6 @@ static void tb_xdomain_release(struct device *dev) ...@@ -1833,21 +1872,6 @@ static void tb_xdomain_release(struct device *dev)
kfree(xd); kfree(xd);
} }
static void start_handshake(struct tb_xdomain *xd)
{
xd->state = XDOMAIN_STATE_INIT;
queue_delayed_work(xd->tb->wq, &xd->state_work,
msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT));
}
static void stop_handshake(struct tb_xdomain *xd)
{
cancel_delayed_work_sync(&xd->properties_changed_work);
cancel_delayed_work_sync(&xd->state_work);
xd->properties_changed_retries = 0;
xd->state_retries = 0;
}
static int __maybe_unused tb_xdomain_suspend(struct device *dev) static int __maybe_unused tb_xdomain_suspend(struct device *dev)
{ {
stop_handshake(tb_to_xdomain(dev)); stop_handshake(tb_to_xdomain(dev));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment