Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87b3d7aa authored by Jack Pham's avatar Jack Pham
Browse files

usb: pd: Add string definitions for message types



Introduce string constants to correspond to the data, control
and extended message types. Use these to clean up all instances
of pd_send_msg() error logs, as they can now be consolidated
using a common format string. phy_msg_received() can get the
same treatment by logging the message type as a string instead
of a numeral which eases debugging.

Change-Id: I14ebc572b4cb164418d3856efddab1ec01c02eff
Signed-off-by: default avatarJack Pham <jackp@codeaurora.org>
parent 8622e936
Loading
Loading
Loading
Loading
+59 −45
Original line number Diff line number Diff line
@@ -135,6 +135,14 @@ enum usbpd_control_msg_type {
	MSG_GET_COUNTRY_CODES,
};

static const char * const usbpd_control_msg_strings[] = {
	"", "GoodCRC", "GotoMin", "Accept", "Reject", "Ping", "PS_RDY",
	"Get_Source_Cap", "Get_Sink_Cap", "DR_Swap", "PR_Swap", "VCONN_Swap",
	"Wait", "Soft_Reset", "", "", "Not_Supported",
	"Get_Source_Cap_Extended", "Get_Status", "FR_Swap", "Get_PPS_Status",
	"Get_Country_Codes",
};

enum usbpd_data_msg_type {
	MSG_SOURCE_CAPABILITIES = 1,
	MSG_REQUEST,
@@ -146,6 +154,12 @@ enum usbpd_data_msg_type {
	MSG_VDM = 0xF,
};

static const char * const usbpd_data_msg_strings[] = {
	"", "Source_Capabilities", "Request", "BIST", "Sink_Capabilities",
	"Battery_Status", "Alert", "Get_Country_Info", "", "", "", "", "", "",
	"", "Vendor_Defined",
};

enum usbpd_ext_msg_type {
	MSG_SOURCE_CAPABILITIES_EXTENDED = 1,
	MSG_STATUS,
@@ -163,6 +177,29 @@ enum usbpd_ext_msg_type {
	MSG_COUNTRY_CODES,
};

static const char * const usbpd_ext_msg_strings[] = {
	"", "Source_Capabilities_Extended", "Status", "Get_Battery_Cap",
	"Get_Battery_Status", "Get_Manufacturer_Info", "Manufacturer_Info",
	"Security_Request", "Security_Response", "Firmware_Update_Request",
	"Firmware_Update_Response", "PPS_Status", "Country_Info",
	"Country_Codes",
};

static inline const char *msg_to_string(u8 id, bool is_data, bool is_ext)
{
	if (is_ext) {
		if (id < ARRAY_SIZE(usbpd_ext_msg_strings))
			return usbpd_ext_msg_strings[id];
	} else if (is_data) {
		if (id < ARRAY_SIZE(usbpd_data_msg_strings))
			return usbpd_data_msg_strings[id];
	} else if (id < ARRAY_SIZE(usbpd_control_msg_strings)) {
		return usbpd_control_msg_strings[id];
	}

	return "Invalid";
}

enum vdm_state {
	VDM_NONE,
	DISCOVERED_ID,
@@ -656,8 +693,12 @@ static int pd_send_msg(struct usbpd *pd, u8 msg_type, const u32 *data,
			pd->tx_msgid, num_data, pd->spec_rev);

	ret = pd_phy_write(hdr, (u8 *)data, num_data * sizeof(u32), sop);
	if (ret)
	if (ret) {
		usbpd_err(&pd->dev, "Error sending %s: %d\n",
				msg_to_string(msg_type, num_data, false),
				ret);
		return ret;
	}

