Skip to content

Commit f794890

Browse files
committed
drm/dp_mst: Clear all payload id tables downstream when initializing
It seems that on certain MST hubs, namely the CableMatters USB-C 2x DP hub, using the DP_PAYLOAD_ALLOCATE_SET and DP_PAYLOAD_TABLE_UPDATE_STATUS register ranges to clear any pre-existing payload allocations on the hub isn't always enough to reset things if the source device has been reset unexpectedly. Or at least, that's the current running theory. The precise behavior appears to be that when the source device gets reset unexpectedly, the hub begins reporting an available_pbn value of 0 for all of its ports. This is a bit inconsistent with the our theory, since this seems to happen even if previously set PBN allocations should have resulted in a non-zero available_pbn value. So, it's possible that something else may be going on here. Strangely though, sending a CLEAR_PAYLOAD_ID_TABLE broadcast request when initializing the MST topology seems to bring things into working order and make available_pbn work again. Since this is a pretty safe solution, let's go ahead and implement it. Changes since v1: * Change indenting on drm_dp_send_clear_payload_id_table() prototype * Remove some braces in drm_dp_send_clear_payload_id_table() * Reorganize some variable declarations in drm_dp_send_clear_payload_id_table() * Don't forget to handle DP_CLEAR_PAYLOAD_ID_TABLE in drm_dp_sideband_parse_reply() * Move drm_dp_send_clear_payload_id_table() call into drm_dp_mst_link_probe_work(), since we can't send sideband messages while under lock in drm_dp_mst_topology_mgr_set_mst() * Change commit message Acked-by: Daniel Vetter <daniel@ffwll.ch> Signed-off-by: Sean Paul <seanpaul@chromium.org> Signed-off-by: Lyude Paul <lyude@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20190829000944.20722-1-lyude@redhat.com
1 parent c0826f4 commit f794890

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

‎drivers/gpu/drm/drm_dp_mst_topology.c‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ static int drm_dp_send_dpcd_write(struct drm_dp_mst_topology_mgr *mgr,
6363

6464
static void drm_dp_send_link_address(struct drm_dp_mst_topology_mgr *mgr,
6565
struct drm_dp_mst_branch *mstb);
66+
67+
static void
68+
drm_dp_send_clear_payload_id_table(struct drm_dp_mst_topology_mgr *mgr,
69+
struct drm_dp_mst_branch *mstb);
70+
6671
static int drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr,
6772
struct drm_dp_mst_branch *mstb,
6873
struct drm_dp_mst_port *port);
@@ -939,6 +944,8 @@ static bool drm_dp_sideband_parse_reply(struct drm_dp_sideband_msg_rx *raw,
939944
case DP_POWER_DOWN_PHY:
940945
case DP_POWER_UP_PHY:
941946
return drm_dp_sideband_parse_power_updown_phy_ack(raw, msg);
947+
case DP_CLEAR_PAYLOAD_ID_TABLE:
948+
return true; /* since there's nothing to parse */
942949
default:
943950
DRM_ERROR("Got unknown reply 0x%02x (%s)\n", msg->req_type,
944951
drm_dp_mst_req_type_str(msg->req_type));
@@ -1037,6 +1044,15 @@ static int build_link_address(struct drm_dp_sideband_msg_tx *msg)
10371044
return 0;
10381045
}
10391046

