From 7dd146696762654a335c05ce810f0ba7309fec9a Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Tue, 8 Jan 2019 11:16:41 -0800 Subject: [PATCH 1/2] usb: pd: Allow sink operations to queue when not SinkTxOk Currently user requested operations such as select_pdo, get_src_cap_ext, DR/PR swap when done in sink mode will get rejected simply because the current Rp state is SinkTxNG. But since these APIs' semantics effectively queue the request to be handled in usbpd_sm(), and there is already a check within PE_SNK_Ready to send only during SinkTxOK, the requests don't need to be rejected and should still be allowed. Since there is a blocking wait, if the Source relinquishes Rp and allows for the AMS, then the operation should be able to go through. Change-Id: I79e78d3f28fdbb3d8e43017181981a78d3decf84 Signed-off-by: Jack Pham --- drivers/usb/pd/policy_engine.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 1d18715bcb4f..60fde6ef84d5 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -3625,12 +3625,6 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role, return -EAGAIN; } - if (pd->current_state == PE_SNK_READY && - !is_sink_tx_ok(pd)) { - usbpd_err(&pd->dev, "Rp indicates SinkTxNG\n"); - return -EAGAIN; - } - mutex_lock(&pd->swap_lock); reinit_completion(&pd->is_ready); pd->send_dr_swap = true; @@ -3685,12 +3679,6 @@ static int usbpd_dr_set_property(struct dual_role_phy_instance *dual_role, return -EAGAIN; } - if (pd->current_state == PE_SNK_READY && - !is_sink_tx_ok(pd)) { - usbpd_err(&pd->dev, "Rp indicates SinkTxNG\n"); - return -EAGAIN; - } - mutex_lock(&pd->swap_lock); reinit_completion(&pd->is_ready); pd->send_pr_swap = true; @@ -3986,7 +3974,7 @@ static ssize_t select_pdo_store(struct device *dev, mutex_lock(&pd->swap_lock); /* Only allowed if we are already in explicit sink contract */ - if (pd->current_state != PE_SNK_READY || !is_sink_tx_ok(pd)) { + if (pd->current_state != PE_SNK_READY) { usbpd_err(&pd->dev, "select_pdo: Cannot select new PDO yet\n"); ret = -EBUSY; goto out; @@ -4138,7 +4126,7 @@ static int trigger_tx_msg(struct usbpd *pd, bool *msg_tx_flag) int ret = 0; /* Only allowed if we are already in explicit sink contract */ - if (pd->current_state != PE_SNK_READY || !is_sink_tx_ok(pd)) { + if (pd->current_state != PE_SNK_READY) { usbpd_err(&pd->dev, "%s: Cannot send msg\n", __func__); ret = -EBUSY; goto out; From 814c5348f56a898ca167e97173ffa1a702e19971 Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Wed, 20 Feb 2019 00:00:34 -0800 Subject: [PATCH 2/2] usb: pd: Further differentiate errors from select_pdo_store Currently -EINVAL is returned both when a select_pdo string is improperly formulated as well as when an RDO request is successfully sent but outright rejected or otherwise failed to enter a new contract. To allow userspace to differentiate these two failures, instead return -ECONNREFUSED in the latter case. Change-Id: I74378b469745d0ef414f8cae228f79741d4846a5 Signed-off-by: Jack Pham --- drivers/usb/pd/policy_engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 60fde6ef84d5..4bee5258e5cc 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -4020,7 +4020,7 @@ static ssize_t select_pdo_store(struct device *dev, if (pd->selected_pdo != pd->requested_pdo || pd->current_voltage != pd->requested_voltage) { usbpd_err(&pd->dev, "select_pdo: request rejected\n"); - ret = -EINVAL; + ret = -ECONNREFUSED; } out: