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 #define HDCP_LOG_ERR(hdcp, ...) DRM_DEBUG_KMS(__VA_ARGS__)
30 #define HDCP_LOG_VER(hdcp, ...) DRM_DEBUG_KMS(__VA_ARGS__)
31 #define HDCP_LOG_FSM(hdcp, ...) DRM_DEBUG_KMS(__VA_ARGS__)
32 #define HDCP_LOG_TOP(hdcp, ...) pr_debug("[HDCP_TOP]:"__VA_ARGS__)
33 #define HDCP_LOG_DDC(hdcp, ...) pr_debug("[HDCP_DDC]:"__VA_ARGS__)
34 
35 /* default logs */
36 #define HDCP_ERROR_TRACE(hdcp, status) \
37 		HDCP_LOG_ERR(hdcp, \
38 			"[Link %d] WARNING %s IN STATE %s STAY COUNT %d", \
39 			hdcp->config.index, \
40 			mod_hdcp_status_to_str(status), \
41 			mod_hdcp_state_id_to_str(hdcp->state.id), \
42 			hdcp->state.stay_count)
43 #define HDCP_HDCP1_ENABLED_TRACE(hdcp, displayIndex) \
44 		HDCP_LOG_VER(hdcp, \
45 			"[Link %d] HDCP 1.4 enabled on display %d", \
46 			hdcp->config.index, displayIndex)
47 #define HDCP_HDCP2_ENABLED_TRACE(hdcp, displayIndex) \
48 		HDCP_LOG_VER(hdcp, \
49 			"[Link %d] HDCP 2.2 enabled on display %d", \
50 			hdcp->config.index, displayIndex)
51 #define HDCP_HDCP1_DISABLED_TRACE(hdcp, displayIndex) \
52 		HDCP_LOG_VER(hdcp, \
53 			"[Link %d] HDCP 1.4 disabled on display %d", \
54 			hdcp->config.index, displayIndex)
55 #define HDCP_HDCP2_DISABLED_TRACE(hdcp, displayIndex) \
56 		HDCP_LOG_VER(hdcp, \
57 			"[Link %d] HDCP 2.2 disabled on display %d", \
58 			hdcp->config.index, displayIndex)
59 
60 /* state machine logs */
61 #define HDCP_REMOVE_DISPLAY_TRACE(hdcp, displayIndex) \
62 		HDCP_LOG_FSM(hdcp, \
63 			"[Link %d] HDCP_REMOVE_DISPLAY index %d", \
64 			hdcp->config.index, displayIndex)
65 #define HDCP_INPUT_PASS_TRACE(hdcp, str) \
66 		HDCP_LOG_FSM(hdcp, \
67 			"[Link %d]\tPASS %s", \
68 			hdcp->config.index, str)
69 #define HDCP_INPUT_FAIL_TRACE(hdcp, str) \
70 		HDCP_LOG_FSM(hdcp, \
71 			"[Link %d]\tFAIL %s", \
72 			hdcp->config.index, str)
73 #define HDCP_NEXT_STATE_TRACE(hdcp, id, output) do { \
74 		if (output->watchdog_timer_needed) \
75 			HDCP_LOG_FSM(hdcp, \
76 				"[Link %d] > %s with %d ms watchdog", \
77 				hdcp->config.index, \
78 				mod_hdcp_state_id_to_str(id), output->watchdog_timer_delay); \
79 		else \
80 			HDCP_LOG_FSM(hdcp, \
81 				"[Link %d] > %s", hdcp->config.index, \
82 				mod_hdcp_state_id_to_str(id)); \
83 } while (0)
84 #define HDCP_TIMEOUT_TRACE(hdcp) \
85 		HDCP_LOG_FSM(hdcp, "[Link %d] --> TIMEOUT", hdcp->config.index)
86 #define HDCP_CPIRQ_TRACE(hdcp) \
87 		HDCP_LOG_FSM(hdcp, "[Link %d] --> CPIRQ", hdcp->config.index)
88 #define HDCP_EVENT_TRACE(hdcp, event) \
89 		if (event == MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) \
90 			HDCP_TIMEOUT_TRACE(hdcp); \
91 		else if (event == MOD_HDCP_EVENT_CPIRQ) \
92 			HDCP_CPIRQ_TRACE(hdcp)
93 /* TODO: find some way to tell if logging is off to save time */
94 #define HDCP_DDC_READ_TRACE(hdcp, msg_name, msg, msg_size) do { \
95 		mod_hdcp_dump_binary_message(msg, msg_size, hdcp->buf, \
96 				sizeof(hdcp->buf)); \
97 		HDCP_LOG_DDC(hdcp, "[Link %d] Read %s%s", hdcp->config.index, \
98 				msg_name, hdcp->buf); \
99 } while (0)
100 #define HDCP_DDC_WRITE_TRACE(hdcp, msg_name, msg, msg_size) do { \
101 		mod_hdcp_dump_binary_message(msg, msg_size, hdcp->buf, \
102 				sizeof(hdcp->buf)); \
103 		HDCP_LOG_DDC(hdcp, "[Link %d] Write %s%s", \
104 				hdcp->config.index, msg_name,\
105 				hdcp->buf); \
106 } while (0)
107 #define HDCP_TOP_ADD_DISPLAY_TRACE(hdcp, i) \
108 		HDCP_LOG_TOP(hdcp, "[Link %d]\tadd display %d", \
109 				hdcp->config.index, i)
110 #define HDCP_TOP_REMOVE_DISPLAY_TRACE(hdcp, i) \
111 		HDCP_LOG_TOP(hdcp, "[Link %d]\tremove display %d", \
112 				hdcp->config.index, i)
113 #define HDCP_TOP_HDCP1_DESTROY_SESSION_TRACE(hdcp) \
114 		HDCP_LOG_TOP(hdcp, "[Link %d]\tdestroy hdcp1 session", \
115 				hdcp->config.index)
116 #define HDCP_TOP_HDCP2_DESTROY_SESSION_TRACE(hdcp) \
117 		HDCP_LOG_TOP(hdcp, "[Link %d]\tdestroy hdcp2 session", \
118 				hdcp->config.index)
119 #define HDCP_TOP_RESET_AUTH_TRACE(hdcp) \
120 		HDCP_LOG_TOP(hdcp, "[Link %d]\treset authentication", hdcp->config.index)
121 #define HDCP_TOP_RESET_CONN_TRACE(hdcp) \
122 		HDCP_LOG_TOP(hdcp, "[Link %d]\treset connection", hdcp->config.index)
123 #define HDCP_TOP_INTERFACE_TRACE(hdcp) do { \
124 		HDCP_LOG_TOP(hdcp, "\n"); \
125 		HDCP_LOG_TOP(hdcp, "[Link %d] %s", hdcp->config.index, __func__); \
126 } while (0)
127 #define HDCP_TOP_INTERFACE_TRACE_WITH_INDEX(hdcp, i) do { \
128 		HDCP_LOG_TOP(hdcp, "\n"); \
129 		HDCP_LOG_TOP(hdcp, "[Link %d] %s display %d", hdcp->config.index, __func__, i); \
130 } while (0)
131 
132 #endif // MOD_HDCP_LOG_H_
133