1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright © 2019 Intel Corporation
5 * mei_hdcp.c: HDCP client driver for mei bus
8 * Ramalingam C <ramalingam.c@intel.com>
12 * DOC: MEI_HDCP Client Driver
14 * The mei_hdcp driver acts as a translation layer between HDCP 2.2
15 * protocol implementer (I915) and ME FW by translating HDCP2.2
16 * negotiation messages to ME FW command payloads and vice versa.
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/uuid.h>
22 #include <linux/mei_cl_bus.h>
23 #include <linux/component.h>
24 #include <drm/drm_connector.h>
25 #include <drm/i915_component.h>
26 #include <drm/i915_mei_hdcp_interface.h>
31 * mei_hdcp_initiate_session() - Initiate a Wired HDCP2.2 Tx Session in ME FW
32 * @dev: device corresponding to the mei_cl_device
33 * @data: Intel HW specific hdcp data
34 * @ake_data: AKE_Init msg output.
36 * Return: 0 on Success, <0 on Failure.
39 mei_hdcp_initiate_session(struct device *dev, struct hdcp_port_data *data,
40 struct hdcp2_ake_init *ake_data)
42 struct wired_cmd_initiate_hdcp2_session_in session_init_in = { { 0 } };
43 struct wired_cmd_initiate_hdcp2_session_out
44 session_init_out = { { 0 } };
45 struct mei_cl_device *cldev;
48 if (!dev || !data || !ake_data)
51 cldev = to_mei_cl_device(dev);
53 session_init_in.header.api_version = HDCP_API_VERSION;
54 session_init_in.header.command_id = WIRED_INITIATE_HDCP2_SESSION;
55 session_init_in.header.status = ME_HDCP_STATUS_SUCCESS;
56 session_init_in.header.buffer_len =
57 WIRED_CMD_BUF_LEN_INITIATE_HDCP2_SESSION_IN;
59 session_init_in.port.integrated_port_type = data->port_type;
60 session_init_in.port.physical_port = (u8)data->fw_ddi;
61 session_init_in.port.attached_transcoder = (u8)data->fw_tc;
62 session_init_in.protocol = data->protocol;
64 byte = mei_cldev_send(cldev, (u8 *)&session_init_in,
65 sizeof(session_init_in));
67 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
71 byte = mei_cldev_recv(cldev, (u8 *)&session_init_out,
72 sizeof(session_init_out));
74 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
78 if (session_init_out.header.status != ME_HDCP_STATUS_SUCCESS) {
79 dev_dbg(dev, "ME cmd 0x%08X Failed. Status: 0x%X\n",
80 WIRED_INITIATE_HDCP2_SESSION,
81 session_init_out.header.status);
85 ake_data->msg_id = HDCP_2_2_AKE_INIT;
86 ake_data->tx_caps = session_init_out.tx_caps;
87 memcpy(ake_data->r_tx, session_init_out.r_tx, HDCP_2_2_RTX_LEN);
93 * mei_hdcp_verify_receiver_cert_prepare_km() - Verify the Receiver Certificate
94 * AKE_Send_Cert and prepare AKE_Stored_Km/AKE_No_Stored_Km
95 * @dev: device corresponding to the mei_cl_device
96 * @data: Intel HW specific hdcp data
97 * @rx_cert: AKE_Send_Cert for verification
98 * @km_stored: Pairing status flag output
99 * @ek_pub_km: AKE_Stored_Km/AKE_No_Stored_Km output msg
100 * @msg_sz : size of AKE_XXXXX_Km output msg
102 * Return: 0 on Success, <0 on Failure
105 mei_hdcp_verify_receiver_cert_prepare_km(struct device *dev,
106 struct hdcp_port_data *data,
107 struct hdcp2_ake_send_cert *rx_cert,
109 struct hdcp2_ake_no_stored_km
113 struct wired_cmd_verify_receiver_cert_in verify_rxcert_in = { { 0 } };
114 struct wired_cmd_verify_receiver_cert_out verify_rxcert_out = { { 0 } };
115 struct mei_cl_device *cldev;
118 if (!dev || !data || !rx_cert || !km_stored || !ek_pub_km || !msg_sz)
121 cldev = to_mei_cl_device(dev);
123 verify_rxcert_in.header.api_version = HDCP_API_VERSION;
124 verify_rxcert_in.header.command_id = WIRED_VERIFY_RECEIVER_CERT;
125 verify_rxcert_in.header.status = ME_HDCP_STATUS_SUCCESS;
126 verify_rxcert_in.header.buffer_len =
127 WIRED_CMD_BUF_LEN_VERIFY_RECEIVER_CERT_IN;
129 verify_rxcert_in.port.integrated_port_type = data->port_type;
130 verify_rxcert_in.port.physical_port = (u8)data->fw_ddi;
131 verify_rxcert_in.port.attached_transcoder = (u8)data->fw_tc;
133 verify_rxcert_in.cert_rx = rx_cert->cert_rx;
134 memcpy(verify_rxcert_in.r_rx, &rx_cert->r_rx, HDCP_2_2_RRX_LEN);
135 memcpy(verify_rxcert_in.rx_caps, rx_cert->rx_caps, HDCP_2_2_RXCAPS_LEN);
137 byte = mei_cldev_send(cldev, (u8 *)&verify_rxcert_in,
138 sizeof(verify_rxcert_in));
140 dev_dbg(dev, "mei_cldev_send failed: %zd\n", byte);
144 byte = mei_cldev_recv(cldev, (u8 *)&verify_rxcert_out,
145 sizeof(verify_rxcert_out));
147 dev_dbg(dev, "mei_cldev_recv failed: %zd\n", byte);
151 if (verify_rxcert_out.header.status != ME_HDCP_STATUS_SUCCESS) {
152 dev_dbg(dev, "ME cmd 0x%08X Failed. Status: 0x%X\n",
153 WIRED_VERIFY_RECEIVER_CERT,
154 verify_rxcert_out.header.status);
158 *km_stored = !!verify_rxcert_out.km_stored;
159 if (verify_rxcert_out.km_stored) {
160 ek_pub_km->msg_id = HDCP_2_2_AKE_STORED_KM;
161 *msg_sz = sizeof(struct hdcp2_ake_stored_km);
163 ek_pub_km->msg_id = HDCP_2_2_AKE_NO_STORED_KM;
164 *msg_sz = sizeof(struct hdcp2_ake_no_stored_km);
167 memcpy(ek_pub_km->e_kpub_km, &verify_rxcert_out.ekm_buff,
168 sizeof(verify_rxcert_out.ekm_buff));
174 * mei_hdcp_verify_hprime() - Verify AKE_Send_H_prime at ME FW.
175 * @dev: device corresponding to the mei_cl_device
176 * @data: Intel HW specific hdcp data
177 * @rx_hprime: AKE_Send_H_prime msg for ME FW verification
179 * Return: 0 on Success, <0 on Failure
182 mei_hdcp_verify_hprime(struct device *dev, struct hdcp_port_data *data,
183 struct hdcp2_ake_send_hprime *rx_hprime)
185 struct wired_cmd_ake_send_hprime_in send_hprime_in = { { 0 } };
186 struct wired_cmd_ake_send_hprime_out send_hprime_out = { { 0 } };
187 struct mei_cl_device *cldev;
190 if (!dev || !data || !rx_hprime)
193 cldev = to_mei_cl_device(dev);
195 send_hprime_in.header.api_version = HDCP_API_VERSION;
196 send_hprime_in.header.command_id = WIRED_AKE_SEND_HPRIME;
197 send_hprime_in.header.status = ME_HDCP_STATUS_SUCCESS;
198 send_hprime_in.header.buffer_len = WIRED_CMD_BUF_LEN_AKE_SEND_HPRIME_IN;
200 send_hprime_in.port.integrated_port_type = data->port_type;
201 send_hprime_in.port.physical_port = (u8)data->fw_ddi;
202 send_hprime_in.port.attached_transcoder = (u8)data->fw_tc;
204 memcpy(send_hprime_in.h_prime, rx_hprime->h_prime,
205 HDCP_2_2_H_PRIME_LEN);
207 byte = mei_cldev_send(cldev, (u8 *)&send_hprime_in,
208 sizeof(send_hprime_in));
210 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
214 byte = mei_cldev_recv(cldev, (u8 *)&send_hprime_out,
215 sizeof(send_hprime_out));
217 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
221 if (send_hprime_out.header.status != ME_HDCP_STATUS_SUCCESS) {
222 dev_dbg(dev, "ME cmd 0x%08X Failed. Status: 0x%X\n",
223 WIRED_AKE_SEND_HPRIME, send_hprime_out.header.status);
231 * mei_hdcp_store_pairing_info() - Store pairing info received at ME FW
232 * @dev: device corresponding to the mei_cl_device
233 * @data: Intel HW specific hdcp data
234 * @pairing_info: AKE_Send_Pairing_Info msg input to ME FW
236 * Return: 0 on Success, <0 on Failure
239 mei_hdcp_store_pairing_info(struct device *dev, struct hdcp_port_data *data,
240 struct hdcp2_ake_send_pairing_info *pairing_info)
242 struct wired_cmd_ake_send_pairing_info_in pairing_info_in = { { 0 } };
243 struct wired_cmd_ake_send_pairing_info_out pairing_info_out = { { 0 } };
244 struct mei_cl_device *cldev;
247 if (!dev || !data || !pairing_info)
250 cldev = to_mei_cl_device(dev);
252 pairing_info_in.header.api_version = HDCP_API_VERSION;
253 pairing_info_in.header.command_id = WIRED_AKE_SEND_PAIRING_INFO;
254 pairing_info_in.header.status = ME_HDCP_STATUS_SUCCESS;
255 pairing_info_in.header.buffer_len =
256 WIRED_CMD_BUF_LEN_SEND_PAIRING_INFO_IN;
258 pairing_info_in.port.integrated_port_type = data->port_type;
259 pairing_info_in.port.physical_port = (u8)data->fw_ddi;
260 pairing_info_in.port.attached_transcoder = (u8)data->fw_tc;
262 memcpy(pairing_info_in.e_kh_km, pairing_info->e_kh_km,
263 HDCP_2_2_E_KH_KM_LEN);
265 byte = mei_cldev_send(cldev, (u8 *)&pairing_info_in,
266 sizeof(pairing_info_in));
268 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
272 byte = mei_cldev_recv(cldev, (u8 *)&pairing_info_out,
273 sizeof(pairing_info_out));
275 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
279 if (pairing_info_out.header.status != ME_HDCP_STATUS_SUCCESS) {
280 dev_dbg(dev, "ME cmd 0x%08X failed. Status: 0x%X\n",
281 WIRED_AKE_SEND_PAIRING_INFO,
282 pairing_info_out.header.status);
290 * mei_hdcp_initiate_locality_check() - Prepare LC_Init
291 * @dev: device corresponding to the mei_cl_device
292 * @data: Intel HW specific hdcp data
293 * @lc_init_data: LC_Init msg output
295 * Return: 0 on Success, <0 on Failure
298 mei_hdcp_initiate_locality_check(struct device *dev,
299 struct hdcp_port_data *data,
300 struct hdcp2_lc_init *lc_init_data)
302 struct wired_cmd_init_locality_check_in lc_init_in = { { 0 } };
303 struct wired_cmd_init_locality_check_out lc_init_out = { { 0 } };
304 struct mei_cl_device *cldev;
307 if (!dev || !data || !lc_init_data)
310 cldev = to_mei_cl_device(dev);
312 lc_init_in.header.api_version = HDCP_API_VERSION;
313 lc_init_in.header.command_id = WIRED_INIT_LOCALITY_CHECK;
314 lc_init_in.header.status = ME_HDCP_STATUS_SUCCESS;
315 lc_init_in.header.buffer_len = WIRED_CMD_BUF_LEN_INIT_LOCALITY_CHECK_IN;
317 lc_init_in.port.integrated_port_type = data->port_type;
318 lc_init_in.port.physical_port = (u8)data->fw_ddi;
319 lc_init_in.port.attached_transcoder = (u8)data->fw_tc;
321 byte = mei_cldev_send(cldev, (u8 *)&lc_init_in, sizeof(lc_init_in));
323 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
327 byte = mei_cldev_recv(cldev, (u8 *)&lc_init_out, sizeof(lc_init_out));
329 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
333 if (lc_init_out.header.status != ME_HDCP_STATUS_SUCCESS) {
334 dev_dbg(dev, "ME cmd 0x%08X Failed. status: 0x%X\n",
335 WIRED_INIT_LOCALITY_CHECK, lc_init_out.header.status);
339 lc_init_data->msg_id = HDCP_2_2_LC_INIT;
340 memcpy(lc_init_data->r_n, lc_init_out.r_n, HDCP_2_2_RN_LEN);
346 * mei_hdcp_verify_lprime() - Verify lprime.
347 * @dev: device corresponding to the mei_cl_device
348 * @data: Intel HW specific hdcp data
349 * @rx_lprime: LC_Send_L_prime msg for ME FW verification
351 * Return: 0 on Success, <0 on Failure
354 mei_hdcp_verify_lprime(struct device *dev, struct hdcp_port_data *data,
355 struct hdcp2_lc_send_lprime *rx_lprime)
357 struct wired_cmd_validate_locality_in verify_lprime_in = { { 0 } };
358 struct wired_cmd_validate_locality_out verify_lprime_out = { { 0 } };
359 struct mei_cl_device *cldev;
362 if (!dev || !data || !rx_lprime)
365 cldev = to_mei_cl_device(dev);
367 verify_lprime_in.header.api_version = HDCP_API_VERSION;
368 verify_lprime_in.header.command_id = WIRED_VALIDATE_LOCALITY;
369 verify_lprime_in.header.status = ME_HDCP_STATUS_SUCCESS;
370 verify_lprime_in.header.buffer_len =
371 WIRED_CMD_BUF_LEN_VALIDATE_LOCALITY_IN;
373 verify_lprime_in.port.integrated_port_type = data->port_type;
374 verify_lprime_in.port.physical_port = (u8)data->fw_ddi;
375 verify_lprime_in.port.attached_transcoder = (u8)data->fw_tc;
377 memcpy(verify_lprime_in.l_prime, rx_lprime->l_prime,
378 HDCP_2_2_L_PRIME_LEN);
380 byte = mei_cldev_send(cldev, (u8 *)&verify_lprime_in,
381 sizeof(verify_lprime_in));
383 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
387 byte = mei_cldev_recv(cldev, (u8 *)&verify_lprime_out,
388 sizeof(verify_lprime_out));
390 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
394 if (verify_lprime_out.header.status != ME_HDCP_STATUS_SUCCESS) {
395 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
396 WIRED_VALIDATE_LOCALITY,
397 verify_lprime_out.header.status);
405 * mei_hdcp_get_session_key() - Prepare SKE_Send_Eks.
406 * @dev: device corresponding to the mei_cl_device
407 * @data: Intel HW specific hdcp data
408 * @ske_data: SKE_Send_Eks msg output from ME FW.
410 * Return: 0 on Success, <0 on Failure
412 static int mei_hdcp_get_session_key(struct device *dev,
413 struct hdcp_port_data *data,
414 struct hdcp2_ske_send_eks *ske_data)
416 struct wired_cmd_get_session_key_in get_skey_in = { { 0 } };
417 struct wired_cmd_get_session_key_out get_skey_out = { { 0 } };
418 struct mei_cl_device *cldev;
421 if (!dev || !data || !ske_data)
424 cldev = to_mei_cl_device(dev);
426 get_skey_in.header.api_version = HDCP_API_VERSION;
427 get_skey_in.header.command_id = WIRED_GET_SESSION_KEY;
428 get_skey_in.header.status = ME_HDCP_STATUS_SUCCESS;
429 get_skey_in.header.buffer_len = WIRED_CMD_BUF_LEN_GET_SESSION_KEY_IN;
431 get_skey_in.port.integrated_port_type = data->port_type;
432 get_skey_in.port.physical_port = (u8)data->fw_ddi;
433 get_skey_in.port.attached_transcoder = (u8)data->fw_tc;
435 byte = mei_cldev_send(cldev, (u8 *)&get_skey_in, sizeof(get_skey_in));
437 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
441 byte = mei_cldev_recv(cldev, (u8 *)&get_skey_out, sizeof(get_skey_out));
444 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
448 if (get_skey_out.header.status != ME_HDCP_STATUS_SUCCESS) {
449 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
450 WIRED_GET_SESSION_KEY, get_skey_out.header.status);
454 ske_data->msg_id = HDCP_2_2_SKE_SEND_EKS;
455 memcpy(ske_data->e_dkey_ks, get_skey_out.e_dkey_ks,
456 HDCP_2_2_E_DKEY_KS_LEN);
457 memcpy(ske_data->riv, get_skey_out.r_iv, HDCP_2_2_RIV_LEN);
463 * mei_hdcp_repeater_check_flow_prepare_ack() - Validate the Downstream topology
464 * and prepare rep_ack.
465 * @dev: device corresponding to the mei_cl_device
466 * @data: Intel HW specific hdcp data
467 * @rep_topology: Receiver ID List to be validated
468 * @rep_send_ack : repeater ack from ME FW.
470 * Return: 0 on Success, <0 on Failure
473 mei_hdcp_repeater_check_flow_prepare_ack(struct device *dev,
474 struct hdcp_port_data *data,
475 struct hdcp2_rep_send_receiverid_list
477 struct hdcp2_rep_send_ack
480 struct wired_cmd_verify_repeater_in verify_repeater_in = { { 0 } };
481 struct wired_cmd_verify_repeater_out verify_repeater_out = { { 0 } };
482 struct mei_cl_device *cldev;
485 if (!dev || !rep_topology || !rep_send_ack || !data)
488 cldev = to_mei_cl_device(dev);
490 verify_repeater_in.header.api_version = HDCP_API_VERSION;
491 verify_repeater_in.header.command_id = WIRED_VERIFY_REPEATER;
492 verify_repeater_in.header.status = ME_HDCP_STATUS_SUCCESS;
493 verify_repeater_in.header.buffer_len =
494 WIRED_CMD_BUF_LEN_VERIFY_REPEATER_IN;
496 verify_repeater_in.port.integrated_port_type = data->port_type;
497 verify_repeater_in.port.physical_port = (u8)data->fw_ddi;
498 verify_repeater_in.port.attached_transcoder = (u8)data->fw_tc;
500 memcpy(verify_repeater_in.rx_info, rep_topology->rx_info,
501 HDCP_2_2_RXINFO_LEN);
502 memcpy(verify_repeater_in.seq_num_v, rep_topology->seq_num_v,
503 HDCP_2_2_SEQ_NUM_LEN);
504 memcpy(verify_repeater_in.v_prime, rep_topology->v_prime,
505 HDCP_2_2_V_PRIME_HALF_LEN);
506 memcpy(verify_repeater_in.receiver_ids, rep_topology->receiver_ids,
507 HDCP_2_2_RECEIVER_IDS_MAX_LEN);
509 byte = mei_cldev_send(cldev, (u8 *)&verify_repeater_in,
510 sizeof(verify_repeater_in));
512 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
516 byte = mei_cldev_recv(cldev, (u8 *)&verify_repeater_out,
517 sizeof(verify_repeater_out));
519 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
523 if (verify_repeater_out.header.status != ME_HDCP_STATUS_SUCCESS) {
524 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
525 WIRED_VERIFY_REPEATER,
526 verify_repeater_out.header.status);
530 memcpy(rep_send_ack->v, verify_repeater_out.v,
531 HDCP_2_2_V_PRIME_HALF_LEN);
532 rep_send_ack->msg_id = HDCP_2_2_REP_SEND_ACK;
538 * mei_hdcp_verify_mprime() - Verify mprime.
539 * @dev: device corresponding to the mei_cl_device
540 * @data: Intel HW specific hdcp data
541 * @stream_ready: RepeaterAuth_Stream_Ready msg for ME FW verification.
543 * Return: 0 on Success, <0 on Failure
545 static int mei_hdcp_verify_mprime(struct device *dev,
546 struct hdcp_port_data *data,
547 struct hdcp2_rep_stream_ready *stream_ready)
549 struct wired_cmd_repeater_auth_stream_req_in *verify_mprime_in;
550 struct wired_cmd_repeater_auth_stream_req_out
551 verify_mprime_out = { { 0 } };
552 struct mei_cl_device *cldev;
556 if (!dev || !stream_ready || !data)
559 cldev = to_mei_cl_device(dev);
561 cmd_size = struct_size(verify_mprime_in, streams, data->k);
562 if (cmd_size == SIZE_MAX)
565 verify_mprime_in = kzalloc(cmd_size, GFP_KERNEL);
566 if (!verify_mprime_in)
569 verify_mprime_in->header.api_version = HDCP_API_VERSION;
570 verify_mprime_in->header.command_id = WIRED_REPEATER_AUTH_STREAM_REQ;
571 verify_mprime_in->header.status = ME_HDCP_STATUS_SUCCESS;
572 verify_mprime_in->header.buffer_len = cmd_size - sizeof(verify_mprime_in->header);
574 verify_mprime_in->port.integrated_port_type = data->port_type;
575 verify_mprime_in->port.physical_port = (u8)data->fw_ddi;
576 verify_mprime_in->port.attached_transcoder = (u8)data->fw_tc;
578 memcpy(verify_mprime_in->m_prime, stream_ready->m_prime, HDCP_2_2_MPRIME_LEN);
579 drm_hdcp_cpu_to_be24(verify_mprime_in->seq_num_m, data->seq_num_m);
581 memcpy(verify_mprime_in->streams, data->streams,
582 array_size(data->k, sizeof(*data->streams)));
584 verify_mprime_in->k = cpu_to_be16(data->k);
586 byte = mei_cldev_send(cldev, (u8 *)verify_mprime_in, cmd_size);
587 kfree(verify_mprime_in);
589 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
593 byte = mei_cldev_recv(cldev, (u8 *)&verify_mprime_out,
594 sizeof(verify_mprime_out));
596 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
600 if (verify_mprime_out.header.status != ME_HDCP_STATUS_SUCCESS) {
601 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
602 WIRED_REPEATER_AUTH_STREAM_REQ,
603 verify_mprime_out.header.status);
611 * mei_hdcp_enable_authentication() - Mark a port as authenticated
613 * @dev: device corresponding to the mei_cl_device
614 * @data: Intel HW specific hdcp data
616 * Return: 0 on Success, <0 on Failure
618 static int mei_hdcp_enable_authentication(struct device *dev,
619 struct hdcp_port_data *data)
621 struct wired_cmd_enable_auth_in enable_auth_in = { { 0 } };
622 struct wired_cmd_enable_auth_out enable_auth_out = { { 0 } };
623 struct mei_cl_device *cldev;
629 cldev = to_mei_cl_device(dev);
631 enable_auth_in.header.api_version = HDCP_API_VERSION;
632 enable_auth_in.header.command_id = WIRED_ENABLE_AUTH;
633 enable_auth_in.header.status = ME_HDCP_STATUS_SUCCESS;
634 enable_auth_in.header.buffer_len = WIRED_CMD_BUF_LEN_ENABLE_AUTH_IN;
636 enable_auth_in.port.integrated_port_type = data->port_type;
637 enable_auth_in.port.physical_port = (u8)data->fw_ddi;
638 enable_auth_in.port.attached_transcoder = (u8)data->fw_tc;
639 enable_auth_in.stream_type = data->streams[0].stream_type;
641 byte = mei_cldev_send(cldev, (u8 *)&enable_auth_in,
642 sizeof(enable_auth_in));
644 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
648 byte = mei_cldev_recv(cldev, (u8 *)&enable_auth_out,
649 sizeof(enable_auth_out));
651 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
655 if (enable_auth_out.header.status != ME_HDCP_STATUS_SUCCESS) {
656 dev_dbg(dev, "ME cmd 0x%08X failed. status: 0x%X\n",
657 WIRED_ENABLE_AUTH, enable_auth_out.header.status);
665 * mei_hdcp_close_session() - Close the Wired HDCP Tx session of ME FW per port.
666 * This also disables the authenticated state of the port.
667 * @dev: device corresponding to the mei_cl_device
668 * @data: Intel HW specific hdcp data
670 * Return: 0 on Success, <0 on Failure
673 mei_hdcp_close_session(struct device *dev, struct hdcp_port_data *data)
675 struct wired_cmd_close_session_in session_close_in = { { 0 } };
676 struct wired_cmd_close_session_out session_close_out = { { 0 } };
677 struct mei_cl_device *cldev;
683 cldev = to_mei_cl_device(dev);
685 session_close_in.header.api_version = HDCP_API_VERSION;
686 session_close_in.header.command_id = WIRED_CLOSE_SESSION;
687 session_close_in.header.status = ME_HDCP_STATUS_SUCCESS;
688 session_close_in.header.buffer_len =
689 WIRED_CMD_BUF_LEN_CLOSE_SESSION_IN;
691 session_close_in.port.integrated_port_type = data->port_type;
692 session_close_in.port.physical_port = (u8)data->fw_ddi;
693 session_close_in.port.attached_transcoder = (u8)data->fw_tc;
695 byte = mei_cldev_send(cldev, (u8 *)&session_close_in,
696 sizeof(session_close_in));
698 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
702 byte = mei_cldev_recv(cldev, (u8 *)&session_close_out,
703 sizeof(session_close_out));
705 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
709 if (session_close_out.header.status != ME_HDCP_STATUS_SUCCESS) {
710 dev_dbg(dev, "Session Close Failed. status: 0x%X\n",
711 session_close_out.header.status);
718 static const struct i915_hdcp_component_ops mei_hdcp_ops = {
719 .owner = THIS_MODULE,
720 .initiate_hdcp2_session = mei_hdcp_initiate_session,
721 .verify_receiver_cert_prepare_km =
722 mei_hdcp_verify_receiver_cert_prepare_km,
723 .verify_hprime = mei_hdcp_verify_hprime,
724 .store_pairing_info = mei_hdcp_store_pairing_info,
725 .initiate_locality_check = mei_hdcp_initiate_locality_check,
726 .verify_lprime = mei_hdcp_verify_lprime,
727 .get_session_key = mei_hdcp_get_session_key,
728 .repeater_check_flow_prepare_ack =
729 mei_hdcp_repeater_check_flow_prepare_ack,
730 .verify_mprime = mei_hdcp_verify_mprime,
731 .enable_hdcp_authentication = mei_hdcp_enable_authentication,
732 .close_hdcp_session = mei_hdcp_close_session,
735 static int mei_component_master_bind(struct device *dev)
737 struct mei_cl_device *cldev = to_mei_cl_device(dev);
738 struct i915_hdcp_comp_master *comp_master =
739 mei_cldev_get_drvdata(cldev);
742 dev_dbg(dev, "%s\n", __func__);
743 comp_master->ops = &mei_hdcp_ops;
744 comp_master->mei_dev = dev;
745 ret = component_bind_all(dev, comp_master);
752 static void mei_component_master_unbind(struct device *dev)
754 struct mei_cl_device *cldev = to_mei_cl_device(dev);
755 struct i915_hdcp_comp_master *comp_master =
756 mei_cldev_get_drvdata(cldev);
758 dev_dbg(dev, "%s\n", __func__);
759 component_unbind_all(dev, comp_master);
762 static const struct component_master_ops mei_component_master_ops = {
763 .bind = mei_component_master_bind,
764 .unbind = mei_component_master_unbind,
768 * mei_hdcp_component_match - compare function for matching mei hdcp.
770 * The function checks if the driver is i915, the subcomponent is HDCP
771 * and the grand parent of hdcp and the parent of i915 are the same
774 * @dev: master device
775 * @subcomponent: subcomponent to match (I915_COMPONENT_HDCP)
776 * @data: compare data (mei hdcp device)
779 * * 1 - if components match
782 static int mei_hdcp_component_match(struct device *dev, int subcomponent,
785 struct device *base = data;
787 if (strcmp(dev->driver->name, "i915") ||
788 subcomponent != I915_COMPONENT_HDCP)
798 return (base && dev && dev == base);
801 static int mei_hdcp_probe(struct mei_cl_device *cldev,
802 const struct mei_cl_device_id *id)
804 struct i915_hdcp_comp_master *comp_master;
805 struct component_match *master_match;
808 ret = mei_cldev_enable(cldev);
810 dev_err(&cldev->dev, "mei_cldev_enable Failed. %d\n", ret);
811 goto enable_err_exit;
814 comp_master = kzalloc(sizeof(*comp_master), GFP_KERNEL);
821 component_match_add_typed(&cldev->dev, &master_match,
822 mei_hdcp_component_match, &cldev->dev);
823 if (IS_ERR_OR_NULL(master_match)) {
828 mei_cldev_set_drvdata(cldev, comp_master);
829 ret = component_master_add_with_match(&cldev->dev,
830 &mei_component_master_ops,
833 dev_err(&cldev->dev, "Master comp add failed %d\n", ret);
840 mei_cldev_set_drvdata(cldev, NULL);
842 mei_cldev_disable(cldev);
847 static void mei_hdcp_remove(struct mei_cl_device *cldev)
849 struct i915_hdcp_comp_master *comp_master =
850 mei_cldev_get_drvdata(cldev);
853 component_master_del(&cldev->dev, &mei_component_master_ops);
855 mei_cldev_set_drvdata(cldev, NULL);
857 ret = mei_cldev_disable(cldev);
859 dev_warn(&cldev->dev, "mei_cldev_disable() failed\n");
862 #define MEI_UUID_HDCP GUID_INIT(0xB638AB7E, 0x94E2, 0x4EA2, 0xA5, \
863 0x52, 0xD1, 0xC5, 0x4B, 0x62, 0x7F, 0x04)
865 static const struct mei_cl_device_id mei_hdcp_tbl[] = {
866 { .uuid = MEI_UUID_HDCP, .version = MEI_CL_VERSION_ANY },
869 MODULE_DEVICE_TABLE(mei, mei_hdcp_tbl);
871 static struct mei_cl_driver mei_hdcp_driver = {
872 .id_table = mei_hdcp_tbl,
873 .name = KBUILD_MODNAME,
874 .probe = mei_hdcp_probe,
875 .remove = mei_hdcp_remove,
878 module_mei_cl_driver(mei_hdcp_driver);
880 MODULE_AUTHOR("Intel Corporation");
881 MODULE_LICENSE("GPL");
882 MODULE_DESCRIPTION("MEI HDCP");