	pd->tx_msgid = (pd->tx_msgid + 1) & PD_MAX_MSG_ID;
	return 0;
@@ -697,8 +738,12 @@ static int pd_send_ext_msg(struct usbpd *pd, u8 msg_type,
			PD_MSG_HDR_EXTENDED;
		ret = pd_phy_write(hdr, chunked_payload,
				num_objs * sizeof(u32), sop);
		if (ret)
		if (ret) {
			usbpd_err(&pd->dev, "Error sending %s: %d\n",
					usbpd_ext_msg_strings[msg_type],
					ret);
			return ret;
		}

		pd->tx_msgid = (pd->tx_msgid + 1) & PD_MAX_MSG_ID;

@@ -1013,6 +1058,7 @@ static void phy_msg_received(struct usbpd *pd, enum pd_sop_type sop,
	struct rx_msg *rx_msg;
	unsigned long flags;
	u16 header;
	u8 msg_type, num_objs;

	if (sop == SOPII_MSG) {
		usbpd_err(&pd->dev, "only SOP/SOP' supported\n");
@@ -1057,8 +1103,12 @@ static void phy_msg_received(struct usbpd *pd, enum pd_sop_type sop,
	if (PD_MSG_HDR_REV(header) < pd->spec_rev)
		pd->spec_rev = PD_MSG_HDR_REV(header);

	usbpd_dbg(&pd->dev, "received message: type(%d) num_objs(%d)\n",
			PD_MSG_HDR_TYPE(header), PD_MSG_HDR_COUNT(header));
	msg_type = PD_MSG_HDR_TYPE(header);
	num_objs = PD_MSG_HDR_COUNT(header);
	usbpd_dbg(&pd->dev, "%s type(%d) num_objs(%d)\n",
			msg_to_string(msg_type, num_objs,
				PD_MSG_HDR_IS_EXTENDED(header)),
			msg_type, num_objs);

	if (!PD_MSG_HDR_IS_EXTENDED(header)) {
		rx_msg = kzalloc(sizeof(*rx_msg) + len, GFP_ATOMIC);
@@ -1281,7 +1331,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)
			/* send Reject */
			ret = pd_send_msg(pd, MSG_REJECT, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Reject\n");
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
				break;
			}
@@ -1303,7 +1352,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)
		/* PE_SRC_TRANSITION_SUPPLY pseudo-state */
		ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "Error sending Accept\n");
			usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
			break;
		}
@@ -1319,7 +1367,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)
		 */
		ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "Error sending PS_RDY\n");
			usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
			break;
		}
@@ -1378,7 +1425,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)

		ret = pd_send_msg(pd, MSG_SOFT_RESET, NULL, 0, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "Error sending Soft Reset, do Hard Reset\n");
			usbpd_set_state(pd, pd->current_pr == PR_SRC ?
					PE_SRC_HARD_RESET : PE_SNK_HARD_RESET);
			break;
@@ -1464,7 +1510,6 @@ static void usbpd_set_state(struct usbpd *pd, enum usbpd_state next_state)

		ret = pd_send_msg(pd, MSG_REQUEST, &pd->rdo, 1, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "Error sending Request\n");
			usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
			break;
		}
@@ -1992,7 +2037,6 @@ static void vconn_swap(struct usbpd *pd)

		ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "Error sending PS_RDY\n");
			usbpd_set_state(pd, pd->current_pr == PR_SRC ?
					PE_SRC_SEND_SOFT_RESET :
					PE_SNK_SEND_SOFT_RESET);
@@ -2319,10 +2363,8 @@ static void usbpd_sm(struct work_struct *w)
			ret = pd_send_msg(pd, MSG_SINK_CAPABILITIES,
					pd->sink_caps, pd->num_sink_caps,
					SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Sink Caps\n");
			if (ret)
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
			}
		} else if (IS_DATA(rx_msg, MSG_REQUEST)) {
			pd->rdo = *(u32 *)rx_msg->payload;
			usbpd_set_state(pd, PE_SRC_NEGOTIATE_CAPABILITY);
@@ -2334,7 +2376,6 @@ static void usbpd_sm(struct work_struct *w)

			ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Accept\n");
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
				break;
			}
@@ -2344,7 +2385,6 @@ static void usbpd_sm(struct work_struct *w)
			/* we'll happily accept Src->Sink requests anytime */
			ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Accept\n");
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
				break;
			}
@@ -2354,7 +2394,6 @@ static void usbpd_sm(struct work_struct *w)
		} else if (IS_CTRL(rx_msg, MSG_VCONN_SWAP)) {
			ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Accept\n");
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
				break;
			}