1047+
static int build_clear_payload_id_table(struct drm_dp_sideband_msg_tx *msg)
1048+
{
1049+
struct drm_dp_sideband_msg_req_body req;
1050+
1051+
req.req_type = DP_CLEAR_PAYLOAD_ID_TABLE;
1052+
drm_dp_encode_sideband_req(&req, msg);
1053+
return 0;
1054+
}
1055+
10401056
static int build_enum_path_resources(struct drm_dp_sideband_msg_tx *msg, int port_num)
10411057
{
10421058
struct drm_dp_sideband_msg_req_body req;
@@ -2166,19 +2182,37 @@ static void drm_dp_mst_link_probe_work(struct work_struct *work)
21662182
struct drm_dp_mst_topology_mgr *mgr = container_of(work, struct drm_dp_mst_topology_mgr, work);
21672183
struct drm_dp_mst_branch *mstb;
21682184
int ret;
2185+
bool clear_payload_id_table;
21692186

21702187
mutex_lock(&mgr->lock);
2188+
clear_payload_id_table = !mgr->payload_id_table_cleared;
2189+
mgr->payload_id_table_cleared = true;
2190+
21712191
mstb = mgr->mst_primary;
21722192
if (mstb) {
21732193
ret = drm_dp_mst_topology_try_get_mstb(mstb);
21742194
if (!ret)
21752195
mstb = NULL;
21762196
}
21772197
mutex_unlock(&mgr->lock);
2178-
if (mstb) {
2179-
drm_dp_check_and_send_link_address(mgr, mstb);
2180-
drm_dp_mst_topology_put_mstb(mstb);
2198+
if (!mstb)
2199+
return;
2200+
2201+
/*
2202+
* Certain branch devices seem to incorrectly report an available_pbn
2203+
* of 0 on downstream sinks, even after clearing the
2204+
* DP_PAYLOAD_ALLOCATE_* registers in
2205+
* drm_dp_mst_topology_mgr_set_mst(). Namely, the CableMatters USB-C
2206+
* 2x DP hub. Sending a CLEAR_PAYLOAD_ID_TABLE message seems to make
2207+
* things work again.
2208+
*/
2209+
if (clear_payload_id_table) {
2210+
DRM_DEBUG_KMS("Clearing payload ID table\n");
2211+
drm_dp_send_clear_payload_id_table(mgr, mstb);
21812212
}
2213+
2214+
drm_dp_check_and_send_link_address(mgr, mstb);
2215+
drm_dp_mst_topology_put_mstb(mstb);
21822216
}
21832217

21842218
static bool drm_dp_validate_guid(struct drm_dp_mst_topology_mgr *mgr,
@@ -2471,6 +2505,28 @@ static void drm_dp_send_link_address(struct drm_dp_mst_topology_mgr *mgr,
24712505
kfree(txmsg);
24722506
}
24732507

2508+
void drm_dp_send_clear_payload_id_table(struct drm_dp_mst_topology_mgr *mgr,
2509+
struct drm_dp_mst_branch *mstb)
2510+
{
2511+
struct drm_dp_sideband_msg_tx *txmsg;
2512+
int len, ret;
2513+
2514+
txmsg = kzalloc(sizeof(*txmsg), GFP_KERNEL);
2515+
if (!txmsg)
2516+
return;
2517+
2518+
txmsg->dst = mstb;
2519+
len = build_clear_payload_id_table(txmsg);
2520+
2521+
drm_dp_queue_down_tx(mgr, txmsg);
2522+
2523+
ret = drm_dp_mst_wait_tx_reply(mstb, txmsg);
2524+
if (ret > 0 && txmsg->reply.reply_type == DP_SIDEBAND_REPLY_NAK)
2525+
DRM_DEBUG_KMS("clear payload table id nak received\n");
2526+
2527+
kfree(txmsg);
2528+
}
2529+
24742530
static int
24752531
drm_dp_send_enum_path_resources(struct drm_dp_mst_topology_mgr *mgr,
24762532
struct drm_dp_mst_branch *mstb,
@@ -3062,6 +3118,7 @@ int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool ms
30623118
mgr->payload_mask = 0;
30633119
set_bit(0, &mgr->payload_mask);
30643120
mgr->vcpi_mask = 0;
3121+
mgr->payload_id_table_cleared = false;
30653122
}
30663123

30673124
out_unlock:

‎include/drm/drm_dp_mst_helper.h‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,23 @@ struct drm_dp_mst_topology_mgr {
490490
struct drm_dp_sideband_msg_rx up_req_recv;
491491

492492
/**
493-
* @lock: protects mst state, primary, dpcd.
493+
* @lock: protects @mst_state, @mst_primary, @dpcd, and
494+
* @payload_id_table_cleared.
494495
*/
495496
struct mutex lock;
496497

497498
/**
498-
* @mst_state: If this manager is enabled for an MST capable port. False
499-
* if no MST sink/branch devices is connected.
499+
* @mst_state: If this manager is enabled for an MST capable port.
500+
* False if no MST sink/branch devices is connected.
500501
*/
501-
bool mst_state;
502+
bool mst_state : 1;
503+
504+
/**
505+
* @payload_id_table_cleared: Whether or not we've cleared the payload
506+
* ID table for @mst_primary. Protected by @lock.
507+
*/
508+
bool payload_id_table_cleared : 1;
509+
502510
/**
503511
* @mst_primary: Pointer to the primary/first branch device.
504512
*/

0 commit comments

Comments
 (0)