Skip to content

Commit 72f1de4

Browse files
Wayne Linalexdeucher
authored andcommitted
drm/dp_mst: Clear MSG_RDY flag before sending new message
[Why] The sequence for collecting down_reply from source perspective should be: Request_n->repeat (get partial reply of Request_n->clear message ready flag to ack DPRX that the message is received) till all partial replies for Request_n are received->new Request_n+1. Now there is chance that drm_dp_mst_hpd_irq() will fire new down request in the tx queue when the down reply is incomplete. Source is restricted to generate interveleaved message transactions so we should avoid it. Also, while assembling partial reply packets, reading out DPCD DOWN_REP Sideband MSG buffer + clearing DOWN_REP_MSG_RDY flag should be wrapped up as a complete operation for reading out a reply packet. Kicking off a new request before clearing DOWN_REP_MSG_RDY flag might be risky. e.g. If the reply of the new request has overwritten the DPRX DOWN_REP Sideband MSG buffer before source writing one to clear DOWN_REP_MSG_RDY flag, source then unintentionally flushes the reply for the new request. Should handle the up request in the same way. [How] Separete drm_dp_mst_hpd_irq() into 2 steps. After acking the MST IRQ event, driver calls drm_dp_mst_hpd_irq_send_new_request() and might trigger drm_dp_mst_kick_tx() only when there is no on going message transaction. Changes since v1: * Reworked on review comments received -> Adjust the fix to let driver explicitly kick off new down request when mst irq event is handled and acked -> Adjust the commit message Changes since v2: * Adjust the commit message * Adjust the naming of the divided 2 functions and add a new input parameter "ack". * Adjust code flow as per review comments. Changes since v3: * Update the function description of drm_dp_mst_hpd_irq_handle_event Changes since v4: * Change ack of drm_dp_mst_hpd_irq_handle_event() to be an array align the size of esi[] Signed-off-by: Wayne Lin <[email protected]> Reviewed-by: Lyude Paul <[email protected]> Acked-by: Jani Nikula <[email protected]> Cc: [email protected] Signed-off-by: Alex Deucher <[email protected]>
1 parent 5d1c70b commit 72f1de4

File tree

5 files changed

+81
-31
lines changed

5 files changed

+81
-31
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3267,6 +3267,7 @@ static void dm_handle_mst_sideband_msg(struct amdgpu_dm_connector *aconnector)
32673267

