xref: /openbmc/linux/drivers/misc/mei/hdcp/mei_hdcp.h (revision 29c37341)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright © 2019 Intel Corporation
4  *
5  * Authors:
6  * Ramalingam C <ramalingam.c@intel.com>
7  */
8 
9 #ifndef __MEI_HDCP_H__
10 #define __MEI_HDCP_H__
11 
12 #include <drm/drm_hdcp.h>
13 
14 /* me_hdcp_status: Enumeration of all HDCP Status Codes */
15 enum me_hdcp_status {
16 	ME_HDCP_STATUS_SUCCESS			= 0x0000,
17 
18 	/* WiDi Generic Status Codes */
19 	ME_HDCP_STATUS_INTERNAL_ERROR		= 0x1000,
20 	ME_HDCP_STATUS_UNKNOWN_ERROR		= 0x1001,
21 	ME_HDCP_STATUS_INCORRECT_API_VERSION	= 0x1002,
22 	ME_HDCP_STATUS_INVALID_FUNCTION		= 0x1003,
23 	ME_HDCP_STATUS_INVALID_BUFFER_LENGTH	= 0x1004,
24 	ME_HDCP_STATUS_INVALID_PARAMS		= 0x1005,
25 	ME_HDCP_STATUS_AUTHENTICATION_FAILED	= 0x1006,
26 
27 	/* WiDi Status Codes */
28 	ME_HDCP_INVALID_SESSION_STATE		= 0x6000,
29 	ME_HDCP_SRM_FRAGMENT_UNEXPECTED		= 0x6001,
30 	ME_HDCP_SRM_INVALID_LENGTH		= 0x6002,
31 	ME_HDCP_SRM_FRAGMENT_OFFSET_INVALID	= 0x6003,
32 	ME_HDCP_SRM_VERIFICATION_FAILED		= 0x6004,
33 	ME_HDCP_SRM_VERSION_TOO_OLD		= 0x6005,
34 	ME_HDCP_RX_CERT_VERIFICATION_FAILED	= 0x6006,
35 	ME_HDCP_RX_REVOKED			= 0x6007,
36 	ME_HDCP_H_VERIFICATION_FAILED		= 0x6008,
37 	ME_HDCP_REPEATER_CHECK_UNEXPECTED	= 0x6009,
38 	ME_HDCP_TOPOLOGY_MAX_EXCEEDED		= 0x600A,
39 	ME_HDCP_V_VERIFICATION_FAILED		= 0x600B,
40 	ME_HDCP_L_VERIFICATION_FAILED		= 0x600C,
41 	ME_HDCP_STREAM_KEY_ALLOC_FAILED		= 0x600D,
42 	ME_HDCP_BASE_KEY_RESET_FAILED		= 0x600E,
43 	ME_HDCP_NONCE_GENERATION_FAILED		= 0x600F,
44 	ME_HDCP_STATUS_INVALID_E_KEY_STATE	= 0x6010,
45 	ME_HDCP_STATUS_INVALID_CS_ICV		= 0x6011,
46 	ME_HDCP_STATUS_INVALID_KB_KEY_STATE	= 0x6012,
47 	ME_HDCP_STATUS_INVALID_PAVP_MODE_ICV	= 0x6013,
48 	ME_HDCP_STATUS_INVALID_PAVP_MODE	= 0x6014,
49 	ME_HDCP_STATUS_LC_MAX_ATTEMPTS		= 0x6015,
50 
51 	/* New status for HDCP 2.1 */
52 	ME_HDCP_STATUS_MISMATCH_IN_M		= 0x6016,
53 
54 	/* New status code for HDCP 2.2 Rx */
55 	ME_HDCP_STATUS_RX_PROV_NOT_ALLOWED	= 0x6017,
56 	ME_HDCP_STATUS_RX_PROV_WRONG_SUBJECT	= 0x6018,
57 	ME_HDCP_RX_NEEDS_PROVISIONING		= 0x6019,
58 	ME_HDCP_BKSV_ICV_AUTH_FAILED		= 0x6020,
59 	ME_HDCP_STATUS_INVALID_STREAM_ID	= 0x6021,
60 	ME_HDCP_STATUS_CHAIN_NOT_INITIALIZED	= 0x6022,
61 	ME_HDCP_FAIL_NOT_EXPECTED		= 0x6023,
62 	ME_HDCP_FAIL_HDCP_OFF			= 0x6024,
63 	ME_HDCP_FAIL_INVALID_PAVP_MEMORY_MODE	= 0x6025,
64 	ME_HDCP_FAIL_AES_ECB_FAILURE		= 0x6026,
65 	ME_HDCP_FEATURE_NOT_SUPPORTED		= 0x6027,
66 	ME_HDCP_DMA_READ_ERROR			= 0x6028,
67 	ME_HDCP_DMA_WRITE_ERROR			= 0x6029,
68 	ME_HDCP_FAIL_INVALID_PACKET_SIZE	= 0x6030,
69 	ME_HDCP_H264_PARSING_ERROR		= 0x6031,
70 	ME_HDCP_HDCP2_ERRATA_VIDEO_VIOLATION	= 0x6032,
71 	ME_HDCP_HDCP2_ERRATA_AUDIO_VIOLATION	= 0x6033,
72 	ME_HDCP_TX_ACTIVE_ERROR			= 0x6034,
73 	ME_HDCP_MODE_CHANGE_ERROR		= 0x6035,
74 	ME_HDCP_STREAM_TYPE_ERROR		= 0x6036,
75 	ME_HDCP_STREAM_MANAGE_NOT_POSSIBLE	= 0x6037,
76 
77 	ME_HDCP_STATUS_PORT_INVALID_COMMAND	= 0x6038,
78 	ME_HDCP_STATUS_UNSUPPORTED_PROTOCOL	= 0x6039,
79 	ME_HDCP_STATUS_INVALID_PORT_INDEX	= 0x603a,
80 	ME_HDCP_STATUS_TX_AUTH_NEEDED		= 0x603b,
81 	ME_HDCP_STATUS_NOT_INTEGRATED_PORT	= 0x603c,
82 	ME_HDCP_STATUS_SESSION_MAX_REACHED	= 0x603d,
83 
84 	/* hdcp capable bit is not set in rx_caps(error is unique to DP) */
85 	ME_HDCP_STATUS_NOT_HDCP_CAPABLE		= 0x6041,
86 
87 	ME_HDCP_STATUS_INVALID_STREAM_COUNT	= 0x6042,
88 };
89 
90 #define HDCP_API_VERSION				0x00010000
91 
92 #define HDCP_M_LEN					16
93 #define HDCP_KH_LEN					16
94 
95 /* Payload Buffer size(Excluding Header) for CMDs and corresponding response */
96 /* Wired_Tx_AKE  */
97 #define	WIRED_CMD_BUF_LEN_INITIATE_HDCP2_SESSION_IN	(4 + 1)
98 #define	WIRED_CMD_BUF_LEN_INITIATE_HDCP2_SESSION_OUT	(4 + 8 + 3)
99 
100 #define	WIRED_CMD_BUF_LEN_VERIFY_RECEIVER_CERT_IN	(4 + 522 + 8 + 3)
101 #define	WIRED_CMD_BUF_LEN_VERIFY_RECEIVER_CERT_MIN_OUT	(4 + 1 + 3 + 16 + 16)
102 #define	WIRED_CMD_BUF_LEN_VERIFY_RECEIVER_CERT_MAX_OUT	(4 + 1 + 3 + 128)
103 
104 #define	WIRED_CMD_BUF_LEN_AKE_SEND_HPRIME_IN		(4 + 32)
105 #define	WIRED_CMD_BUF_LEN_AKE_SEND_HPRIME_OUT		(4)
106 
107 #define	WIRED_CMD_BUF_LEN_SEND_PAIRING_INFO_IN		(4 + 16)
108 #define	WIRED_CMD_BUF_LEN_SEND_PAIRING_INFO_OUT		(4)
109 
110 #define	WIRED_CMD_BUF_LEN_CLOSE_SESSION_IN		(4)
111 #define	WIRED_CMD_BUF_LEN_CLOSE_SESSION_OUT		(4)
112 
113 /* Wired_Tx_LC */
114 #define	WIRED_CMD_BUF_LEN_INIT_LOCALITY_CHECK_IN	(4)
115 #define	WIRED_CMD_BUF_LEN_INIT_LOCALITY_CHECK_OUT	(4 + 8)
116 
117 #define	WIRED_CMD_BUF_LEN_VALIDATE_LOCALITY_IN		(4 + 32)
118 #define	WIRED_CMD_BUF_LEN_VALIDATE_LOCALITY_OUT		(4)
119 
120 /* Wired_Tx_SKE */
121 #define	WIRED_CMD_BUF_LEN_GET_SESSION_KEY_IN		(4)
122 #define	WIRED_CMD_BUF_LEN_GET_SESSION_KEY_OUT		(4 + 16 + 8)
123 
124 /* Wired_Tx_SKE */
125 #define	WIRED_CMD_BUF_LEN_ENABLE_AUTH_IN		(4 + 1)
126 #define	WIRED_CMD_BUF_LEN_ENABLE_AUTH_OUT		(4)
127 
128 /* Wired_Tx_Repeater */
129 #define	WIRED_CMD_BUF_LEN_VERIFY_REPEATER_IN		(4 + 2 + 3 + 16 + 155)
130 #define	WIRED_CMD_BUF_LEN_VERIFY_REPEATER_OUT		(4 + 1 + 16)
131 
132 #define	WIRED_CMD_BUF_LEN_REPEATER_AUTH_STREAM_REQ_MIN_IN	(4 + 3 + \
133 								32 + 2 + 2)
134 
135 #define	WIRED_CMD_BUF_LEN_REPEATER_AUTH_STREAM_REQ_OUT		(4)
136 
137 /* hdcp_command_id: Enumeration of all WIRED HDCP Command IDs */
138 enum hdcp_command_id {
139 	_WIDI_COMMAND_BASE		= 0x00030000,
140 	WIDI_INITIATE_HDCP2_SESSION	= _WIDI_COMMAND_BASE,
141 	HDCP_GET_SRM_STATUS,
142 	HDCP_SEND_SRM_FRAGMENT,
143 
144 	/* The wired HDCP Tx commands */
145 	_WIRED_COMMAND_BASE		= 0x00031000,
146 	WIRED_INITIATE_HDCP2_SESSION	= _WIRED_COMMAND_BASE,
147 	WIRED_VERIFY_RECEIVER_CERT,
148 	WIRED_AKE_SEND_HPRIME,
149 	WIRED_AKE_SEND_PAIRING_INFO,
150 	WIRED_INIT_LOCALITY_CHECK,
151 	WIRED_VALIDATE_LOCALITY,
152 	WIRED_GET_SESSION_KEY,
153 	WIRED_ENABLE_AUTH,
154 	WIRED_VERIFY_REPEATER,
155 	WIRED_REPEATER_AUTH_STREAM_REQ,
156 	WIRED_CLOSE_SESSION,
157 
158 	_WIRED_COMMANDS_COUNT,
159 };
160 
161 union encrypted_buff {
162 	u8		e_kpub_km[HDCP_2_2_E_KPUB_KM_LEN];
163 	u8		e_kh_km_m[HDCP_2_2_E_KH_KM_M_LEN];
164 	struct {
165 		u8	e_kh_km[HDCP_KH_LEN];
166 		u8	m[HDCP_M_LEN];
167 	} __packed;
168 };
169 
170 /* HDCP HECI message header. All header values are little endian. */
171 struct hdcp_cmd_header {
172 	u32			api_version;
173 	u32			command_id;
174 	enum me_hdcp_status	status;
175 	/* Length of the HECI message (excluding the header) */
176 	u32			buffer_len;
177 } __packed;
178 
179 /* Empty command request or response. No data follows the header. */
180 struct hdcp_cmd_no_data {
181 	struct hdcp_cmd_header header;
182 } __packed;
183 
184 /* Uniquely identifies the hdcp port being addressed for a given command. */
185 struct hdcp_port_id {
186 	u8	integrated_port_type;
187 	/* physical_port is used until Gen11.5. Must be zero for Gen11.5+ */
188 	u8	physical_port;
189 	/* attached_transcoder is for Gen11.5+. Set to zero for <Gen11.5 */
190 	u8	attached_transcoder;
191 	u8	reserved;
192 } __packed;
193 
194 /*
195  * Data structures for integrated wired HDCP2 Tx in
196  * support of the AKE protocol
197  */
198 /* HECI struct for integrated wired HDCP Tx session initiation. */
199 struct wired_cmd_initiate_hdcp2_session_in {
200 	struct hdcp_cmd_header	header;
201 	struct hdcp_port_id	port;
202 	u8			protocol; /* for HDMI vs DP */
203 } __packed;
204 
205 struct wired_cmd_initiate_hdcp2_session_out {
206 	struct hdcp_cmd_header	header;
207 	struct hdcp_port_id	port;
208 	u8			r_tx[HDCP_2_2_RTX_LEN];
209 	struct hdcp2_tx_caps	tx_caps;
210 } __packed;
211 
212 /* HECI struct for ending an integrated wired HDCP Tx session. */
213 struct wired_cmd_close_session_in {
214 	struct hdcp_cmd_header	header;
215 	struct hdcp_port_id	port;
216 } __packed;
217 
218 struct wired_cmd_close_session_out {
219 	struct hdcp_cmd_header	header;
220 	struct hdcp_port_id	port;
221 } __packed;
222 
223 /* HECI struct for integrated wired HDCP Tx Rx Cert verification. */
224 struct wired_cmd_verify_receiver_cert_in {
225 	struct hdcp_cmd_header	header;
226 	struct hdcp_port_id	port;
227 	struct hdcp2_cert_rx	cert_rx;
228 	u8			r_rx[HDCP_2_2_RRX_LEN];
229 	u8			rx_caps[HDCP_2_2_RXCAPS_LEN];
230 } __packed;
231 
232 struct wired_cmd_verify_receiver_cert_out {
233 	struct hdcp_cmd_header	header;
234 	struct hdcp_port_id	port;
235 	u8			km_stored;
236 	u8			reserved[3];
237 	union encrypted_buff	ekm_buff;
238 } __packed;
239 
240 /* HECI struct for verification of Rx's Hprime in a HDCP Tx session */
241 struct wired_cmd_ake_send_hprime_in {
242 	struct hdcp_cmd_header	header;
243 	struct hdcp_port_id	port;
244 	u8			h_prime[HDCP_2_2_H_PRIME_LEN];
245 } __packed;
246 
247 struct wired_cmd_ake_send_hprime_out {
248 	struct hdcp_cmd_header	header;
249 	struct hdcp_port_id	port;
250 } __packed;
251 
252 /*
253  * HECI struct for sending in AKE pairing data generated by the Rx in an
254  * integrated wired HDCP Tx session.
255  */
256 struct wired_cmd_ake_send_pairing_info_in {
257 	struct hdcp_cmd_header	header;
258 	struct hdcp_port_id	port;
259 	u8			e_kh_km[HDCP_2_2_E_KH_KM_LEN];
260 } __packed;
261 
262 struct wired_cmd_ake_send_pairing_info_out {
263 	struct hdcp_cmd_header	header;
264 	struct hdcp_port_id	port;
265 } __packed;
266 
267 /* Data structures for integrated wired HDCP2 Tx in support of the LC protocol*/
268 /*
269  * HECI struct for initiating locality check with an
270  * integrated wired HDCP Tx session.
271  */
272 struct wired_cmd_init_locality_check_in {
273 	struct hdcp_cmd_header	header;
274 	struct hdcp_port_id	port;
275 } __packed;
276 
277 struct wired_cmd_init_locality_check_out {
278 	struct hdcp_cmd_header	header;
279 	struct hdcp_port_id	port;
280 	u8			r_n[HDCP_2_2_RN_LEN];
281 } __packed;
282 
283 /*
284  * HECI struct for validating an Rx's LPrime value in an
285  * integrated wired HDCP Tx session.
286  */
287 struct wired_cmd_validate_locality_in {
288 	struct hdcp_cmd_header	header;
289 	struct hdcp_port_id	port;
290 	u8			l_prime[HDCP_2_2_L_PRIME_LEN];
291 } __packed;
292 
293 struct wired_cmd_validate_locality_out {
294 	struct hdcp_cmd_header	header;
295 	struct hdcp_port_id	port;
296 } __packed;
297 
298 /*
299  * Data structures for integrated wired HDCP2 Tx in support of the
300  * SKE protocol
301  */
302 /* HECI struct for creating session key */
303 struct wired_cmd_get_session_key_in {
304 	struct hdcp_cmd_header	header;
305 	struct hdcp_port_id	port;
306 } __packed;
307 
308 struct wired_cmd_get_session_key_out {
309 	struct hdcp_cmd_header	header;
310 	struct hdcp_port_id	port;
311 	u8			e_dkey_ks[HDCP_2_2_E_DKEY_KS_LEN];
312 	u8			r_iv[HDCP_2_2_RIV_LEN];
313 } __packed;
314 
315 /* HECI struct for the Tx enable authentication command */
316 struct wired_cmd_enable_auth_in {
317 	struct hdcp_cmd_header	header;
318 	struct hdcp_port_id	port;
319 	u8			stream_type;
320 } __packed;
321 
322 struct wired_cmd_enable_auth_out {
323 	struct hdcp_cmd_header	header;
324 	struct hdcp_port_id	port;
325 } __packed;
326 
327 /*
328  * Data structures for integrated wired HDCP2 Tx in support of
329  * the repeater protocols
330  */
331 /*
332  * HECI struct for verifying the downstream repeater's HDCP topology in an
333  * integrated wired HDCP Tx session.
334  */
335 struct wired_cmd_verify_repeater_in {
336 	struct hdcp_cmd_header	header;
337 	struct hdcp_port_id	port;
338 	u8			rx_info[HDCP_2_2_RXINFO_LEN];
339 	u8			seq_num_v[HDCP_2_2_SEQ_NUM_LEN];
340 	u8			v_prime[HDCP_2_2_V_PRIME_HALF_LEN];
341 	u8			receiver_ids[HDCP_2_2_RECEIVER_IDS_MAX_LEN];
342 } __packed;
343 
344 struct wired_cmd_verify_repeater_out {
345 	struct hdcp_cmd_header	header;
346 	struct hdcp_port_id	port;
347 	u8			content_type_supported;
348 	u8			v[HDCP_2_2_V_PRIME_HALF_LEN];
349 } __packed;
350 
351 /*
352  * HECI struct in support of stream management in an
353  * integrated wired HDCP Tx session.
354  */
355 struct wired_cmd_repeater_auth_stream_req_in {
356 	struct hdcp_cmd_header		header;
357 	struct hdcp_port_id		port;
358 	u8				seq_num_m[HDCP_2_2_SEQ_NUM_LEN];
359 	u8				m_prime[HDCP_2_2_MPRIME_LEN];
360 	__be16				k;
361 	struct hdcp2_streamid_type	streams[];
362 } __packed;
363 
364 struct wired_cmd_repeater_auth_stream_req_out {
365 	struct hdcp_cmd_header	header;
366 	struct hdcp_port_id	port;
367 } __packed;
368 #endif /* __MEI_HDCP_H__ */
369