1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2021 NXP
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
10 #include <fsl_dprc_cmd.h>
17 * dprc_open() - Open DPRC object for use
18 * @mc_io: Pointer to MC portal's I/O object
19 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
20 * @container_id: Container ID to open
21 * @token: Returned token of DPRC object
23 * Return: '0' on Success; Error code otherwise.
25 * @warning Required before any operation on the object.
27 int dprc_open(struct fsl_mc_io *mc_io,
32 struct mc_command cmd = { 0 };
33 struct dprc_cmd_open *cmd_params;
37 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
39 cmd_params = (struct dprc_cmd_open *)cmd.params;
40 cmd_params->container_id = cpu_to_le32(container_id);
42 /* send command to mc*/
43 err = mc_send_command(mc_io, &cmd);
47 /* retrieve response parameters */
48 *token = mc_cmd_hdr_read_token(&cmd);
54 * dprc_close() - Close the control session of the object
55 * @mc_io: Pointer to MC portal's I/O object
56 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
57 * @token: Token of DPRC object
59 * After this function is called, no further operations are
60 * allowed on the object without opening a new control session.
62 * Return: '0' on Success; Error code otherwise.
64 int dprc_close(struct fsl_mc_io *mc_io,
68 struct mc_command cmd = { 0 };
71 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
74 /* send command to mc*/
75 return mc_send_command(mc_io, &cmd);
79 * dprc_get_connection() - Get connected endpoint and link status if connection
81 * @mc_io: Pointer to MC portal's I/O object
82 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
83 * @token: Token of DPRC object
84 * @endpoint1: Endpoint 1 configuration parameters
85 * @endpoint2: Returned endpoint 2 configuration parameters
86 * @state: Returned link state:
89 * -1 - no connection (endpoint2 information is irrelevant)
91 * Return: '0' on Success; -ENAVAIL if connection does not exist.
93 int dprc_get_connection(struct fsl_mc_io *mc_io,
96 const struct dprc_endpoint *endpoint1,
97 struct dprc_endpoint *endpoint2,
100 struct mc_command cmd = { 0 };
101 struct dprc_cmd_get_connection *cmd_params;
102 struct dprc_rsp_get_connection *rsp_params;
105 /* prepare command */
106 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
109 cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
110 cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
111 cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id);
112 for (i = 0; i < 16; i++)
113 cmd_params->ep1_type[i] = endpoint1->type[i];
115 /* send command to mc*/
116 err = mc_send_command(mc_io, &cmd);
120 /* retrieve response parameters */
121 rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
122 endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
123 endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id);
124 *state = le32_to_cpu(rsp_params->state);
125 for (i = 0; i < 16; i++)
126 endpoint2->type[i] = rsp_params->ep2_type[i];