@@ -2366,16 +2405,13 @@ static void usbpd_sm(struct work_struct *w)
			/* unhandled messages */
			ret = pd_send_msg(pd, MSG_NOT_SUPPORTED, NULL, 0,
					SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Not supported\n");
			if (ret)
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
			}
			break;
		} else if (pd->send_pr_swap) {
			pd->send_pr_swap = false;
			ret = pd_send_msg(pd, MSG_PR_SWAP, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending PR Swap\n");
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
				break;
			}
@@ -2386,7 +2422,6 @@ static void usbpd_sm(struct work_struct *w)
			pd->send_dr_swap = false;
			ret = pd_send_msg(pd, MSG_DR_SWAP, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending DR Swap\n");
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
				break;
			}
@@ -2594,17 +2629,14 @@ static void usbpd_sm(struct work_struct *w)
			ret = pd_send_msg(pd, MSG_SINK_CAPABILITIES,
					pd->sink_caps, pd->num_sink_caps,
					SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Sink Caps\n");
			if (ret)
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
			}
		} else if (IS_CTRL(rx_msg, MSG_GET_SOURCE_CAP) &&
				pd->spec_rev == USBPD_REV_20) {
			ret = pd_send_msg(pd, MSG_SOURCE_CAPABILITIES,
					default_src_caps,
					ARRAY_SIZE(default_src_caps), SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending SRC CAPs\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2616,7 +2648,6 @@ static void usbpd_sm(struct work_struct *w)

			ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Accept\n");
				usbpd_set_state(pd, PE_SRC_SEND_SOFT_RESET);
				break;
			}
@@ -2627,7 +2658,6 @@ static void usbpd_sm(struct work_struct *w)
			/* TODO: should we Reject in certain circumstances? */
			ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Accept\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2644,18 +2674,15 @@ static void usbpd_sm(struct work_struct *w)
					(pd->requested_voltage > 5000000)) {
				ret = pd_send_msg(pd, MSG_REJECT, NULL, 0,
						SOP_MSG);
				if (ret) {
					usbpd_err(&pd->dev, "Error sending Reject\n");
				if (ret)
					usbpd_set_state(pd,
							PE_SNK_SEND_SOFT_RESET);
				}

				break;
			}

			ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Accept\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2668,7 +2695,6 @@ static void usbpd_sm(struct work_struct *w)
			ret = pd_send_msg(pd, MSG_GET_SOURCE_CAP_EXTENDED, NULL,
				0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending get_src_cap_ext\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2687,7 +2713,6 @@ static void usbpd_sm(struct work_struct *w)
			ret = pd_send_msg(pd, MSG_GET_PPS_STATUS, NULL,
				0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending get_pps_status\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2722,7 +2747,6 @@ static void usbpd_sm(struct work_struct *w)
			pd->send_get_status = false;
			ret = pd_send_msg(pd, MSG_GET_STATUS, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending get_status\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2740,7 +2764,6 @@ static void usbpd_sm(struct work_struct *w)
			ret = pd_send_ext_msg(pd, MSG_GET_BATTERY_CAP,
				&pd->get_battery_cap_db, 1, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending get_battery_cap\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2759,7 +2782,6 @@ static void usbpd_sm(struct work_struct *w)
			ret = pd_send_ext_msg(pd, MSG_GET_BATTERY_STATUS,
				&pd->get_battery_status_db, 1, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending get_battery_status\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2777,10 +2799,8 @@ static void usbpd_sm(struct work_struct *w)
			/* unhandled messages */
			ret = pd_send_msg(pd, MSG_NOT_SUPPORTED, NULL, 0,
					SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending Not supported\n");
			if (ret)
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
			}
			break;
		} else if (pd->send_request) {
			pd->send_request = false;
@@ -2789,7 +2809,6 @@ static void usbpd_sm(struct work_struct *w)
			pd->send_pr_swap = false;
			ret = pd_send_msg(pd, MSG_PR_SWAP, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending PR Swap\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2800,7 +2819,6 @@ static void usbpd_sm(struct work_struct *w)
			pd->send_dr_swap = false;
			ret = pd_send_msg(pd, MSG_DR_SWAP, NULL, 0, SOP_MSG);
			if (ret) {
				usbpd_err(&pd->dev, "Error sending DR Swap\n");
				usbpd_set_state(pd, PE_SNK_SEND_SOFT_RESET);
				break;
			}
@@ -2822,8 +2840,6 @@ static void usbpd_sm(struct work_struct *w)

		ret = pd_send_msg(pd, MSG_ACCEPT, NULL, 0, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "%s: Error sending Accept, do Hard Reset\n",
					usbpd_state_strings[pd->current_state]);
			usbpd_set_state(pd, pd->current_pr == PR_SRC ?
					PE_SRC_HARD_RESET : PE_SNK_HARD_RESET);
			break;
@@ -2908,7 +2924,6 @@ static void usbpd_sm(struct work_struct *w)

		ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "Error sending PS_RDY\n");
			usbpd_set_state(pd, PE_ERROR_RECOVERY);
			break;
		}
@@ -2952,7 +2967,6 @@ static void usbpd_sm(struct work_struct *w)

		ret = pd_send_msg(pd, MSG_PS_RDY, NULL, 0, SOP_MSG);
		if (ret) {
			usbpd_err(&pd->dev, "Error sending PS_RDY\n");
			usbpd_set_state(pd, PE_ERROR_RECOVERY);
			break;
		}