Branch data Line data Source code
1 : : /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2 : : * 3 : : * Copyright 2013-2016 Freescale Semiconductor Inc. 4 : : * Copyright 2016-2021 NXP 5 : : * 6 : : */ 7 : : #include <fsl_mc_sys.h> 8 : : #include <fsl_mc_cmd.h> 9 : : #include <fsl_dprc.h> 10 : : #include <fsl_dprc_cmd.h> 11 : : 12 : : /** @addtogroup dprc 13 : : * @{ 14 : : */ 15 : : 16 : : /** 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 22 : : * 23 : : * Return: '0' on Success; Error code otherwise. 24 : : * 25 : : * @warning Required before any operation on the object. 26 : : */ 27 : 0 : int dprc_open(struct fsl_mc_io *mc_io, 28 : : uint32_t cmd_flags, 29 : : int container_id, 30 : : uint16_t *token) 31 : : { 32 : 0 : struct mc_command cmd = { 0 }; 33 : : struct dprc_cmd_open *cmd_params; 34 : : int err; 35 : : 36 : : /* prepare command */ 37 : 0 : cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags, 38 : : 0); 39 : : cmd_params = (struct dprc_cmd_open *)cmd.params; 40 : 0 : cmd_params->container_id = cpu_to_le32(container_id); 41 : : 42 : : /* send command to mc*/ 43 : 0 : err = mc_send_command(mc_io, &cmd); 44 [ # # ]: 0 : if (err) 45 : : return err; 46 : : 47 : : /* retrieve response parameters */ 48 : 0 : *token = mc_cmd_hdr_read_token(&cmd); 49 : : 50 : 0 : return 0; 51 : : } 52 : : 53 : : /** 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 58 : : * 59 : : * After this function is called, no further operations are 60 : : * allowed on the object without opening a new control session. 61 : : * 62 : : * Return: '0' on Success; Error code otherwise. 63 : : */ 64 : 0 : int dprc_close(struct fsl_mc_io *mc_io, 65 : : uint32_t cmd_flags, 66 : : uint16_t token) 67 : : { 68 : 0 : struct mc_command cmd = { 0 }; 69 : : 70 : : /* prepare command */ 71 : 0 : cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags, 72 : : token); 73 : : 74 : : /* send command to mc*/ 75 : 0 : return mc_send_command(mc_io, &cmd); 76 : : } 77 : : 78 : : /** 79 : : * dprc_get_connection() - Get connected endpoint and link status if connection 80 : : * exists. 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: 87 : : * 1 - link is up; 88 : : * 0 - link is down; 89 : : * -1 - no connection (endpoint2 information is irrelevant) 90 : : * 91 : : * Return: '0' on Success; -ENAVAIL if connection does not exist. 92 : : */ 93 : 0 : int dprc_get_connection(struct fsl_mc_io *mc_io, 94 : : uint32_t cmd_flags, 95 : : uint16_t token, 96 : : const struct dprc_endpoint *endpoint1, 97 : : struct dprc_endpoint *endpoint2, 98 : : int *state) 99 : : { 100 : 0 : struct mc_command cmd = { 0 }; 101 : : struct dprc_cmd_get_connection *cmd_params; 102 : : struct dprc_rsp_get_connection *rsp_params; 103 : : int err, i; 104 : : 105 : : /* prepare command */ 106 : 0 : cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, 107 : : cmd_flags, 108 : : token); 109 : : cmd_params = (struct dprc_cmd_get_connection *)cmd.params; 110 : 0 : cmd_params->ep1_id = cpu_to_le32(endpoint1->id); 111 : 0 : cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id); 112 [ # # ]: 0 : for (i = 0; i < 16; i++) 113 : 0 : cmd_params->ep1_type[i] = endpoint1->type[i]; 114 : : 115 : : /* send command to mc*/ 116 : 0 : err = mc_send_command(mc_io, &cmd); 117 [ # # ]: 0 : if (err) 118 : : return err; 119 : : 120 : : /* retrieve response parameters */ 121 : : rsp_params = (struct dprc_rsp_get_connection *)cmd.params; 122 : 0 : endpoint2->id = le32_to_cpu(rsp_params->ep2_id); 123 : 0 : endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id); 124 : 0 : *state = le32_to_cpu(rsp_params->state); 125 [ # # ]: 0 : for (i = 0; i < 16; i++) 126 : 0 : endpoint2->type[i] = rsp_params->ep2_type[i]; 127 : : 128 : : return 0; 129 : : }