32683268
while (dret == dpcd_bytes_to_read &&
32693269
process_count < max_process_count) {
3270+
u8 ack[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] = {};
32703271
u8 retry;
32713272
dret = 0;
32723273

@@ -3275,28 +3276,29 @@ static void dm_handle_mst_sideband_msg(struct amdgpu_dm_connector *aconnector)
32753276
DRM_DEBUG_DRIVER("ESI %02x %02x %02x\n", esi[0], esi[1], esi[2]);
32763277
/* handle HPD short pulse irq */
32773278
if (aconnector->mst_mgr.mst_state)
3278-
drm_dp_mst_hpd_irq(
3279-
&aconnector->mst_mgr,
3280-
esi,
3281-
&new_irq_handled);
3279+
drm_dp_mst_hpd_irq_handle_event(&aconnector->mst_mgr,
3280+
esi,
3281+
ack,
3282+
&new_irq_handled);
32823283

32833284
if (new_irq_handled) {
32843285
/* ACK at DPCD to notify down stream */
3285-
const int ack_dpcd_bytes_to_write =
3286-
dpcd_bytes_to_read - 1;
3287-
32883286
for (retry = 0; retry < 3; retry++) {
3289-
u8 wret;
3290-
3291-
wret = drm_dp_dpcd_write(
3292-
&aconnector->dm_dp_aux.aux,
3293-
dpcd_addr + 1,
3294-
&esi[1],
3295-
ack_dpcd_bytes_to_write);
3296-
if (wret == ack_dpcd_bytes_to_write)
3287+
ssize_t wret;
3288+
3289+
wret = drm_dp_dpcd_writeb(&aconnector->dm_dp_aux.aux,
3290+
dpcd_addr + 1,
3291+
ack[1]);
3292+
if (wret == 1)
32973293
break;
32983294
}
32993295

3296+
if (retry == 3) {
3297+
DRM_ERROR("Failed to ack MST event.\n");
3298+
return;
3299+
}
3300+
3301+
drm_dp_mst_hpd_irq_send_new_request(&aconnector->mst_mgr);
33003302
/* check if there is new irq to be handled */
33013303
dret = drm_dp_dpcd_read(
33023304
&aconnector->dm_dp_aux.aux,

drivers/gpu/drm/display/drm_dp_mst_topology.c

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4053,17 +4053,28 @@ static int drm_dp_mst_handle_up_req(struct drm_dp_mst_topology_mgr *mgr)
40534053
}
40544054

40554055
/**
4056-
* drm_dp_mst_hpd_irq() - MST hotplug IRQ notify
4056+
* drm_dp_mst_hpd_irq_handle_event() - MST hotplug IRQ handle MST event
40574057
* @mgr: manager to notify irq for.
40584058
* @esi: 4 bytes from SINK_COUNT_ESI
4059+
* @ack: 4 bytes used to ack events starting from SINK_COUNT_ESI
40594060
* @handled: whether the hpd interrupt was consumed or not
40604061
*
4061-
* This should be called from the driver when it detects a short IRQ,
4062+
* This should be called from the driver when it detects a HPD IRQ,
40624063
* along with the value of the DEVICE_SERVICE_IRQ_VECTOR_ESI0. The
4063-
* topology manager will process the sideband messages received as a result
4064-
* of this.
4064+
* topology manager will process the sideband messages received
4065+
* as indicated in the DEVICE_SERVICE_IRQ_VECTOR_ESI0 and set the
4066+
* corresponding flags that Driver has to ack the DP receiver later.
4067+
*
4068+
* Note that driver shall also call
4069+
* drm_dp_mst_hpd_irq_send_new_request() if the 'handled' is set
4070+
* after calling this function, to try to kick off a new request in
4071+
* the queue if the previous message transaction is completed.
4072+
*
4073+
* See also:
4074+
* drm_dp_mst_hpd_irq_send_new_request()
40654075
*/
4066-
int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled)
4076+
int drm_dp_mst_hpd_irq_handle_event(struct drm_dp_mst_topology_mgr *mgr, const u8 *esi,
4077+
u8 *ack, bool *handled)
40674078
{
40684079
int ret = 0;
40694080
int sc;
@@ -4078,18 +4089,47 @@ int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handl
40784089
if (esi[1] & DP_DOWN_REP_MSG_RDY) {
40794090
ret = drm_dp_mst_handle_down_rep(mgr);
40804091
*handled = true;
4092+
ack[1] |= DP_DOWN_REP_MSG_RDY;
40814093
}
40824094

40834095
if (esi[1] & DP_UP_REQ_MSG_RDY) {
40844096
ret |= drm_dp_mst_handle_up_req(mgr);
40854097
*handled = true;
4098+
ack[1] |= DP_UP_REQ_MSG_RDY;
40864099
}
40874100

4088-
drm_dp_mst_kick_tx(mgr);
40894101
return ret;
40904102
}
4091-
EXPORT_SYMBOL(drm_dp_mst_hpd_irq);
4103+
EXPORT_SYMBOL(drm_dp_mst_hpd_irq_handle_event);
40924104

4105+
/**
4106+
* drm_dp_mst_hpd_irq_send_new_request() - MST hotplug IRQ kick off new request
4107+
* @mgr: manager to notify irq for.
4108+
*
4109+
* This should be called from the driver when mst irq event is handled
4110+
* and acked. Note that new down request should only be sent when
4111+
* previous message transaction is completed. Source is not supposed to generate
4112+
* interleaved message transactions.
4113+
*/
4114+
void drm_dp_mst_hpd_irq_send_new_request(struct drm_dp_mst_topology_mgr *mgr)
4115+
{
4116+
struct drm_dp_sideband_msg_tx *txmsg;
4117+
bool kick = true;
4118+
4119+
mutex_lock(&mgr->qlock);
4120+
txmsg = list_first_entry_or_null(&mgr->tx_msg_downq,
4121+
struct drm_dp_sideband_msg_tx, next);
4122+
/* If last transaction is not completed yet*/
4123+
if (!txmsg ||
4124+
txmsg->state == DRM_DP_SIDEBAND_TX_START_SEND ||
4125+
txmsg->state == DRM_DP_SIDEBAND_TX_SENT)
4126+
kick = false;
4127+
mutex_unlock(&mgr->qlock);
4128+
4129+
if (kick)
4130+
drm_dp_mst_kick_tx(mgr);
4131+
}
4132+
EXPORT_SYMBOL(drm_dp_mst_hpd_irq_send_new_request);
40934133
/**
40944134
* drm_dp_mst_detect_port() - get connection status for an MST port
40954135
* @connector: DRM connector for this port

drivers/gpu/drm/i915/display/intel_dp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,9 +4069,7 @@ intel_dp_mst_hpd_irq(struct intel_dp *intel_dp, u8 *esi, u8 *ack)
40694069
{
40704070
bool handled = false;
40714071

4072-
drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4073-
if (handled)
4074-
ack[1] |= esi[1] & (DP_DOWN_REP_MSG_RDY | DP_UP_REQ_MSG_RDY);
4072+
drm_dp_mst_hpd_irq_handle_event(&intel_dp->mst_mgr, esi, ack, &handled);
40754073

40764074
if (esi[1] & DP_CP_IRQ) {
40774075
intel_hdcp_handle_cp_irq(intel_dp->attached_connector);
@@ -4146,6 +4144,9 @@ intel_dp_check_mst_status(struct intel_dp *intel_dp)
41464144

41474145
if (!intel_dp_ack_sink_irq_esi(intel_dp, ack))
41484146
drm_dbg_kms(&i915->drm, "Failed to ack ESI\n");
4147+
4148+
if (ack[1] & (DP_DOWN_REP_MSG_RDY | DP_UP_REQ_MSG_RDY))
4149+
drm_dp_mst_hpd_irq_send_new_request(&intel_dp->mst_mgr);
41494150
}
41504151

41514152
return link_ok;

drivers/gpu/drm/nouveau/dispnv50/disp.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,22 +1359,26 @@ nv50_mstm_service(struct nouveau_drm *drm,
13591359
u8 esi[8] = {};
13601360

13611361
while (handled) {
1362+
u8 ack[8] = {};
1363+
13621364
rc = drm_dp_dpcd_read(aux, DP_SINK_COUNT_ESI, esi, 8);
13631365
if (rc != 8) {
13641366
ret = false;
13651367
break;
13661368
}
13671369

1368-
drm_dp_mst_hpd_irq(&mstm->mgr, esi, &handled);
1370+
drm_dp_mst_hpd_irq_handle_event(&mstm->mgr, esi, ack, &handled);
13691371
if (!handled)
13701372
break;
13711373

1372-
rc = drm_dp_dpcd_write(aux, DP_SINK_COUNT_ESI + 1, &esi[1],
1373-
3);
1374-
if (rc != 3) {
1374+
rc = drm_dp_dpcd_writeb(aux, DP_SINK_COUNT_ESI + 1, ack[1]);
1375+
1376+
if (rc != 1) {
13751377
ret = false;
13761378
break;
13771379
}
1380+
1381+
drm_dp_mst_hpd_irq_send_new_request(&mstm->mgr);
13781382
}
13791383

13801384
if (!ret)

include/drm/display/drm_dp_mst_helper.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,11 @@ void drm_dp_mst_topology_mgr_destroy(struct drm_dp_mst_topology_mgr *mgr);
810810
bool drm_dp_read_mst_cap(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
811811
int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool mst_state);
812812

813-
int drm_dp_mst_hpd_irq(struct drm_dp_mst_topology_mgr *mgr, u8 *esi, bool *handled);
814-
813+
int drm_dp_mst_hpd_irq_handle_event(struct drm_dp_mst_topology_mgr *mgr,
814+
const u8 *esi,
815+
u8 *ack,
816+
bool *handled);
817+
void drm_dp_mst_hpd_irq_send_new_request(struct drm_dp_mst_topology_mgr *mgr);
815818

816819
int
817820
drm_dp_mst_detect_port(struct drm_connector *connector,

0 commit comments

Comments
 (0)