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 : : #include <eal_export.h> 12 : : 13 : : /** @addtogroup dprc 14 : : * @{ 15 : : */ 16 : : 17 : : /** 18 : : * dprc_open() - Open DPRC object for use 19 : : * @mc_io: Pointer to MC portal's I/O object 20 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 21 : : * @container_id: Container ID to open 22 : : * @token: Returned token of DPRC object 23 : : * 24 : : * Return: '0' on Success; Error code otherwise. 25 : : * 26 : : * @warning Required before any operation on the object. 27 : : */ 28 : 0 : int dprc_open(struct fsl_mc_io *mc_io, 29 : : uint32_t cmd_flags, 30 : : int container_id, 31 : : uint16_t *token) 32 : : { 33 : 0 : struct mc_command cmd = { 0 }; 34 : : struct dprc_cmd_open *cmd_params; 35 : : int err; 36 : : 37 : : /* prepare command */ 38 : 0 : cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags, 39 : : 0); 40 : : cmd_params = (struct dprc_cmd_open *)cmd.params; 41 : 0 : cmd_params->container_id = cpu_to_le32(container_id); 42 : : 43 : : /* send command to mc*/ 44 : 0 : err = mc_send_command(mc_io, &cmd); 45 [ # # ]: 0 : if (err) 46 : : return err; 47 : : 48 : : /* retrieve response parameters */ 49 : 0 : *token = mc_cmd_hdr_read_token(&cmd); 50 : : 51 : 0 : return 0; 52 : : } 53 : : 54 : : /** 55 : : * dprc_close() - Close the control session of the object 56 : : * @mc_io: Pointer to MC portal's I/O object 57 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 58 : : * @token: Token of DPRC object 59 : : * 60 : : * After this function is called, no further operations are 61 : : * allowed on the object without opening a new control session. 62 : : * 63 : : * Return: '0' on Success; Error code otherwise. 64 : : */ 65 : 0 : int dprc_close(struct fsl_mc_io *mc_io, 66 : : uint32_t cmd_flags, 67 : : uint16_t token) 68 : : { 69 : 0 : struct mc_command cmd = { 0 }; 70 : : 71 : : /* prepare command */ 72 : 0 : cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags, 73 : : token); 74 : : 75 : : /* send command to mc*/ 76 : 0 : return mc_send_command(mc_io, &cmd); 77 : : } 78 : : 79 : : /** 80 : : * dprc_get_connection() - Get connected endpoint and link status if connection 81 : : * exists. 82 : : * @mc_io: Pointer to MC portal's I/O object 83 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 84 : : * @token: Token of DPRC object 85 : : * @endpoint1: Endpoint 1 configuration parameters 86 : : * @endpoint2: Returned endpoint 2 configuration parameters 87 : : * @state: Returned link state: 88 : : * 1 - link is up; 89 : : * 0 - link is down; 90 : : * -1 - no connection (endpoint2 information is irrelevant) 91 : : * 92 : : * Return: '0' on Success; -ENAVAIL if connection does not exist. 93 : : */ 94 : : RTE_EXPORT_INTERNAL_SYMBOL(dprc_get_connection) 95 : 0 : int dprc_get_connection(struct fsl_mc_io *mc_io, 96 : : uint32_t cmd_flags, 97 : : uint16_t token, 98 : : const struct dprc_endpoint *endpoint1, 99 : : struct dprc_endpoint *endpoint2, 100 : : int *state) 101 : : { 102 : 0 : struct mc_command cmd = { 0 }; 103 : : struct dprc_cmd_get_connection *cmd_params; 104 : : struct dprc_rsp_get_connection *rsp_params; 105 : : int err, i; 106 : : 107 : : /* prepare command */ 108 : 0 : cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, 109 : : cmd_flags, 110 : : token); 111 : : cmd_params = (struct dprc_cmd_get_connection *)cmd.params; 112 : 0 : cmd_params->ep1_id = cpu_to_le32(endpoint1->id); 113 : 0 : cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id); 114 [ # # ]: 0 : for (i = 0; i < 16; i++) 115 : 0 : cmd_params->ep1_type[i] = endpoint1->type[i]; 116 : : 117 : : /* send command to mc*/ 118 : 0 : err = mc_send_command(mc_io, &cmd); 119 [ # # ]: 0 : if (err) 120 : : return err; 121 : : 122 : : /* retrieve response parameters */ 123 : : rsp_params = (struct dprc_rsp_get_connection *)cmd.params; 124 : 0 : endpoint2->id = le32_to_cpu(rsp_params->ep2_id); 125 : 0 : endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id); 126 : 0 : *state = le32_to_cpu(rsp_params->state); 127 [ # # ]: 0 : for (i = 0; i < 16; i++) 128 : 0 : endpoint2->type[i] = rsp_params->ep2_type[i]; 129 : : 130 : : return 0; 131 : : }