1 /*
2  * Copyright 2019 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #ifndef MOD_HDCP_LOG_H_
27 #define MOD_HDCP_LOG_H_
28 
29 #ifdef CONFIG_DRM_AMD_DC_HDCP
30 #define HDCP_LOG_ERR(hdcp, ...) DRM_ERROR(__VA_ARGS__)
31 #define HDCP_LOG_VER(hdcp, ...) DRM_DEBUG_KMS(__VA_ARGS__)
32 #define HDCP_LOG_FSM(hdcp, ...) DRM_DEBUG_KMS(__VA_ARGS__)
33 #define HDCP_LOG_TOP(hdcp, ...) pr_debug("[HDCP_TOP]:"__VA_ARGS__)
34 #define HDCP_LOG_DDC(hdcp, ...) pr_debug("[HDCP_DDC]:"__VA_ARGS__)
35 #endif
36 
37 /* default logs */
38 #define HDCP_ERROR_TRACE(hdcp, status) \
39 		HDCP_LOG_ERR(hdcp, \
40 			"[Link %d] ERROR %s IN STATE %s", \
41 			hdcp->config.index, \
42 			mod_hdcp_status_to_str(status), \
43 			mod_hdcp_state_id_to_str(hdcp->state.id))
44 #define HDCP_HDCP1_ENABLED_TRACE(hdcp, displayIndex) \
45 		HDCP_LOG_VER(hdcp, \
46 			"[Link %d] HDCP 1.4 enabled on display %d", \
47 			hdcp->config.index, displayIndex)
48 /* state machine logs */
49 #define HDCP_REMOVE_DISPLAY_TRACE(hdcp, displayIndex) \
50 		HDCP_LOG_FSM(hdcp, \
51 			"[Link %d] HDCP_REMOVE_DISPLAY index %d", \
52 			hdcp->config.index, displayIndex)
53 #define HDCP_INPUT_PASS_TRACE(hdcp, str) \
54 		HDCP_LOG_FSM(hdcp, \
55 			"[Link %d]\tPASS %s", \
56 			hdcp->config.index, str)
57 #define HDCP_INPUT_FAIL_TRACE(hdcp, str) \
58 		HDCP_LOG_FSM(hdcp, \
59 			"[Link %d]\tFAIL %s", \
60 			hdcp->config.index, str)
61 #define HDCP_NEXT_STATE_TRACE(hdcp, id, output) do { \
62 		if (output->watchdog_timer_needed) \
63 			HDCP_LOG_FSM(hdcp, \
64 				"[Link %d] > %s with %d ms watchdog", \
65 				hdcp->config.index, \
66 				mod_hdcp_state_id_to_str(id), output->watchdog_timer_delay); \
67 		else \
68 			HDCP_LOG_FSM(hdcp, \
69 				"[Link %d] > %s", hdcp->config.index, \
70 				mod_hdcp_state_id_to_str(id)); \
71 } while (0)
72 #define HDCP_TIMEOUT_TRACE(hdcp) \
73 		HDCP_LOG_FSM(hdcp, "[Link %d] --> TIMEOUT", hdcp->config.index)
74 #define HDCP_CPIRQ_TRACE(hdcp) \
75 		HDCP_LOG_FSM(hdcp, "[Link %d] --> CPIRQ", hdcp->config.index)
76 #define HDCP_EVENT_TRACE(hdcp, event) \
77 		if (event == MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) \
78 			HDCP_TIMEOUT_TRACE(hdcp); \
79 		else if (event == MOD_HDCP_EVENT_CPIRQ) \
80 			HDCP_CPIRQ_TRACE(hdcp)
81 /* TODO: find some way to tell if logging is off to save time */
82 #define HDCP_DDC_READ_TRACE(hdcp, msg_name, msg, msg_size) do { \
83 		mod_hdcp_dump_binary_message(msg, msg_size, hdcp->buf, \
84 				sizeof(hdcp->buf)); \
85 		HDCP_LOG_DDC(hdcp, "[Link %d] Read %s%s", hdcp->config.index, \
86 				msg_name, hdcp->buf); \
87 } while (0)
88 #define HDCP_DDC_WRITE_TRACE(hdcp, msg_name, msg, msg_size) do { \
89 		mod_hdcp_dump_binary_message(msg, msg_size, hdcp->buf, \
90 				sizeof(hdcp->buf)); \
91 		HDCP_LOG_DDC(hdcp, "[Link %d] Write %s%s", \
92 				hdcp->config.index, msg_name,\
93 				hdcp->buf); \
94 } while (0)
95 #define HDCP_FULL_DDC_TRACE(hdcp) do { \
96 	HDCP_DDC_READ_TRACE(hdcp, "BKSV", hdcp->auth.msg.hdcp1.bksv, \
97 			sizeof(hdcp->auth.msg.hdcp1.bksv)); \
98 	HDCP_DDC_READ_TRACE(hdcp, "BCAPS", &hdcp->auth.msg.hdcp1.bcaps, \
99 			sizeof(hdcp->auth.msg.hdcp1.bcaps)); \
100 	HDCP_DDC_WRITE_TRACE(hdcp, "AN", hdcp->auth.msg.hdcp1.an, \
101 			sizeof(hdcp->auth.msg.hdcp1.an)); \
102 	HDCP_DDC_WRITE_TRACE(hdcp, "AKSV", hdcp->auth.msg.hdcp1.aksv, \
103 			sizeof(hdcp->auth.msg.hdcp1.aksv)); \
104 	HDCP_DDC_WRITE_TRACE(hdcp, "AINFO", &hdcp->auth.msg.hdcp1.ainfo, \
105 			sizeof(hdcp->auth.msg.hdcp1.ainfo)); \
106 	HDCP_DDC_READ_TRACE(hdcp, "RI' / R0'", \
107 			(uint8_t *)&hdcp->auth.msg.hdcp1.r0p, \
108 			sizeof(hdcp->auth.msg.hdcp1.r0p)); \
109 	HDCP_DDC_READ_TRACE(hdcp, "BINFO", \
110 			(uint8_t *)&hdcp->auth.msg.hdcp1.binfo_dp, \
111 			sizeof(hdcp->auth.msg.hdcp1.binfo_dp)); \
112 	HDCP_DDC_READ_TRACE(hdcp, "KSVLIST", hdcp->auth.msg.hdcp1.ksvlist, \
113 			hdcp->auth.msg.hdcp1.ksvlist_size); \
114 	HDCP_DDC_READ_TRACE(hdcp, "V'", hdcp->auth.msg.hdcp1.vp, \
115 			sizeof(hdcp->auth.msg.hdcp1.vp)); \
116 } while (0)
117 #define HDCP_TOP_ADD_DISPLAY_TRACE(hdcp, i) \
118 		HDCP_LOG_TOP(hdcp, "[Link %d]\tadd display %d", \
119 				hdcp->config.index, i)
120 #define HDCP_TOP_REMOVE_DISPLAY_TRACE(hdcp, i) \
121 		HDCP_LOG_TOP(hdcp, "[Link %d]\tremove display %d", \
122 				hdcp->config.index, i)
123 #define HDCP_TOP_HDCP1_DESTROY_SESSION_TRACE(hdcp) \
124 		HDCP_LOG_TOP(hdcp, "[Link %d]\tdestroy hdcp1 session", \
125 				hdcp->config.index)
126 #define HDCP_TOP_RESET_AUTH_TRACE(hdcp) \
127 		HDCP_LOG_TOP(hdcp, "[Link %d]\treset authentication", hdcp->config.index)
128 #define HDCP_TOP_RESET_CONN_TRACE(hdcp) \
129 		HDCP_LOG_TOP(hdcp, "[Link %d]\treset connection", hdcp->config.index)
130 #define HDCP_TOP_INTERFACE_TRACE(hdcp) do { \
131 		HDCP_LOG_TOP(hdcp, "\n"); \
132 		HDCP_LOG_TOP(hdcp, "[Link %d] %s", hdcp->config.index, __func__); \
133 } while (0)
134 #define HDCP_TOP_INTERFACE_TRACE_WITH_INDEX(hdcp, i) do { \
135 		HDCP_LOG_TOP(hdcp, "\n"); \
136 		HDCP_LOG_TOP(hdcp, "[Link %d] %s display %d", hdcp->config.index, __func__, i); \
137 } while (0)
138 
139 #endif // MOD_HDCP_LOG_H_
140