Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1 | /* Copyright 2013-2016 Freescale Semiconductor Inc. |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are met: |
| 5 | * * Redistributions of source code must retain the above copyright |
| 6 | * notice, this list of conditions and the following disclaimer. |
| 7 | * * Redistributions in binary form must reproduce the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer in the |
| 9 | * documentation and/or other materials provided with the distribution. |
| 10 | * * Neither the name of the above-listed copyright holders nor the |
| 11 | * names of any contributors may be used to endorse or promote products |
| 12 | * derived from this software without specific prior written permission. |
| 13 | * |
| 14 | * |
| 15 | * ALTERNATIVELY, this software may be distributed under the terms of the |
| 16 | * GNU General Public License ("GPL") as published by the Free Software |
| 17 | * Foundation, either version 2 of that License or (at your option) any |
| 18 | * later version. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | * POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | #include "../include/mc-sys.h" |
| 33 | #include "../include/mc-cmd.h" |
| 34 | #include "../include/dprc.h" |
| 35 | #include "dprc-cmd.h" |
| 36 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 37 | /** |
| 38 | * dprc_open() - Open DPRC object for use |
| 39 | * @mc_io: Pointer to MC portal's I/O object |
| 40 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 41 | * @container_id: Container ID to open |
| 42 | * @token: Returned token of DPRC object |
| 43 | * |
| 44 | * Return: '0' on Success; Error code otherwise. |
| 45 | * |
| 46 | * @warning Required before any operation on the object. |
| 47 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 48 | int dprc_open(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 49 | u32 cmd_flags, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 50 | int container_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 51 | u16 *token) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 52 | { |
| 53 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 54 | struct dprc_cmd_open *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 55 | int err; |
| 56 | |
| 57 | /* prepare command */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 58 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 59 | 0); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 60 | cmd_params = (struct dprc_cmd_open *)cmd.params; |
| 61 | cmd_params->container_id = cpu_to_le32(container_id); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 62 | |
| 63 | /* send command to mc*/ |
| 64 | err = mc_send_command(mc_io, &cmd); |
| 65 | if (err) |
| 66 | return err; |
| 67 | |
| 68 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 69 | *token = mc_cmd_hdr_read_token(&cmd); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | EXPORT_SYMBOL(dprc_open); |
| 74 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 75 | /** |
| 76 | * dprc_close() - Close the control session of the object |
| 77 | * @mc_io: Pointer to MC portal's I/O object |
| 78 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 79 | * @token: Token of DPRC object |
| 80 | * |
| 81 | * After this function is called, no further operations are |
| 82 | * allowed on the object without opening a new control session. |
| 83 | * |
| 84 | * Return: '0' on Success; Error code otherwise. |
| 85 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 86 | int dprc_close(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 87 | u32 cmd_flags, |
| 88 | u16 token) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 89 | { |
| 90 | struct mc_command cmd = { 0 }; |
| 91 | |
| 92 | /* prepare command */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 93 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 94 | token); |
| 95 | |
| 96 | /* send command to mc*/ |
| 97 | return mc_send_command(mc_io, &cmd); |
| 98 | } |
| 99 | EXPORT_SYMBOL(dprc_close); |
| 100 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 101 | /** |
| 102 | * dprc_create_container() - Create child container |
| 103 | * @mc_io: Pointer to MC portal's I/O object |
| 104 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 105 | * @token: Token of DPRC object |
| 106 | * @cfg: Child container configuration |
| 107 | * @child_container_id: Returned child container ID |
| 108 | * @child_portal_offset: Returned child portal offset from MC portal base |
| 109 | * |
| 110 | * Return: '0' on Success; Error code otherwise. |
| 111 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 112 | int dprc_create_container(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 113 | u32 cmd_flags, |
| 114 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 115 | struct dprc_cfg *cfg, |
| 116 | int *child_container_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 117 | u64 *child_portal_offset) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 118 | { |
| 119 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 120 | struct dprc_cmd_create_container *cmd_params; |
| 121 | struct dprc_rsp_create_container *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 122 | int err; |
| 123 | |
| 124 | /* prepare command */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 125 | cmd_params = (struct dprc_cmd_create_container *)cmd.params; |
| 126 | cmd_params->options = cpu_to_le32(cfg->options); |
| 127 | cmd_params->icid = cpu_to_le16(cfg->icid); |
| 128 | cmd_params->portal_id = cpu_to_le32(cfg->portal_id); |
| 129 | strncpy(cmd_params->label, cfg->label, 16); |
| 130 | cmd_params->label[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 131 | |
| 132 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 133 | cmd_flags, token); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 134 | |
| 135 | /* send command to mc*/ |
| 136 | err = mc_send_command(mc_io, &cmd); |
| 137 | if (err) |
| 138 | return err; |
| 139 | |
| 140 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 141 | rsp_params = (struct dprc_rsp_create_container *)cmd.params; |
| 142 | *child_container_id = le32_to_cpu(rsp_params->child_container_id); |
| 143 | *child_portal_offset = le64_to_cpu(rsp_params->child_portal_addr); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 148 | /** |
| 149 | * dprc_destroy_container() - Destroy child container. |
| 150 | * @mc_io: Pointer to MC portal's I/O object |
| 151 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 152 | * @token: Token of DPRC object |
| 153 | * @child_container_id: ID of the container to destroy |
| 154 | * |
| 155 | * This function terminates the child container, so following this call the |
| 156 | * child container ID becomes invalid. |
| 157 | * |
| 158 | * Notes: |
| 159 | * - All resources and objects of the destroyed container are returned to the |
| 160 | * parent container or destroyed if were created be the destroyed container. |
| 161 | * - This function destroy all the child containers of the specified |
| 162 | * container prior to destroying the container itself. |
| 163 | * |
| 164 | * warning: Only the parent container is allowed to destroy a child policy |
| 165 | * Container 0 can't be destroyed |
| 166 | * |
| 167 | * Return: '0' on Success; Error code otherwise. |
| 168 | * |
| 169 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 170 | int dprc_destroy_container(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 171 | u32 cmd_flags, |
| 172 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 173 | int child_container_id) |
| 174 | { |
| 175 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 176 | struct dprc_cmd_destroy_container *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 177 | |
| 178 | /* prepare command */ |
| 179 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 180 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 181 | cmd_params = (struct dprc_cmd_destroy_container *)cmd.params; |
| 182 | cmd_params->child_container_id = cpu_to_le32(child_container_id); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 183 | |
| 184 | /* send command to mc*/ |
| 185 | return mc_send_command(mc_io, &cmd); |
| 186 | } |
| 187 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 188 | /** |
| 189 | * dprc_reset_container - Reset child container. |
| 190 | * @mc_io: Pointer to MC portal's I/O object |
| 191 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 192 | * @token: Token of DPRC object |
| 193 | * @child_container_id: ID of the container to reset |
| 194 | * |
| 195 | * In case a software context crashes or becomes non-responsive, the parent |
| 196 | * may wish to reset its resources container before the software context is |
| 197 | * restarted. |
| 198 | * |
| 199 | * This routine informs all objects assigned to the child container that the |
| 200 | * container is being reset, so they may perform any cleanup operations that are |
| 201 | * needed. All objects handles that were owned by the child container shall be |
| 202 | * closed. |
| 203 | * |
| 204 | * Note that such request may be submitted even if the child software context |
| 205 | * has not crashed, but the resulting object cleanup operations will not be |
| 206 | * aware of that. |
| 207 | * |
| 208 | * Return: '0' on Success; Error code otherwise. |
| 209 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 210 | int dprc_reset_container(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 211 | u32 cmd_flags, |
| 212 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 213 | int child_container_id) |
| 214 | { |
| 215 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 216 | struct dprc_cmd_reset_container *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 217 | |
| 218 | /* prepare command */ |
| 219 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 220 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 221 | cmd_params = (struct dprc_cmd_reset_container *)cmd.params; |
| 222 | cmd_params->child_container_id = cpu_to_le32(child_container_id); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 223 | |
| 224 | /* send command to mc*/ |
| 225 | return mc_send_command(mc_io, &cmd); |
| 226 | } |
| 227 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 228 | /** |
| 229 | * dprc_get_irq() - Get IRQ information from the DPRC. |
| 230 | * @mc_io: Pointer to MC portal's I/O object |
| 231 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 232 | * @token: Token of DPRC object |
| 233 | * @irq_index: The interrupt index to configure |
| 234 | * @type: Interrupt type: 0 represents message interrupt |
| 235 | * type (both irq_addr and irq_val are valid) |
| 236 | * @irq_cfg: IRQ attributes |
| 237 | * |
| 238 | * Return: '0' on Success; Error code otherwise. |
| 239 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 240 | int dprc_get_irq(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 241 | u32 cmd_flags, |
| 242 | u16 token, |
| 243 | u8 irq_index, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 244 | int *type, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 245 | struct dprc_irq_cfg *irq_cfg) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 246 | { |
| 247 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 248 | struct dprc_cmd_get_irq *cmd_params; |
| 249 | struct dprc_rsp_get_irq *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 250 | int err; |
| 251 | |
| 252 | /* prepare command */ |
| 253 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 254 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 255 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 256 | cmd_params = (struct dprc_cmd_get_irq *)cmd.params; |
| 257 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 258 | |
| 259 | /* send command to mc*/ |
| 260 | err = mc_send_command(mc_io, &cmd); |
| 261 | if (err) |
| 262 | return err; |
| 263 | |
| 264 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 265 | rsp_params = (struct dprc_rsp_get_irq *)cmd.params; |
| 266 | irq_cfg->val = le32_to_cpu(rsp_params->irq_val); |
| 267 | irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr); |
| 268 | irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num); |
| 269 | *type = le32_to_cpu(rsp_params->type); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 270 | |
| 271 | return 0; |
| 272 | } |
| 273 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 274 | /** |
| 275 | * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt. |
| 276 | * @mc_io: Pointer to MC portal's I/O object |
| 277 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 278 | * @token: Token of DPRC object |
| 279 | * @irq_index: Identifies the interrupt index to configure |
| 280 | * @irq_cfg: IRQ configuration |
| 281 | * |
| 282 | * Return: '0' on Success; Error code otherwise. |
| 283 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 284 | int dprc_set_irq(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 285 | u32 cmd_flags, |
| 286 | u16 token, |
| 287 | u8 irq_index, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 288 | struct dprc_irq_cfg *irq_cfg) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 289 | { |
| 290 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 291 | struct dprc_cmd_set_irq *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 292 | |
| 293 | /* prepare command */ |
| 294 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 295 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 296 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 297 | cmd_params = (struct dprc_cmd_set_irq *)cmd.params; |
| 298 | cmd_params->irq_val = cpu_to_le32(irq_cfg->val); |
| 299 | cmd_params->irq_index = irq_index; |
| 300 | cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr); |
| 301 | cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 302 | |
| 303 | /* send command to mc*/ |
| 304 | return mc_send_command(mc_io, &cmd); |
| 305 | } |
| 306 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 307 | /** |
| 308 | * dprc_get_irq_enable() - Get overall interrupt state. |
| 309 | * @mc_io: Pointer to MC portal's I/O object |
| 310 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 311 | * @token: Token of DPRC object |
| 312 | * @irq_index: The interrupt index to configure |
| 313 | * @en: Returned interrupt state - enable = 1, disable = 0 |
| 314 | * |
| 315 | * Return: '0' on Success; Error code otherwise. |
| 316 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 317 | int dprc_get_irq_enable(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 318 | u32 cmd_flags, |
| 319 | u16 token, |
| 320 | u8 irq_index, |
| 321 | u8 *en) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 322 | { |
| 323 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 324 | struct dprc_cmd_get_irq_enable *cmd_params; |
| 325 | struct dprc_rsp_get_irq_enable *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 326 | int err; |
| 327 | |
| 328 | /* prepare command */ |
| 329 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 330 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 331 | cmd_params = (struct dprc_cmd_get_irq_enable *)cmd.params; |
| 332 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 333 | |
| 334 | /* send command to mc*/ |
| 335 | err = mc_send_command(mc_io, &cmd); |
| 336 | if (err) |
| 337 | return err; |
| 338 | |
| 339 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 340 | rsp_params = (struct dprc_rsp_get_irq_enable *)cmd.params; |
| 341 | *en = rsp_params->enabled & DPRC_ENABLE; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 346 | /** |
| 347 | * dprc_set_irq_enable() - Set overall interrupt state. |
| 348 | * @mc_io: Pointer to MC portal's I/O object |
| 349 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 350 | * @token: Token of DPRC object |
| 351 | * @irq_index: The interrupt index to configure |
| 352 | * @en: Interrupt state - enable = 1, disable = 0 |
| 353 | * |
| 354 | * Allows GPP software to control when interrupts are generated. |
| 355 | * Each interrupt can have up to 32 causes. The enable/disable control's the |
| 356 | * overall interrupt state. if the interrupt is disabled no causes will cause |
| 357 | * an interrupt. |
| 358 | * |
| 359 | * Return: '0' on Success; Error code otherwise. |
| 360 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 361 | int dprc_set_irq_enable(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 362 | u32 cmd_flags, |
| 363 | u16 token, |
| 364 | u8 irq_index, |
| 365 | u8 en) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 366 | { |
| 367 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 368 | struct dprc_cmd_set_irq_enable *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 369 | |
| 370 | /* prepare command */ |
| 371 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 372 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 373 | cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params; |
| 374 | cmd_params->enable = en & DPRC_ENABLE; |
| 375 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 376 | |
| 377 | /* send command to mc*/ |
| 378 | return mc_send_command(mc_io, &cmd); |
| 379 | } |
| 380 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 381 | /** |
| 382 | * dprc_get_irq_mask() - Get interrupt mask. |
| 383 | * @mc_io: Pointer to MC portal's I/O object |
| 384 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 385 | * @token: Token of DPRC object |
| 386 | * @irq_index: The interrupt index to configure |
| 387 | * @mask: Returned event mask to trigger interrupt |
| 388 | * |
| 389 | * Every interrupt can have up to 32 causes and the interrupt model supports |
| 390 | * masking/unmasking each cause independently |
| 391 | * |
| 392 | * Return: '0' on Success; Error code otherwise. |
| 393 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 394 | int dprc_get_irq_mask(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 395 | u32 cmd_flags, |
| 396 | u16 token, |
| 397 | u8 irq_index, |
| 398 | u32 *mask) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 399 | { |
| 400 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 401 | struct dprc_cmd_get_irq_mask *cmd_params; |
| 402 | struct dprc_rsp_get_irq_mask *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 403 | int err; |
| 404 | |
| 405 | /* prepare command */ |
| 406 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 407 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 408 | cmd_params = (struct dprc_cmd_get_irq_mask *)cmd.params; |
| 409 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 410 | |
| 411 | /* send command to mc*/ |
| 412 | err = mc_send_command(mc_io, &cmd); |
| 413 | if (err) |
| 414 | return err; |
| 415 | |
| 416 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 417 | rsp_params = (struct dprc_rsp_get_irq_mask *)cmd.params; |
| 418 | *mask = le32_to_cpu(rsp_params->mask); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 423 | /** |
| 424 | * dprc_set_irq_mask() - Set interrupt mask. |
| 425 | * @mc_io: Pointer to MC portal's I/O object |
| 426 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 427 | * @token: Token of DPRC object |
| 428 | * @irq_index: The interrupt index to configure |
| 429 | * @mask: event mask to trigger interrupt; |
| 430 | * each bit: |
| 431 | * 0 = ignore event |
| 432 | * 1 = consider event for asserting irq |
| 433 | * |
| 434 | * Every interrupt can have up to 32 causes and the interrupt model supports |
| 435 | * masking/unmasking each cause independently |
| 436 | * |
| 437 | * Return: '0' on Success; Error code otherwise. |
| 438 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 439 | int dprc_set_irq_mask(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 440 | u32 cmd_flags, |
| 441 | u16 token, |
| 442 | u8 irq_index, |
| 443 | u32 mask) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 444 | { |
| 445 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 446 | struct dprc_cmd_set_irq_mask *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 447 | |
| 448 | /* prepare command */ |
| 449 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 450 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 451 | cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params; |
| 452 | cmd_params->mask = cpu_to_le32(mask); |
| 453 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 454 | |
| 455 | /* send command to mc*/ |
| 456 | return mc_send_command(mc_io, &cmd); |
| 457 | } |
| 458 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 459 | /** |
| 460 | * dprc_get_irq_status() - Get the current status of any pending interrupts. |
| 461 | * @mc_io: Pointer to MC portal's I/O object |
| 462 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 463 | * @token: Token of DPRC object |
| 464 | * @irq_index: The interrupt index to configure |
| 465 | * @status: Returned interrupts status - one bit per cause: |
| 466 | * 0 = no interrupt pending |
| 467 | * 1 = interrupt pending |
| 468 | * |
| 469 | * Return: '0' on Success; Error code otherwise. |
| 470 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 471 | int dprc_get_irq_status(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 472 | u32 cmd_flags, |
| 473 | u16 token, |
| 474 | u8 irq_index, |
| 475 | u32 *status) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 476 | { |
| 477 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 478 | struct dprc_cmd_get_irq_status *cmd_params; |
| 479 | struct dprc_rsp_get_irq_status *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 480 | int err; |
| 481 | |
| 482 | /* prepare command */ |
| 483 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 484 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 485 | cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params; |
| 486 | cmd_params->status = cpu_to_le32(*status); |
| 487 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 488 | |
| 489 | /* send command to mc*/ |
| 490 | err = mc_send_command(mc_io, &cmd); |
| 491 | if (err) |
| 492 | return err; |
| 493 | |
| 494 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 495 | rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params; |
| 496 | *status = le32_to_cpu(rsp_params->status); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 501 | /** |
| 502 | * dprc_clear_irq_status() - Clear a pending interrupt's status |
| 503 | * @mc_io: Pointer to MC portal's I/O object |
| 504 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 505 | * @token: Token of DPRC object |
| 506 | * @irq_index: The interrupt index to configure |
| 507 | * @status: bits to clear (W1C) - one bit per cause: |
| 508 | * 0 = don't change |
| 509 | * 1 = clear status bit |
| 510 | * |
| 511 | * Return: '0' on Success; Error code otherwise. |
| 512 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 513 | int dprc_clear_irq_status(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 514 | u32 cmd_flags, |
| 515 | u16 token, |
| 516 | u8 irq_index, |
| 517 | u32 status) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 518 | { |
| 519 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 520 | struct dprc_cmd_clear_irq_status *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 521 | |
| 522 | /* prepare command */ |
| 523 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 524 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 525 | cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params; |
| 526 | cmd_params->status = cpu_to_le32(status); |
| 527 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 528 | |
| 529 | /* send command to mc*/ |
| 530 | return mc_send_command(mc_io, &cmd); |
| 531 | } |
| 532 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 533 | /** |
| 534 | * dprc_get_attributes() - Obtains container attributes |
| 535 | * @mc_io: Pointer to MC portal's I/O object |
| 536 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 537 | * @token: Token of DPRC object |
| 538 | * @attributes Returned container attributes |
| 539 | * |
| 540 | * Return: '0' on Success; Error code otherwise. |
| 541 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 542 | int dprc_get_attributes(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 543 | u32 cmd_flags, |
| 544 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 545 | struct dprc_attributes *attr) |
| 546 | { |
| 547 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 548 | struct dprc_rsp_get_attributes *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 549 | int err; |
| 550 | |
| 551 | /* prepare command */ |
| 552 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 553 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 554 | token); |
| 555 | |
| 556 | /* send command to mc*/ |
| 557 | err = mc_send_command(mc_io, &cmd); |
| 558 | if (err) |
| 559 | return err; |
| 560 | |
| 561 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 562 | rsp_params = (struct dprc_rsp_get_attributes *)cmd.params; |
| 563 | attr->container_id = le32_to_cpu(rsp_params->container_id); |
| 564 | attr->icid = le16_to_cpu(rsp_params->icid); |
| 565 | attr->options = le32_to_cpu(rsp_params->options); |
| 566 | attr->portal_id = le32_to_cpu(rsp_params->portal_id); |
| 567 | attr->version.major = le16_to_cpu(rsp_params->version_major); |
| 568 | attr->version.minor = le16_to_cpu(rsp_params->version_minor); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 573 | /** |
| 574 | * dprc_set_res_quota() - Set allocation policy for a specific resource/object |
| 575 | * type in a child container |
| 576 | * @mc_io: Pointer to MC portal's I/O object |
| 577 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 578 | * @token: Token of DPRC object |
| 579 | * @child_container_id: ID of the child container |
| 580 | * @type: Resource/object type |
| 581 | * @quota: Sets the maximum number of resources of the selected type |
| 582 | * that the child container is allowed to allocate from its parent; |
| 583 | * when quota is set to -1, the policy is the same as container's |
| 584 | * general policy. |
| 585 | * |
| 586 | * Allocation policy determines whether or not a container may allocate |
| 587 | * resources from its parent. Each container has a 'global' allocation policy |
| 588 | * that is set when the container is created. |
| 589 | * |
| 590 | * This function sets allocation policy for a specific resource type. |
| 591 | * The default policy for all resource types matches the container's 'global' |
| 592 | * allocation policy. |
| 593 | * |
| 594 | * Return: '0' on Success; Error code otherwise. |
| 595 | * |
| 596 | * @warning Only the parent container is allowed to change a child policy. |
| 597 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 598 | int dprc_set_res_quota(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 599 | u32 cmd_flags, |
| 600 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 601 | int child_container_id, |
| 602 | char *type, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 603 | u16 quota) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 604 | { |
| 605 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 606 | struct dprc_cmd_set_res_quota *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 607 | |
| 608 | /* prepare command */ |
| 609 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 610 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 611 | cmd_params = (struct dprc_cmd_set_res_quota *)cmd.params; |
| 612 | cmd_params->child_container_id = cpu_to_le32(child_container_id); |
| 613 | cmd_params->quota = cpu_to_le16(quota); |
| 614 | strncpy(cmd_params->type, type, 16); |
| 615 | cmd_params->type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 616 | |
| 617 | /* send command to mc*/ |
| 618 | return mc_send_command(mc_io, &cmd); |
| 619 | } |
| 620 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 621 | /** |
| 622 | * dprc_get_res_quota() - Gets the allocation policy of a specific |
| 623 | * resource/object type in a child container |
| 624 | * @mc_io: Pointer to MC portal's I/O object |
| 625 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 626 | * @token: Token of DPRC object |
| 627 | * @child_container_id; ID of the child container |
| 628 | * @type: resource/object type |
| 629 | * @quota: Returnes the maximum number of resources of the selected type |
| 630 | * that the child container is allowed to allocate from the parent; |
| 631 | * when quota is set to -1, the policy is the same as container's |
| 632 | * general policy. |
| 633 | * |
| 634 | * Return: '0' on Success; Error code otherwise. |
| 635 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 636 | int dprc_get_res_quota(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 637 | u32 cmd_flags, |
| 638 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 639 | int child_container_id, |
| 640 | char *type, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 641 | u16 *quota) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 642 | { |
| 643 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 644 | struct dprc_cmd_get_res_quota *cmd_params; |
| 645 | struct dprc_rsp_get_res_quota *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 646 | int err; |
| 647 | |
| 648 | /* prepare command */ |
| 649 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 650 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 651 | cmd_params = (struct dprc_cmd_get_res_quota *)cmd.params; |
| 652 | cmd_params->child_container_id = cpu_to_le32(child_container_id); |
| 653 | strncpy(cmd_params->type, type, 16); |
| 654 | cmd_params->type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 655 | |
| 656 | /* send command to mc*/ |
| 657 | err = mc_send_command(mc_io, &cmd); |
| 658 | if (err) |
| 659 | return err; |
| 660 | |
| 661 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 662 | rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params; |
| 663 | *quota = le16_to_cpu(rsp_params->quota); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 668 | /** |
| 669 | * dprc_assign() - Assigns objects or resource to a child container. |
| 670 | * @mc_io: Pointer to MC portal's I/O object |
| 671 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 672 | * @token: Token of DPRC object |
| 673 | * @container_id: ID of the child container |
| 674 | * @res_req: Describes the type and amount of resources to |
| 675 | * assign to the given container |
| 676 | * |
| 677 | * Assignment is usually done by a parent (this DPRC) to one of its child |
| 678 | * containers. |
| 679 | * |
| 680 | * According to the DPRC allocation policy, the assigned resources may be taken |
| 681 | * (allocated) from the container's ancestors, if not enough resources are |
| 682 | * available in the container itself. |
| 683 | * |
| 684 | * The type of assignment depends on the dprc_res_req options, as follows: |
| 685 | * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have |
| 686 | * the explicit base ID specified at the id_base_align field of res_req. |
| 687 | * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be |
| 688 | * aligned to the value given at id_base_align field of res_req. |
| 689 | * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment, |
| 690 | * and indicates that the object must be set to the plugged state. |
| 691 | * |
| 692 | * A container may use this function with its own ID in order to change a |
| 693 | * object state to plugged or unplugged. |
| 694 | * |
| 695 | * If IRQ information has been set in the child DPRC, it will signal an |
| 696 | * interrupt following every change in its object assignment. |
| 697 | * |
| 698 | * Return: '0' on Success; Error code otherwise. |
| 699 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 700 | int dprc_assign(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 701 | u32 cmd_flags, |
| 702 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 703 | int container_id, |
| 704 | struct dprc_res_req *res_req) |
| 705 | { |
| 706 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 707 | struct dprc_cmd_assign *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 708 | |
| 709 | /* prepare command */ |
| 710 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 711 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 712 | cmd_params = (struct dprc_cmd_assign *)cmd.params; |
| 713 | cmd_params->container_id = cpu_to_le32(container_id); |
| 714 | cmd_params->options = cpu_to_le32(res_req->options); |
| 715 | cmd_params->num = cpu_to_le32(res_req->num); |
| 716 | cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align); |
| 717 | strncpy(cmd_params->type, res_req->type, 16); |
| 718 | cmd_params->type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 719 | |
| 720 | /* send command to mc*/ |
| 721 | return mc_send_command(mc_io, &cmd); |
| 722 | } |
| 723 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 724 | /** |
| 725 | * dprc_unassign() - Un-assigns objects or resources from a child container |
| 726 | * and moves them into this (parent) DPRC. |
| 727 | * @mc_io: Pointer to MC portal's I/O object |
| 728 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 729 | * @token: Token of DPRC object |
| 730 | * @child_container_id: ID of the child container |
| 731 | * @res_req: Describes the type and amount of resources to un-assign from |
| 732 | * the child container |
| 733 | * |
| 734 | * Un-assignment of objects can succeed only if the object is not in the |
| 735 | * plugged or opened state. |
| 736 | * |
| 737 | * Return: '0' on Success; Error code otherwise. |
| 738 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 739 | int dprc_unassign(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 740 | u32 cmd_flags, |
| 741 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 742 | int child_container_id, |
| 743 | struct dprc_res_req *res_req) |
| 744 | { |
| 745 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 746 | struct dprc_cmd_unassign *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 747 | |
| 748 | /* prepare command */ |
| 749 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 750 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 751 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 752 | cmd_params = (struct dprc_cmd_unassign *)cmd.params; |
| 753 | cmd_params->child_container_id = cpu_to_le32(child_container_id); |
| 754 | cmd_params->options = cpu_to_le32(res_req->options); |
| 755 | cmd_params->num = cpu_to_le32(res_req->num); |
| 756 | cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align); |
| 757 | strncpy(cmd_params->type, res_req->type, 16); |
| 758 | cmd_params->type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 759 | |
| 760 | /* send command to mc*/ |
| 761 | return mc_send_command(mc_io, &cmd); |
| 762 | } |
| 763 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 764 | /** |
| 765 | * dprc_get_pool_count() - Get the number of dprc's pools |
| 766 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 767 | * @mc_io: Pointer to MC portal's I/O object |
| 768 | * @token: Token of DPRC object |
| 769 | * @pool_count: Returned number of resource pools in the dprc |
| 770 | * |
| 771 | * Return: '0' on Success; Error code otherwise. |
| 772 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 773 | int dprc_get_pool_count(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 774 | u32 cmd_flags, |
| 775 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 776 | int *pool_count) |
| 777 | { |
| 778 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 779 | struct dprc_rsp_get_pool_count *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 780 | int err; |
| 781 | |
| 782 | /* prepare command */ |
| 783 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 784 | cmd_flags, token); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 785 | |
| 786 | /* send command to mc*/ |
| 787 | err = mc_send_command(mc_io, &cmd); |
| 788 | if (err) |
| 789 | return err; |
| 790 | |
| 791 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 792 | rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params; |
| 793 | *pool_count = le32_to_cpu(rsp_params->pool_count); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 794 | |
| 795 | return 0; |
| 796 | } |
| 797 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 798 | /** |
| 799 | * dprc_get_pool() - Get the type (string) of a certain dprc's pool |
| 800 | * @mc_io: Pointer to MC portal's I/O object |
| 801 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 802 | * @token: Token of DPRC object |
| 803 | * @pool_index; Index of the pool to be queried (< pool_count) |
| 804 | * @type: The type of the pool |
| 805 | * |
| 806 | * The pool types retrieved one by one by incrementing |
| 807 | * pool_index up to (not including) the value of pool_count returned |
| 808 | * from dprc_get_pool_count(). dprc_get_pool_count() must |
| 809 | * be called prior to dprc_get_pool(). |
| 810 | * |
| 811 | * Return: '0' on Success; Error code otherwise. |
| 812 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 813 | int dprc_get_pool(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 814 | u32 cmd_flags, |
| 815 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 816 | int pool_index, |
| 817 | char *type) |
| 818 | { |
| 819 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 820 | struct dprc_cmd_get_pool *cmd_params; |
| 821 | struct dprc_rsp_get_pool *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 822 | int err; |
| 823 | |
| 824 | /* prepare command */ |
| 825 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 826 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 827 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 828 | cmd_params = (struct dprc_cmd_get_pool *)cmd.params; |
| 829 | cmd_params->pool_index = cpu_to_le32(pool_index); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 830 | |
| 831 | /* send command to mc*/ |
| 832 | err = mc_send_command(mc_io, &cmd); |
| 833 | if (err) |
| 834 | return err; |
| 835 | |
| 836 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 837 | rsp_params = (struct dprc_rsp_get_pool *)cmd.params; |
| 838 | strncpy(type, rsp_params->type, 16); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 839 | type[15] = '\0'; |
| 840 | |
| 841 | return 0; |
| 842 | } |
| 843 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 844 | /** |
| 845 | * dprc_get_obj_count() - Obtains the number of objects in the DPRC |
| 846 | * @mc_io: Pointer to MC portal's I/O object |
| 847 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 848 | * @token: Token of DPRC object |
| 849 | * @obj_count: Number of objects assigned to the DPRC |
| 850 | * |
| 851 | * Return: '0' on Success; Error code otherwise. |
| 852 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 853 | int dprc_get_obj_count(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 854 | u32 cmd_flags, |
| 855 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 856 | int *obj_count) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 857 | { |
| 858 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 859 | struct dprc_rsp_get_obj_count *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 860 | int err; |
| 861 | |
| 862 | /* prepare command */ |
| 863 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 864 | cmd_flags, token); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 865 | |
| 866 | /* send command to mc*/ |
| 867 | err = mc_send_command(mc_io, &cmd); |
| 868 | if (err) |
| 869 | return err; |
| 870 | |
| 871 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 872 | rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params; |
| 873 | *obj_count = le32_to_cpu(rsp_params->obj_count); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | EXPORT_SYMBOL(dprc_get_obj_count); |
| 878 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 879 | /** |
| 880 | * dprc_get_obj() - Get general information on an object |
| 881 | * @mc_io: Pointer to MC portal's I/O object |
| 882 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 883 | * @token: Token of DPRC object |
| 884 | * @obj_index: Index of the object to be queried (< obj_count) |
| 885 | * @obj_desc: Returns the requested object descriptor |
| 886 | * |
| 887 | * The object descriptors are retrieved one by one by incrementing |
| 888 | * obj_index up to (not including) the value of obj_count returned |
| 889 | * from dprc_get_obj_count(). dprc_get_obj_count() must |
| 890 | * be called prior to dprc_get_obj(). |
| 891 | * |
| 892 | * Return: '0' on Success; Error code otherwise. |
| 893 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 894 | int dprc_get_obj(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 895 | u32 cmd_flags, |
| 896 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 897 | int obj_index, |
| 898 | struct dprc_obj_desc *obj_desc) |
| 899 | { |
| 900 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 901 | struct dprc_cmd_get_obj *cmd_params; |
| 902 | struct dprc_rsp_get_obj *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 903 | int err; |
| 904 | |
| 905 | /* prepare command */ |
| 906 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 907 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 908 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 909 | cmd_params = (struct dprc_cmd_get_obj *)cmd.params; |
| 910 | cmd_params->obj_index = cpu_to_le32(obj_index); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 911 | |
| 912 | /* send command to mc*/ |
| 913 | err = mc_send_command(mc_io, &cmd); |
| 914 | if (err) |
| 915 | return err; |
| 916 | |
| 917 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 918 | rsp_params = (struct dprc_rsp_get_obj *)cmd.params; |
| 919 | obj_desc->id = le32_to_cpu(rsp_params->id); |
| 920 | obj_desc->vendor = le16_to_cpu(rsp_params->vendor); |
| 921 | obj_desc->irq_count = rsp_params->irq_count; |
| 922 | obj_desc->region_count = rsp_params->region_count; |
| 923 | obj_desc->state = le32_to_cpu(rsp_params->state); |
| 924 | obj_desc->ver_major = le16_to_cpu(rsp_params->version_major); |
| 925 | obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor); |
| 926 | obj_desc->flags = le16_to_cpu(rsp_params->flags); |
| 927 | strncpy(obj_desc->type, rsp_params->type, 16); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 928 | obj_desc->type[15] = '\0'; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 929 | strncpy(obj_desc->label, rsp_params->label, 16); |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 930 | obj_desc->label[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 931 | return 0; |
| 932 | } |
| 933 | EXPORT_SYMBOL(dprc_get_obj); |
| 934 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 935 | /** |
| 936 | * dprc_get_obj_desc() - Get object descriptor. |
| 937 | * |
| 938 | * @mc_io: Pointer to MC portal's I/O object |
| 939 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 940 | * @token: Token of DPRC object |
| 941 | * @obj_type: The type of the object to get its descriptor. |
| 942 | * @obj_id: The id of the object to get its descriptor |
| 943 | * @obj_desc: The returned descriptor to fill and return to the user |
| 944 | * |
| 945 | * Return: '0' on Success; Error code otherwise. |
| 946 | * |
| 947 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 948 | int dprc_get_obj_desc(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 949 | u32 cmd_flags, |
| 950 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 951 | char *obj_type, |
| 952 | int obj_id, |
| 953 | struct dprc_obj_desc *obj_desc) |
| 954 | { |
| 955 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 956 | struct dprc_cmd_get_obj_desc *cmd_params; |
| 957 | struct dprc_rsp_get_obj_desc *rsp_params; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 958 | int err; |
| 959 | |
| 960 | /* prepare command */ |
| 961 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC, |
| 962 | cmd_flags, |
| 963 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 964 | cmd_params = (struct dprc_cmd_get_obj_desc *)cmd.params; |
| 965 | cmd_params->obj_id = cpu_to_le32(obj_id); |
| 966 | strncpy(cmd_params->type, obj_type, 16); |
| 967 | cmd_params->type[15] = '\0'; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 968 | |
| 969 | /* send command to mc*/ |
| 970 | err = mc_send_command(mc_io, &cmd); |
| 971 | if (err) |
| 972 | return err; |
| 973 | |
| 974 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 975 | rsp_params = (struct dprc_rsp_get_obj_desc *)cmd.params; |
| 976 | obj_desc->id = le32_to_cpu(rsp_params->id); |
| 977 | obj_desc->vendor = le16_to_cpu(rsp_params->vendor); |
| 978 | obj_desc->irq_count = rsp_params->irq_count; |
| 979 | obj_desc->region_count = rsp_params->region_count; |
| 980 | obj_desc->state = le32_to_cpu(rsp_params->state); |
| 981 | obj_desc->ver_major = le16_to_cpu(rsp_params->version_major); |
| 982 | obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor); |
| 983 | obj_desc->flags = le16_to_cpu(rsp_params->flags); |
| 984 | strncpy(obj_desc->type, rsp_params->type, 16); |
| 985 | obj_desc->type[15] = '\0'; |
| 986 | strncpy(obj_desc->label, rsp_params->label, 16); |
| 987 | obj_desc->label[15] = '\0'; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 988 | |
| 989 | return 0; |
| 990 | } |
| 991 | EXPORT_SYMBOL(dprc_get_obj_desc); |
| 992 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 993 | /** |
| 994 | * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt. |
| 995 | * @mc_io: Pointer to MC portal's I/O object |
| 996 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 997 | * @token: Token of DPRC object |
| 998 | * @obj_type: Type of the object to set its IRQ |
| 999 | * @obj_id: ID of the object to set its IRQ |
| 1000 | * @irq_index: The interrupt index to configure |
| 1001 | * @irq_cfg: IRQ configuration |
| 1002 | * |
| 1003 | * Return: '0' on Success; Error code otherwise. |
| 1004 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1005 | int dprc_set_obj_irq(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1006 | u32 cmd_flags, |
| 1007 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1008 | char *obj_type, |
| 1009 | int obj_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1010 | u8 irq_index, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1011 | struct dprc_irq_cfg *irq_cfg) |
| 1012 | { |
| 1013 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1014 | struct dprc_cmd_set_obj_irq *cmd_params; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1015 | |
| 1016 | /* prepare command */ |
| 1017 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ, |
| 1018 | cmd_flags, |
| 1019 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1020 | cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params; |
| 1021 | cmd_params->irq_val = cpu_to_le32(irq_cfg->val); |
| 1022 | cmd_params->irq_index = irq_index; |
| 1023 | cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr); |
| 1024 | cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num); |
| 1025 | cmd_params->obj_id = cpu_to_le32(obj_id); |
| 1026 | strncpy(cmd_params->obj_type, obj_type, 16); |
| 1027 | cmd_params->obj_type[15] = '\0'; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1028 | |
| 1029 | /* send command to mc*/ |
| 1030 | return mc_send_command(mc_io, &cmd); |
| 1031 | } |
| 1032 | EXPORT_SYMBOL(dprc_set_obj_irq); |
| 1033 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1034 | /** |
| 1035 | * dprc_get_obj_irq() - Get IRQ information from object. |
| 1036 | * @mc_io: Pointer to MC portal's I/O object |
| 1037 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1038 | * @token: Token of DPRC object |
| 1039 | * @obj_type: Type od the object to get its IRQ |
| 1040 | * @obj_id: ID of the object to get its IRQ |
| 1041 | * @irq_index: The interrupt index to configure |
| 1042 | * @type: Interrupt type: 0 represents message interrupt |
| 1043 | * type (both irq_addr and irq_val are valid) |
| 1044 | * @irq_cfg: The returned IRQ attributes |
| 1045 | * |
| 1046 | * Return: '0' on Success; Error code otherwise. |
| 1047 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1048 | int dprc_get_obj_irq(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1049 | u32 cmd_flags, |
| 1050 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1051 | char *obj_type, |
| 1052 | int obj_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1053 | u8 irq_index, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1054 | int *type, |
| 1055 | struct dprc_irq_cfg *irq_cfg) |
| 1056 | { |
| 1057 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1058 | struct dprc_cmd_get_obj_irq *cmd_params; |
| 1059 | struct dprc_rsp_get_obj_irq *rsp_params; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1060 | int err; |
| 1061 | |
| 1062 | /* prepare command */ |
| 1063 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ, |
| 1064 | cmd_flags, |
| 1065 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1066 | cmd_params = (struct dprc_cmd_get_obj_irq *)cmd.params; |
| 1067 | cmd_params->obj_id = cpu_to_le32(obj_id); |
| 1068 | cmd_params->irq_index = irq_index; |
| 1069 | strncpy(cmd_params->obj_type, obj_type, 16); |
| 1070 | cmd_params->obj_type[15] = '\0'; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1071 | |
| 1072 | /* send command to mc*/ |
| 1073 | err = mc_send_command(mc_io, &cmd); |
| 1074 | if (err) |
| 1075 | return err; |
| 1076 | |
| 1077 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1078 | rsp_params = (struct dprc_rsp_get_obj_irq *)cmd.params; |
| 1079 | irq_cfg->val = le32_to_cpu(rsp_params->irq_val); |
| 1080 | irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr); |
| 1081 | irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num); |
| 1082 | *type = le32_to_cpu(rsp_params->type); |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | EXPORT_SYMBOL(dprc_get_obj_irq); |
| 1087 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1088 | /** |
| 1089 | * dprc_get_res_count() - Obtains the number of free resources that are assigned |
| 1090 | * to this container, by pool type |
| 1091 | * @mc_io: Pointer to MC portal's I/O object |
| 1092 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1093 | * @token: Token of DPRC object |
| 1094 | * @type: pool type |
| 1095 | * @res_count: Returned number of free resources of the given |
| 1096 | * resource type that are assigned to this DPRC |
| 1097 | * |
| 1098 | * Return: '0' on Success; Error code otherwise. |
| 1099 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1100 | int dprc_get_res_count(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1101 | u32 cmd_flags, |
| 1102 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1103 | char *type, |
| 1104 | int *res_count) |
| 1105 | { |
| 1106 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1107 | struct dprc_cmd_get_res_count *cmd_params; |
| 1108 | struct dprc_rsp_get_res_count *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1109 | int err; |
| 1110 | |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1111 | /* prepare command */ |
| 1112 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1113 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1114 | cmd_params = (struct dprc_cmd_get_res_count *)cmd.params; |
| 1115 | strncpy(cmd_params->type, type, 16); |
| 1116 | cmd_params->type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1117 | |
| 1118 | /* send command to mc*/ |
| 1119 | err = mc_send_command(mc_io, &cmd); |
| 1120 | if (err) |
| 1121 | return err; |
| 1122 | |
| 1123 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1124 | rsp_params = (struct dprc_rsp_get_res_count *)cmd.params; |
| 1125 | *res_count = le32_to_cpu(rsp_params->res_count); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1126 | |
| 1127 | return 0; |
| 1128 | } |
| 1129 | EXPORT_SYMBOL(dprc_get_res_count); |
| 1130 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1131 | /** |
| 1132 | * dprc_get_res_ids() - Obtains IDs of free resources in the container |
| 1133 | * @mc_io: Pointer to MC portal's I/O object |
| 1134 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1135 | * @token: Token of DPRC object |
| 1136 | * @type: pool type |
| 1137 | * @range_desc: range descriptor |
| 1138 | * |
| 1139 | * Return: '0' on Success; Error code otherwise. |
| 1140 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1141 | int dprc_get_res_ids(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1142 | u32 cmd_flags, |
| 1143 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1144 | char *type, |
| 1145 | struct dprc_res_ids_range_desc *range_desc) |
| 1146 | { |
| 1147 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1148 | struct dprc_cmd_get_res_ids *cmd_params; |
| 1149 | struct dprc_rsp_get_res_ids *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1150 | int err; |
| 1151 | |
| 1152 | /* prepare command */ |
| 1153 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1154 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1155 | cmd_params = (struct dprc_cmd_get_res_ids *)cmd.params; |
| 1156 | cmd_params->iter_status = range_desc->iter_status; |
| 1157 | cmd_params->base_id = cpu_to_le32(range_desc->base_id); |
| 1158 | cmd_params->last_id = cpu_to_le32(range_desc->last_id); |
| 1159 | strncpy(cmd_params->type, type, 16); |
| 1160 | cmd_params->type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1161 | |
| 1162 | /* send command to mc*/ |
| 1163 | err = mc_send_command(mc_io, &cmd); |
| 1164 | if (err) |
| 1165 | return err; |
| 1166 | |
| 1167 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1168 | rsp_params = (struct dprc_rsp_get_res_ids *)cmd.params; |
| 1169 | range_desc->iter_status = rsp_params->iter_status; |
| 1170 | range_desc->base_id = le32_to_cpu(rsp_params->base_id); |
| 1171 | range_desc->last_id = le32_to_cpu(rsp_params->last_id); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | EXPORT_SYMBOL(dprc_get_res_ids); |
| 1176 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1177 | /** |
| 1178 | * dprc_get_obj_region() - Get region information for a specified object. |
| 1179 | * @mc_io: Pointer to MC portal's I/O object |
| 1180 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1181 | * @token: Token of DPRC object |
| 1182 | * @obj_type; Object type as returned in dprc_get_obj() |
| 1183 | * @obj_id: Unique object instance as returned in dprc_get_obj() |
| 1184 | * @region_index: The specific region to query |
| 1185 | * @region_desc: Returns the requested region descriptor |
| 1186 | * |
| 1187 | * Return: '0' on Success; Error code otherwise. |
| 1188 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1189 | int dprc_get_obj_region(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1190 | u32 cmd_flags, |
| 1191 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1192 | char *obj_type, |
| 1193 | int obj_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1194 | u8 region_index, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1195 | struct dprc_region_desc *region_desc) |
| 1196 | { |
| 1197 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1198 | struct dprc_cmd_get_obj_region *cmd_params; |
| 1199 | struct dprc_rsp_get_obj_region *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1200 | int err; |
| 1201 | |
| 1202 | /* prepare command */ |
| 1203 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1204 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1205 | cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params; |
| 1206 | cmd_params->obj_id = cpu_to_le32(obj_id); |
| 1207 | cmd_params->region_index = region_index; |
| 1208 | strncpy(cmd_params->obj_type, obj_type, 16); |
| 1209 | cmd_params->obj_type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1210 | |
| 1211 | /* send command to mc*/ |
| 1212 | err = mc_send_command(mc_io, &cmd); |
| 1213 | if (err) |
| 1214 | return err; |
| 1215 | |
| 1216 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1217 | rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params; |
| 1218 | region_desc->base_offset = le64_to_cpu(rsp_params->base_addr); |
| 1219 | region_desc->size = le32_to_cpu(rsp_params->size); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1220 | |
| 1221 | return 0; |
| 1222 | } |
| 1223 | EXPORT_SYMBOL(dprc_get_obj_region); |
| 1224 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1225 | /** |
| 1226 | * dprc_set_obj_label() - Set object label. |
| 1227 | * @mc_io: Pointer to MC portal's I/O object |
| 1228 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1229 | * @token: Token of DPRC object |
| 1230 | * @obj_type: Object's type |
| 1231 | * @obj_id: Object's ID |
| 1232 | * @label: The required label. The maximum length is 16 chars. |
| 1233 | * |
| 1234 | * Return: '0' on Success; Error code otherwise. |
| 1235 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1236 | int dprc_set_obj_label(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1237 | u32 cmd_flags, |
| 1238 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1239 | char *obj_type, |
| 1240 | int obj_id, |
| 1241 | char *label) |
| 1242 | { |
| 1243 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1244 | struct dprc_cmd_set_obj_label *cmd_params; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1245 | |
| 1246 | /* prepare command */ |
| 1247 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL, |
| 1248 | cmd_flags, |
| 1249 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1250 | cmd_params = (struct dprc_cmd_set_obj_label *)cmd.params; |
| 1251 | cmd_params->obj_id = cpu_to_le32(obj_id); |
| 1252 | strncpy(cmd_params->label, label, 16); |
| 1253 | cmd_params->label[15] = '\0'; |
| 1254 | strncpy(cmd_params->obj_type, obj_type, 16); |
| 1255 | cmd_params->obj_type[15] = '\0'; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1256 | |
| 1257 | /* send command to mc*/ |
| 1258 | return mc_send_command(mc_io, &cmd); |
| 1259 | } |
| 1260 | EXPORT_SYMBOL(dprc_set_obj_label); |
| 1261 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1262 | /** |
| 1263 | * dprc_connect() - Connect two endpoints to create a network link between them |
| 1264 | * @mc_io: Pointer to MC portal's I/O object |
| 1265 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1266 | * @token: Token of DPRC object |
| 1267 | * @endpoint1: Endpoint 1 configuration parameters |
| 1268 | * @endpoint2: Endpoint 2 configuration parameters |
| 1269 | * @cfg: Connection configuration. The connection configuration is ignored for |
Stuart Yoder | ac06199 | 2016-04-11 11:48:59 -0500 | [diff] [blame] | 1270 | * connections made to DPMAC objects, where rate is retrieved from the |
| 1271 | * MAC configuration. |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1272 | * |
| 1273 | * Return: '0' on Success; Error code otherwise. |
| 1274 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1275 | int dprc_connect(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1276 | u32 cmd_flags, |
| 1277 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1278 | const struct dprc_endpoint *endpoint1, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1279 | const struct dprc_endpoint *endpoint2, |
| 1280 | const struct dprc_connection_cfg *cfg) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1281 | { |
| 1282 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1283 | struct dprc_cmd_connect *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1284 | |
| 1285 | /* prepare command */ |
| 1286 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1287 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1288 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1289 | cmd_params = (struct dprc_cmd_connect *)cmd.params; |
| 1290 | cmd_params->ep1_id = cpu_to_le32(endpoint1->id); |
| 1291 | cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id); |
| 1292 | cmd_params->ep2_id = cpu_to_le32(endpoint2->id); |
| 1293 | cmd_params->ep2_interface_id = cpu_to_le32(endpoint2->if_id); |
| 1294 | strncpy(cmd_params->ep1_type, endpoint1->type, 16); |
| 1295 | cmd_params->ep1_type[15] = '\0'; |
| 1296 | cmd_params->max_rate = cpu_to_le32(cfg->max_rate); |
| 1297 | cmd_params->committed_rate = cpu_to_le32(cfg->committed_rate); |
| 1298 | strncpy(cmd_params->ep2_type, endpoint2->type, 16); |
| 1299 | cmd_params->ep2_type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1300 | |
| 1301 | /* send command to mc*/ |
| 1302 | return mc_send_command(mc_io, &cmd); |
| 1303 | } |
| 1304 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1305 | /** |
| 1306 | * dprc_disconnect() - Disconnect one endpoint to remove its network connection |
| 1307 | * @mc_io: Pointer to MC portal's I/O object |
| 1308 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1309 | * @token: Token of DPRC object |
| 1310 | * @endpoint: Endpoint configuration parameters |
| 1311 | * |
| 1312 | * Return: '0' on Success; Error code otherwise. |
| 1313 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1314 | int dprc_disconnect(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1315 | u32 cmd_flags, |
| 1316 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1317 | const struct dprc_endpoint *endpoint) |
| 1318 | { |
| 1319 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1320 | struct dprc_cmd_disconnect *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1321 | |
| 1322 | /* prepare command */ |
| 1323 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1324 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1325 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1326 | cmd_params = (struct dprc_cmd_disconnect *)cmd.params; |
| 1327 | cmd_params->id = cpu_to_le32(endpoint->id); |
| 1328 | cmd_params->interface_id = cpu_to_le32(endpoint->if_id); |
| 1329 | strncpy(cmd_params->type, endpoint->type, 16); |
| 1330 | cmd_params->type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1331 | |
| 1332 | /* send command to mc*/ |
| 1333 | return mc_send_command(mc_io, &cmd); |
| 1334 | } |
| 1335 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1336 | /** |
| 1337 | * dprc_get_connection() - Get connected endpoint and link status if connection |
| 1338 | * exists. |
| 1339 | * @mc_io: Pointer to MC portal's I/O object |
| 1340 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 1341 | * @token: Token of DPRC object |
| 1342 | * @endpoint1: Endpoint 1 configuration parameters |
| 1343 | * @endpoint2: Returned endpoint 2 configuration parameters |
Stuart Yoder | ac06199 | 2016-04-11 11:48:59 -0500 | [diff] [blame] | 1344 | * @state: Returned link state: |
| 1345 | * 1 - link is up; |
| 1346 | * 0 - link is down; |
| 1347 | * -1 - no connection (endpoint2 information is irrelevant) |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 1348 | * |
| 1349 | * Return: '0' on Success; -ENAVAIL if connection does not exist. |
| 1350 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1351 | int dprc_get_connection(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 1352 | u32 cmd_flags, |
| 1353 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1354 | const struct dprc_endpoint *endpoint1, |
| 1355 | struct dprc_endpoint *endpoint2, |
| 1356 | int *state) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1357 | { |
| 1358 | struct mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1359 | struct dprc_cmd_get_connection *cmd_params; |
| 1360 | struct dprc_rsp_get_connection *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1361 | int err; |
| 1362 | |
| 1363 | /* prepare command */ |
| 1364 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 1365 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1366 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1367 | cmd_params = (struct dprc_cmd_get_connection *)cmd.params; |
| 1368 | cmd_params->ep1_id = cpu_to_le32(endpoint1->id); |
| 1369 | cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id); |
| 1370 | strncpy(cmd_params->ep1_type, endpoint1->type, 16); |
| 1371 | cmd_params->ep1_type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1372 | |
| 1373 | /* send command to mc*/ |
| 1374 | err = mc_send_command(mc_io, &cmd); |
| 1375 | if (err) |
| 1376 | return err; |
| 1377 | |
| 1378 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame^] | 1379 | rsp_params = (struct dprc_rsp_get_connection *)cmd.params; |
| 1380 | endpoint2->id = le32_to_cpu(rsp_params->ep2_id); |
| 1381 | endpoint2->if_id = le32_to_cpu(rsp_params->ep2_interface_id); |
| 1382 | strncpy(endpoint2->type, rsp_params->ep2_type, 16); |
| 1383 | endpoint2->type[15] = '\0'; |
| 1384 | *state = le32_to_cpu(rsp_params->state); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 1385 | |
| 1386 | return 0; |
| 1387 | } |