1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2 * 3 * Copyright 2013-2016 Freescale Semiconductor Inc. 4 * Copyright 2017-2019 NXP 5 * 6 */ 7 #include <fsl_mc_sys.h> 8 #include <fsl_mc_cmd.h> 9 #include <fsl_dpcon.h> 10 #include <fsl_dpcon_cmd.h> 11 12 /** 13 * dpcon_open() - Open a control session for the specified object 14 * @mc_io: Pointer to MC portal's I/O object 15 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 16 * @dpcon_id: DPCON unique ID 17 * @token: Returned token; use in subsequent API calls 18 * 19 * This function can be used to open a control session for an 20 * already created object; an object may have been declared in 21 * the DPL or by calling the dpcon_create() function. 22 * This function returns a unique authentication token, 23 * associated with the specific object ID and the specific MC 24 * portal; this token must be used in all subsequent commands for 25 * this specific object. 26 * 27 * Return: '0' on Success; Error code otherwise. 28 */ 29 int dpcon_open(struct fsl_mc_io *mc_io, 30 uint32_t cmd_flags, 31 int dpcon_id, 32 uint16_t *token) 33 { 34 struct mc_command cmd = { 0 }; 35 struct dpcon_cmd_open *dpcon_cmd; 36 int err; 37 38 /* prepare command */ 39 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN, 40 cmd_flags, 41 0); 42 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params; 43 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id); 44 45 /* send command to mc*/ 46 err = mc_send_command(mc_io, &cmd); 47 if (err) 48 return err; 49 50 /* retrieve response parameters */ 51 *token = mc_cmd_hdr_read_token(&cmd); 52 53 return 0; 54 } 55 56 /** 57 * dpcon_close() - Close the control session of the object 58 * @mc_io: Pointer to MC portal's I/O object 59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 60 * @token: Token of DPCON object 61 * 62 * After this function is called, no further operations are 63 * allowed on the object without opening a new control session. 64 * 65 * Return: '0' on Success; Error code otherwise. 66 */ 67 int dpcon_close(struct fsl_mc_io *mc_io, 68 uint32_t cmd_flags, 69 uint16_t token) 70 { 71 struct mc_command cmd = { 0 }; 72 73 /* prepare command */ 74 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE, 75 cmd_flags, 76 token); 77 78 /* send command to mc*/ 79 return mc_send_command(mc_io, &cmd); 80 } 81 82 /** 83 * dpcon_create() - Create the DPCON object. 84 * @mc_io: Pointer to MC portal's I/O object 85 * @dprc_token: Parent container token; '0' for default container 86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 87 * @cfg: Configuration structure 88 * @obj_id: Returned object id; use in subsequent API calls 89 * 90 * Create the DPCON object, allocate required resources and 91 * perform required initialization. 92 * 93 * The object can be created either by declaring it in the 94 * DPL file, or by calling this function. 95 * 96 * This function accepts an authentication token of a parent 97 * container that this object should be assigned to and returns 98 * an object id. This object_id will be used in all subsequent calls to 99 * this specific object. 100 * 101 * Return: '0' on Success; Error code otherwise. 102 */ 103 int dpcon_create(struct fsl_mc_io *mc_io, 104 uint16_t dprc_token, 105 uint32_t cmd_flags, 106 const struct dpcon_cfg *cfg, 107 uint32_t *obj_id) 108 { 109 struct dpcon_cmd_create *dpcon_cmd; 110 struct mc_command cmd = { 0 }; 111 int err; 112 113 /* prepare command */ 114 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CREATE, 115 cmd_flags, 116 dprc_token); 117 dpcon_cmd = (struct dpcon_cmd_create *)cmd.params; 118 dpcon_cmd->num_priorities = cfg->num_priorities; 119 120 /* send command to mc*/ 121 err = mc_send_command(mc_io, &cmd); 122 if (err) 123 return err; 124 125 /* retrieve response parameters */ 126 *obj_id = mc_cmd_read_object_id(&cmd); 127 128 return 0; 129 } 130 131 /** 132 * dpcon_destroy() - Destroy the DPCON object and release all its resources. 133 * @mc_io: Pointer to MC portal's I/O object 134 * @dprc_token: Parent container token; '0' for default container 135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 136 * @obj_id: ID of DPCON object 137 * 138 * Return: '0' on Success; error code otherwise. 139 */ 140 int dpcon_destroy(struct fsl_mc_io *mc_io, 141 uint16_t dprc_token, 142 uint32_t cmd_flags, 143 uint32_t obj_id) 144 { 145 struct dpcon_cmd_destroy *cmd_params; 146 struct mc_command cmd = { 0 }; 147 148 /* prepare command */ 149 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DESTROY, 150 cmd_flags, 151 dprc_token); 152 cmd_params = (struct dpcon_cmd_destroy *)cmd.params; 153 cmd_params->object_id = cpu_to_le32(obj_id); 154 155 /* send command to mc*/ 156 return mc_send_command(mc_io, &cmd); 157 } 158 159 /** 160 * dpcon_enable() - Enable the DPCON 161 * @mc_io: Pointer to MC portal's I/O object 162 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 163 * @token: Token of DPCON object 164 * 165 * Return: '0' on Success; Error code otherwise 166 */ 167 int dpcon_enable(struct fsl_mc_io *mc_io, 168 uint32_t cmd_flags, 169 uint16_t token) 170 { 171 struct mc_command cmd = { 0 }; 172 173 /* prepare command */ 174 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE, 175 cmd_flags, 176 token); 177 178 /* send command to mc*/ 179 return mc_send_command(mc_io, &cmd); 180 } 181 182 /** 183 * dpcon_disable() - Disable the DPCON 184 * @mc_io: Pointer to MC portal's I/O object 185 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 186 * @token: Token of DPCON object 187 * 188 * Return: '0' on Success; Error code otherwise 189 */ 190 int dpcon_disable(struct fsl_mc_io *mc_io, 191 uint32_t cmd_flags, 192 uint16_t token) 193 { 194 struct mc_command cmd = { 0 }; 195 196 /* prepare command */ 197 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE, 198 cmd_flags, 199 token); 200 201 /* send command to mc*/ 202 return mc_send_command(mc_io, &cmd); 203 } 204 205 /** 206 * dpcon_is_enabled() - Check if the DPCON is enabled. 207 * @mc_io: Pointer to MC portal's I/O object 208 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 209 * @token: Token of DPCON object 210 * @en: Returns '1' if object is enabled; '0' otherwise 211 * 212 * Return: '0' on Success; Error code otherwise. 213 */ 214 int dpcon_is_enabled(struct fsl_mc_io *mc_io, 215 uint32_t cmd_flags, 216 uint16_t token, 217 int *en) 218 { 219 struct dpcon_rsp_is_enabled *dpcon_rsp; 220 struct mc_command cmd = { 0 }; 221 int err; 222 223 /* prepare command */ 224 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED, 225 cmd_flags, 226 token); 227 228 /* send command to mc*/ 229 err = mc_send_command(mc_io, &cmd); 230 if (err) 231 return err; 232 233 /* retrieve response parameters */ 234 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params; 235 *en = dpcon_rsp->enabled & DPCON_ENABLE; 236 237 return 0; 238 } 239 240 /** 241 * dpcon_reset() - Reset the DPCON, returns the object to initial state. 242 * @mc_io: Pointer to MC portal's I/O object 243 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 244 * @token: Token of DPCON object 245 * 246 * Return: '0' on Success; Error code otherwise. 247 */ 248 int dpcon_reset(struct fsl_mc_io *mc_io, 249 uint32_t cmd_flags, 250 uint16_t token) 251 { 252 struct mc_command cmd = { 0 }; 253 254 /* prepare command */ 255 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET, 256 cmd_flags, token); 257 258 /* send command to mc*/ 259 return mc_send_command(mc_io, &cmd); 260 } 261 262 /** 263 * dpcon_get_attributes() - Retrieve DPCON attributes. 264 * @mc_io: Pointer to MC portal's I/O object 265 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 266 * @token: Token of DPCON object 267 * @attr: Object's attributes 268 * 269 * Return: '0' on Success; Error code otherwise. 270 */ 271 int dpcon_get_attributes(struct fsl_mc_io *mc_io, 272 uint32_t cmd_flags, 273 uint16_t token, 274 struct dpcon_attr *attr) 275 { 276 struct dpcon_rsp_get_attr *dpcon_rsp; 277 struct mc_command cmd = { 0 }; 278 int err; 279 280 /* prepare command */ 281 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR, 282 cmd_flags, 283 token); 284 285 /* send command to mc*/ 286 err = mc_send_command(mc_io, &cmd); 287 if (err) 288 return err; 289 290 /* retrieve response parameters */ 291 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params; 292 attr->id = le32_to_cpu(dpcon_rsp->id); 293 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id); 294 attr->num_priorities = dpcon_rsp->num_priorities; 295 296 return 0; 297 } 298 299 /** 300 * dpcon_get_api_version - Get Data Path Concentrator API version 301 * @mc_io: Pointer to MC portal's DPCON object 302 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 303 * @major_ver: Major version of DPCON API 304 * @minor_ver: Minor version of DPCON API 305 * 306 * Return: '0' on Success; Error code otherwise 307 */ 308 int dpcon_get_api_version(struct fsl_mc_io *mc_io, 309 uint32_t cmd_flags, 310 uint16_t *major_ver, 311 uint16_t *minor_ver) 312 { 313 struct dpcon_rsp_get_api_version *rsp_params; 314 struct mc_command cmd = { 0 }; 315 int err; 316 317 /* prepare command */ 318 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION, 319 cmd_flags, 0); 320 321 /* send command to mc */ 322 err = mc_send_command(mc_io, &cmd); 323 if (err) 324 return err; 325 326 /* retrieve response parameters */ 327 rsp_params = (struct dpcon_rsp_get_api_version *)cmd.params; 328 *major_ver = le16_to_cpu(rsp_params->major); 329 *minor_ver = le16_to_cpu(rsp_params->minor); 330 331 return 0; 332 } 333