diff options
author | Ayushee <ayushee.shah@intel.com> | 2020-01-30 14:35:18 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-03 22:49:30 +0000 |
commit | ae9aea55280abdf2febb362cd9af7be656614eb2 (patch) | |
tree | 286e99979dcdb751bdb72752631257579131a062 /common | |
parent | 6967f634ab7c558522236a3608766fe9a5a067fd (diff) | |
download | chrome-ec-ae9aea55280abdf2febb362cd9af7be656614eb2.tar.gz |
usb_pd TCPMv1: Maintain independent MessageId for SOP''
This patchset enables checking and storaging the MessageId counter
received from the SOP'' messages.
Since SOP*(Cable) communication and SOP(Port Partner) have separate
MessageID counters, it is necessary to store separate messageIDs to
avoid the the incoming packets from getting dropped.
BUG=b:148481858
BRANCH=None
TEST=Tested on Volteer, able to maintain separate MessageId count for
SOP, SOP' and SOP'' communication.
Change-Id: Id3a29594c5f9b354ecb650c6d351b16883d2126b
Signed-off-by: Ayushee <ayushee.shah@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2032344
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/usb_pd_policy.c | 35 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 45 |
2 files changed, 43 insertions, 37 deletions
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index 93ce6fccb4..25dfea72f9 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -173,21 +173,32 @@ bool is_transmit_msg_sop_prime(int port) (cable[port].flags & CABLE_FLAGS_SOP_PRIME_ENABLE)); } -static bool is_transmit_msg_sop_prime_prime(int port) +bool is_transmit_msg_sop_prime_prime(int port) { return (IS_ENABLED(CONFIG_USB_PD_DECODE_SOP) && (cable[port].flags & CABLE_FLAGS_SOP_PRIME_PRIME_ENABLE)); } -int cable_consume_repeat_message(int port, uint8_t msg_id) +bool consume_sop_prime_repeat_msg(int port, uint8_t msg_id) { - if (cable[port].last_cable_msg_id != msg_id) { - cable[port].last_cable_msg_id = msg_id; - return 0; + if (cable[port].last_sop_p_msg_id != msg_id) { + cable[port].last_sop_p_msg_id = msg_id; + return false; } - CPRINTF("C%d Cable repeat msg_id %d\n", port, msg_id); - return 1; + CPRINTF("C%d SOP Prime repeat msg_id %d\n", port, msg_id); + return true; +} + +bool consume_sop_prime_prime_repeat_msg(int port, uint8_t msg_id) +{ + + if (cable[port].last_sop_p_p_msg_id != msg_id) { + cable[port].last_sop_p_p_msg_id = msg_id; + return false; + } + CPRINTF("C%d SOP Prime Prime repeat msg_id %d\n", port, msg_id); + return true; } static void disable_transmit_sop_prime(int port) @@ -245,14 +256,8 @@ void reset_pd_cable(int port) { if (IS_ENABLED(CONFIG_USB_PD_DECODE_SOP)) { memset(&cable[port], 0, sizeof(cable[port])); - /* - * Invalidate the last cable messageId counter. The cable - * Message id starts from 0 to 7 and if last_cable msg_id - * is initialized to 0, it will lead to repetitive message - * id with first received packet. Hence, initialize it with - * an invalid value 0xff. - */ - cable[port].last_cable_msg_id = 0xff; + cable[port].last_sop_p_msg_id = INVALID_MSG_ID_COUNTER; + cable[port].last_sop_p_p_msg_id = INVALID_MSG_ID_COUNTER; } } diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index ea18fd05d4..a592ffaec3 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -677,12 +677,17 @@ static void pd_update_saved_port_flags(int port, uint8_t flag, uint8_t val) */ static void invalidate_last_message_id(int port) { - /* - * Message id starts from 0 to 7. If last_msg_id is initialized to 0, - * it will lead to repetitive message id with first received packet, - * so initialize it with an invalid value 0xff. - */ - pd[port].last_msg_id = 0xff; + pd[port].last_msg_id = INVALID_MSG_ID_COUNTER; +} + +static bool consume_sop_repeat_message(int port, uint8_t msg_id) +{ + if (pd[port].last_msg_id != msg_id) { + pd[port].last_msg_id = msg_id; + return false; + } + CPRINTF("C%d Repeat msg_id %d\n", port, msg_id); + return true; } /** @@ -690,32 +695,28 @@ static void invalidate_last_message_id(int port) * * @param port USB PD TCPC port number * @param msg_header Message Header containing the RX message ID - * @return 1 if the received message is a duplicate one, 0 otherwise. + * @return True if the received message is a duplicate one, False otherwise. + * + * From USB PD version 1.3 section 6.7.1, the port which communicates + * using SOP* Packets Shall maintain copies of the last MessageID for + * each type of SOP* it uses. */ -static int consume_repeat_message(int port, uint16_t msg_header) +static bool consume_repeat_message(int port, uint16_t msg_header) { uint8_t msg_id = PD_HEADER_ID(msg_header); /* If repeat message ignore, except softreset control request. */ if (PD_HEADER_TYPE(msg_header) == PD_CTRL_SOFT_RESET && PD_HEADER_CNT(msg_header) == 0) { - return 0; - /* TODO: Check for incoming SOP'' messages */ + return false; } else if (is_transmit_msg_sop_prime(port)) { - /* - * From USB PD version 1.3 section 6.7.1, the port which - * communicates using SOP* Packets Shall maintain copy - * of the last MessageID for each type of SOP* it uses. - */ - return cable_consume_repeat_message(port, msg_id); - } else if (pd[port].last_msg_id != msg_id) { - pd[port].last_msg_id = msg_id; - } else if (pd[port].last_msg_id == msg_id) { - CPRINTF("C%d Repeat msg_id %d\n", port, msg_id); - return 1; + return consume_sop_prime_repeat_msg(port, msg_id); + } else if (is_transmit_msg_sop_prime_prime(port)) { + return consume_sop_prime_prime_repeat_msg(port, msg_id); + } else { + return consume_sop_repeat_message(port, msg_id); } - return 0; } /** |