blob: c260549813335888c5f8005c5c3d5d3a6cc0ca0c [file] [log] [blame]
Ioana Radulescu9989b592016-06-22 16:40:52 -05001/* Copyright 2013-2016 Freescale Semiconductor Inc.
J. German Rivera31c88962015-03-05 19:29:09 -06002*
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 Riverae9bf3f22015-09-24 14:26:54 -050037/**
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 Rivera1ee695f2015-09-23 16:11:03 -050048int dprc_open(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -050049 u32 cmd_flags,
J. German Rivera1ee695f2015-09-23 16:11:03 -050050 int container_id,
J. German Riveraba72f252015-09-25 11:21:01 -050051 u16 *token)
J. German Rivera31c88962015-03-05 19:29:09 -060052{
53 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -050054 struct dprc_cmd_open *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -060055 int err;
56
57 /* prepare command */
J. German Rivera1ee695f2015-09-23 16:11:03 -050058 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -060059 0);
Ioana Radulescu9989b592016-06-22 16:40:52 -050060 cmd_params = (struct dprc_cmd_open *)cmd.params;
61 cmd_params->container_id = cpu_to_le32(container_id);
J. German Rivera31c88962015-03-05 19:29:09 -060062
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 Radulescu9989b592016-06-22 16:40:52 -050069 *token = mc_cmd_hdr_read_token(&cmd);
J. German Rivera31c88962015-03-05 19:29:09 -060070
71 return 0;
72}
73EXPORT_SYMBOL(dprc_open);
74
J. German Riverae9bf3f22015-09-24 14:26:54 -050075/**
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 Rivera1ee695f2015-09-23 16:11:03 -050086int dprc_close(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -050087 u32 cmd_flags,
88 u16 token)
J. German Rivera31c88962015-03-05 19:29:09 -060089{
90 struct mc_command cmd = { 0 };
91
92 /* prepare command */
J. German Rivera1ee695f2015-09-23 16:11:03 -050093 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -060094 token);
95
96 /* send command to mc*/
97 return mc_send_command(mc_io, &cmd);
98}
99EXPORT_SYMBOL(dprc_close);
100
J. German Riverae9bf3f22015-09-24 14:26:54 -0500101/**
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 Rivera31c88962015-03-05 19:29:09 -0600112int dprc_create_container(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500113 u32 cmd_flags,
114 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600115 struct dprc_cfg *cfg,
116 int *child_container_id,
J. German Riveraba72f252015-09-25 11:21:01 -0500117 u64 *child_portal_offset)
J. German Rivera31c88962015-03-05 19:29:09 -0600118{
119 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500120 struct dprc_cmd_create_container *cmd_params;
121 struct dprc_rsp_create_container *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600122 int err;
123
124 /* prepare command */
Ioana Radulescu9989b592016-06-22 16:40:52 -0500125 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 Rivera31c88962015-03-05 19:29:09 -0600131
132 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500133 cmd_flags, token);
J. German Rivera31c88962015-03-05 19:29:09 -0600134
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 Radulescu9989b592016-06-22 16:40:52 -0500141 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 Rivera31c88962015-03-05 19:29:09 -0600144
145 return 0;
146}
147
J. German Riverae9bf3f22015-09-24 14:26:54 -0500148/**
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 Rivera31c88962015-03-05 19:29:09 -0600170int dprc_destroy_container(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500171 u32 cmd_flags,
172 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600173 int child_container_id)
174{
175 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500176 struct dprc_cmd_destroy_container *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600177
178 /* prepare command */
179 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500180 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500181 cmd_params = (struct dprc_cmd_destroy_container *)cmd.params;
182 cmd_params->child_container_id = cpu_to_le32(child_container_id);
J. German Rivera31c88962015-03-05 19:29:09 -0600183
184 /* send command to mc*/
185 return mc_send_command(mc_io, &cmd);
186}
187
J. German Riverae9bf3f22015-09-24 14:26:54 -0500188/**
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 Rivera31c88962015-03-05 19:29:09 -0600210int dprc_reset_container(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500211 u32 cmd_flags,
212 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600213 int child_container_id)
214{
215 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500216 struct dprc_cmd_reset_container *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600217
218 /* prepare command */
219 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500220 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500221 cmd_params = (struct dprc_cmd_reset_container *)cmd.params;
222 cmd_params->child_container_id = cpu_to_le32(child_container_id);
J. German Rivera31c88962015-03-05 19:29:09 -0600223
224 /* send command to mc*/
225 return mc_send_command(mc_io, &cmd);
226}
227
J. German Riverae9bf3f22015-09-24 14:26:54 -0500228/**
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 Rivera31c88962015-03-05 19:29:09 -0600240int dprc_get_irq(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500241 u32 cmd_flags,
242 u16 token,
243 u8 irq_index,
J. German Rivera31c88962015-03-05 19:29:09 -0600244 int *type,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500245 struct dprc_irq_cfg *irq_cfg)
J. German Rivera31c88962015-03-05 19:29:09 -0600246{
247 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500248 struct dprc_cmd_get_irq *cmd_params;
249 struct dprc_rsp_get_irq *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600250 int err;
251
252 /* prepare command */
253 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500254 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -0600255 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500256 cmd_params = (struct dprc_cmd_get_irq *)cmd.params;
257 cmd_params->irq_index = irq_index;
J. German Rivera31c88962015-03-05 19:29:09 -0600258
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 Radulescu9989b592016-06-22 16:40:52 -0500265 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 Rivera31c88962015-03-05 19:29:09 -0600270
271 return 0;
272}
273
J. German Riverae9bf3f22015-09-24 14:26:54 -0500274/**
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 Rivera31c88962015-03-05 19:29:09 -0600284int dprc_set_irq(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500285 u32 cmd_flags,
286 u16 token,
287 u8 irq_index,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500288 struct dprc_irq_cfg *irq_cfg)
J. German Rivera31c88962015-03-05 19:29:09 -0600289{
290 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500291 struct dprc_cmd_set_irq *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600292
293 /* prepare command */
294 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500295 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -0600296 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500297 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 Rivera31c88962015-03-05 19:29:09 -0600302
303 /* send command to mc*/
304 return mc_send_command(mc_io, &cmd);
305}
306
J. German Riverae9bf3f22015-09-24 14:26:54 -0500307/**
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 Rivera31c88962015-03-05 19:29:09 -0600317int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500318 u32 cmd_flags,
319 u16 token,
320 u8 irq_index,
321 u8 *en)
J. German Rivera31c88962015-03-05 19:29:09 -0600322{
323 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500324 struct dprc_cmd_get_irq_enable *cmd_params;
325 struct dprc_rsp_get_irq_enable *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600326 int err;
327
328 /* prepare command */
329 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500330 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500331 cmd_params = (struct dprc_cmd_get_irq_enable *)cmd.params;
332 cmd_params->irq_index = irq_index;
J. German Rivera31c88962015-03-05 19:29:09 -0600333
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 Radulescu9989b592016-06-22 16:40:52 -0500340 rsp_params = (struct dprc_rsp_get_irq_enable *)cmd.params;
341 *en = rsp_params->enabled & DPRC_ENABLE;
J. German Rivera31c88962015-03-05 19:29:09 -0600342
343 return 0;
344}
345
J. German Riverae9bf3f22015-09-24 14:26:54 -0500346/**
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 Rivera31c88962015-03-05 19:29:09 -0600361int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500362 u32 cmd_flags,
363 u16 token,
364 u8 irq_index,
365 u8 en)
J. German Rivera31c88962015-03-05 19:29:09 -0600366{
367 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500368 struct dprc_cmd_set_irq_enable *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600369
370 /* prepare command */
371 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500372 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500373 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 Rivera31c88962015-03-05 19:29:09 -0600376
377 /* send command to mc*/
378 return mc_send_command(mc_io, &cmd);
379}
380
J. German Riverae9bf3f22015-09-24 14:26:54 -0500381/**
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 Rivera31c88962015-03-05 19:29:09 -0600394int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500395 u32 cmd_flags,
396 u16 token,
397 u8 irq_index,
398 u32 *mask)
J. German Rivera31c88962015-03-05 19:29:09 -0600399{
400 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500401 struct dprc_cmd_get_irq_mask *cmd_params;
402 struct dprc_rsp_get_irq_mask *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600403 int err;
404
405 /* prepare command */
406 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500407 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500408 cmd_params = (struct dprc_cmd_get_irq_mask *)cmd.params;
409 cmd_params->irq_index = irq_index;
J. German Rivera31c88962015-03-05 19:29:09 -0600410
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 Radulescu9989b592016-06-22 16:40:52 -0500417 rsp_params = (struct dprc_rsp_get_irq_mask *)cmd.params;
418 *mask = le32_to_cpu(rsp_params->mask);
J. German Rivera31c88962015-03-05 19:29:09 -0600419
420 return 0;
421}
422
J. German Riverae9bf3f22015-09-24 14:26:54 -0500423/**
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 Rivera31c88962015-03-05 19:29:09 -0600439int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500440 u32 cmd_flags,
441 u16 token,
442 u8 irq_index,
443 u32 mask)
J. German Rivera31c88962015-03-05 19:29:09 -0600444{
445 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500446 struct dprc_cmd_set_irq_mask *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600447
448 /* prepare command */
449 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500450 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500451 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 Rivera31c88962015-03-05 19:29:09 -0600454
455 /* send command to mc*/
456 return mc_send_command(mc_io, &cmd);
457}
458
J. German Riverae9bf3f22015-09-24 14:26:54 -0500459/**
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 Rivera31c88962015-03-05 19:29:09 -0600471int dprc_get_irq_status(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500472 u32 cmd_flags,
473 u16 token,
474 u8 irq_index,
475 u32 *status)
J. German Rivera31c88962015-03-05 19:29:09 -0600476{
477 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500478 struct dprc_cmd_get_irq_status *cmd_params;
479 struct dprc_rsp_get_irq_status *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600480 int err;
481
482 /* prepare command */
483 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500484 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500485 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 Rivera31c88962015-03-05 19:29:09 -0600488
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 Radulescu9989b592016-06-22 16:40:52 -0500495 rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
496 *status = le32_to_cpu(rsp_params->status);
J. German Rivera31c88962015-03-05 19:29:09 -0600497
498 return 0;
499}
500
J. German Riverae9bf3f22015-09-24 14:26:54 -0500501/**
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 Rivera31c88962015-03-05 19:29:09 -0600513int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500514 u32 cmd_flags,
515 u16 token,
516 u8 irq_index,
517 u32 status)
J. German Rivera31c88962015-03-05 19:29:09 -0600518{
519 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500520 struct dprc_cmd_clear_irq_status *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600521
522 /* prepare command */
523 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500524 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500525 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 Rivera31c88962015-03-05 19:29:09 -0600528
529 /* send command to mc*/
530 return mc_send_command(mc_io, &cmd);
531}
532
J. German Riverae9bf3f22015-09-24 14:26:54 -0500533/**
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 Rivera31c88962015-03-05 19:29:09 -0600542int dprc_get_attributes(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500543 u32 cmd_flags,
544 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600545 struct dprc_attributes *attr)
546{
547 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500548 struct dprc_rsp_get_attributes *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600549 int err;
550
551 /* prepare command */
552 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500553 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -0600554 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 Radulescu9989b592016-06-22 16:40:52 -0500562 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 Rivera31c88962015-03-05 19:29:09 -0600569
570 return 0;
571}
572
J. German Riverae9bf3f22015-09-24 14:26:54 -0500573/**
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 Rivera31c88962015-03-05 19:29:09 -0600598int dprc_set_res_quota(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500599 u32 cmd_flags,
600 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600601 int child_container_id,
602 char *type,
J. German Riveraba72f252015-09-25 11:21:01 -0500603 u16 quota)
J. German Rivera31c88962015-03-05 19:29:09 -0600604{
605 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500606 struct dprc_cmd_set_res_quota *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600607
608 /* prepare command */
609 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500610 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500611 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 Rivera31c88962015-03-05 19:29:09 -0600616
617 /* send command to mc*/
618 return mc_send_command(mc_io, &cmd);
619}
620
J. German Riverae9bf3f22015-09-24 14:26:54 -0500621/**
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 Rivera31c88962015-03-05 19:29:09 -0600636int dprc_get_res_quota(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500637 u32 cmd_flags,
638 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600639 int child_container_id,
640 char *type,
J. German Riveraba72f252015-09-25 11:21:01 -0500641 u16 *quota)
J. German Rivera31c88962015-03-05 19:29:09 -0600642{
643 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500644 struct dprc_cmd_get_res_quota *cmd_params;
645 struct dprc_rsp_get_res_quota *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600646 int err;
647
648 /* prepare command */
649 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500650 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500651 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 Rivera31c88962015-03-05 19:29:09 -0600655
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 Radulescu9989b592016-06-22 16:40:52 -0500662 rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params;
663 *quota = le16_to_cpu(rsp_params->quota);
J. German Rivera31c88962015-03-05 19:29:09 -0600664
665 return 0;
666}
667
J. German Riverae9bf3f22015-09-24 14:26:54 -0500668/**
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 Rivera31c88962015-03-05 19:29:09 -0600700int dprc_assign(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500701 u32 cmd_flags,
702 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600703 int container_id,
704 struct dprc_res_req *res_req)
705{
706 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500707 struct dprc_cmd_assign *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600708
709 /* prepare command */
710 cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500711 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500712 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 Rivera31c88962015-03-05 19:29:09 -0600719
720 /* send command to mc*/
721 return mc_send_command(mc_io, &cmd);
722}
723
J. German Riverae9bf3f22015-09-24 14:26:54 -0500724/**
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 Rivera31c88962015-03-05 19:29:09 -0600739int dprc_unassign(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500740 u32 cmd_flags,
741 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600742 int child_container_id,
743 struct dprc_res_req *res_req)
744{
745 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500746 struct dprc_cmd_unassign *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600747
748 /* prepare command */
749 cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500750 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -0600751 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500752 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 Rivera31c88962015-03-05 19:29:09 -0600759
760 /* send command to mc*/
761 return mc_send_command(mc_io, &cmd);
762}
763
J. German Riverae9bf3f22015-09-24 14:26:54 -0500764/**
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 Rivera31c88962015-03-05 19:29:09 -0600773int dprc_get_pool_count(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500774 u32 cmd_flags,
775 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600776 int *pool_count)
777{
778 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500779 struct dprc_rsp_get_pool_count *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600780 int err;
781
782 /* prepare command */
783 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500784 cmd_flags, token);
J. German Rivera31c88962015-03-05 19:29:09 -0600785
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 Radulescu9989b592016-06-22 16:40:52 -0500792 rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params;
793 *pool_count = le32_to_cpu(rsp_params->pool_count);
J. German Rivera31c88962015-03-05 19:29:09 -0600794
795 return 0;
796}
797
J. German Riverae9bf3f22015-09-24 14:26:54 -0500798/**
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 Rivera31c88962015-03-05 19:29:09 -0600813int dprc_get_pool(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500814 u32 cmd_flags,
815 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600816 int pool_index,
817 char *type)
818{
819 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500820 struct dprc_cmd_get_pool *cmd_params;
821 struct dprc_rsp_get_pool *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600822 int err;
823
824 /* prepare command */
825 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500826 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -0600827 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500828 cmd_params = (struct dprc_cmd_get_pool *)cmd.params;
829 cmd_params->pool_index = cpu_to_le32(pool_index);
J. German Rivera31c88962015-03-05 19:29:09 -0600830
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 Radulescu9989b592016-06-22 16:40:52 -0500837 rsp_params = (struct dprc_rsp_get_pool *)cmd.params;
838 strncpy(type, rsp_params->type, 16);
J. German Rivera31c88962015-03-05 19:29:09 -0600839 type[15] = '\0';
840
841 return 0;
842}
843
J. German Riverae9bf3f22015-09-24 14:26:54 -0500844/**
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 Rivera1ee695f2015-09-23 16:11:03 -0500853int dprc_get_obj_count(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500854 u32 cmd_flags,
855 u16 token,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500856 int *obj_count)
J. German Rivera31c88962015-03-05 19:29:09 -0600857{
858 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500859 struct dprc_rsp_get_obj_count *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600860 int err;
861
862 /* prepare command */
863 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500864 cmd_flags, token);
J. German Rivera31c88962015-03-05 19:29:09 -0600865
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 Radulescu9989b592016-06-22 16:40:52 -0500872 rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
873 *obj_count = le32_to_cpu(rsp_params->obj_count);
J. German Rivera31c88962015-03-05 19:29:09 -0600874
875 return 0;
876}
877EXPORT_SYMBOL(dprc_get_obj_count);
878
J. German Riverae9bf3f22015-09-24 14:26:54 -0500879/**
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 Rivera31c88962015-03-05 19:29:09 -0600894int dprc_get_obj(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500895 u32 cmd_flags,
896 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -0600897 int obj_index,
898 struct dprc_obj_desc *obj_desc)
899{
900 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500901 struct dprc_cmd_get_obj *cmd_params;
902 struct dprc_rsp_get_obj *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -0600903 int err;
904
905 /* prepare command */
906 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500907 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -0600908 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500909 cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
910 cmd_params->obj_index = cpu_to_le32(obj_index);
J. German Rivera31c88962015-03-05 19:29:09 -0600911
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 Radulescu9989b592016-06-22 16:40:52 -0500918 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 Rivera31c88962015-03-05 19:29:09 -0600928 obj_desc->type[15] = '\0';
Ioana Radulescu9989b592016-06-22 16:40:52 -0500929 strncpy(obj_desc->label, rsp_params->label, 16);
J. German Rivera1ee695f2015-09-23 16:11:03 -0500930 obj_desc->label[15] = '\0';
J. German Rivera31c88962015-03-05 19:29:09 -0600931 return 0;
932}
933EXPORT_SYMBOL(dprc_get_obj);
934
J. German Riverae9bf3f22015-09-24 14:26:54 -0500935/**
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 Rivera1ee695f2015-09-23 16:11:03 -0500948int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -0500949 u32 cmd_flags,
950 u16 token,
J. German Rivera1ee695f2015-09-23 16:11:03 -0500951 char *obj_type,
952 int obj_id,
953 struct dprc_obj_desc *obj_desc)
954{
955 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -0500956 struct dprc_cmd_get_obj_desc *cmd_params;
957 struct dprc_rsp_get_obj_desc *rsp_params;
J. German Rivera1ee695f2015-09-23 16:11:03 -0500958 int err;
959
960 /* prepare command */
961 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
962 cmd_flags,
963 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -0500964 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 Rivera1ee695f2015-09-23 16:11:03 -0500968
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 Radulescu9989b592016-06-22 16:40:52 -0500975 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 Rivera1ee695f2015-09-23 16:11:03 -0500988
989 return 0;
990}
991EXPORT_SYMBOL(dprc_get_obj_desc);
992
J. German Riverae9bf3f22015-09-24 14:26:54 -0500993/**
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 Rivera1ee695f2015-09-23 16:11:03 -05001005int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001006 u32 cmd_flags,
1007 u16 token,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001008 char *obj_type,
1009 int obj_id,
J. German Riveraba72f252015-09-25 11:21:01 -05001010 u8 irq_index,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001011 struct dprc_irq_cfg *irq_cfg)
1012{
1013 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001014 struct dprc_cmd_set_obj_irq *cmd_params;
J. German Rivera1ee695f2015-09-23 16:11:03 -05001015
1016 /* prepare command */
1017 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
1018 cmd_flags,
1019 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001020 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 Rivera1ee695f2015-09-23 16:11:03 -05001028
1029 /* send command to mc*/
1030 return mc_send_command(mc_io, &cmd);
1031}
1032EXPORT_SYMBOL(dprc_set_obj_irq);
1033
J. German Riverae9bf3f22015-09-24 14:26:54 -05001034/**
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 Rivera1ee695f2015-09-23 16:11:03 -05001048int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001049 u32 cmd_flags,
1050 u16 token,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001051 char *obj_type,
1052 int obj_id,
J. German Riveraba72f252015-09-25 11:21:01 -05001053 u8 irq_index,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001054 int *type,
1055 struct dprc_irq_cfg *irq_cfg)
1056{
1057 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001058 struct dprc_cmd_get_obj_irq *cmd_params;
1059 struct dprc_rsp_get_obj_irq *rsp_params;
J. German Rivera1ee695f2015-09-23 16:11:03 -05001060 int err;
1061
1062 /* prepare command */
1063 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
1064 cmd_flags,
1065 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001066 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 Rivera1ee695f2015-09-23 16:11:03 -05001071
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 Radulescu9989b592016-06-22 16:40:52 -05001078 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 Rivera1ee695f2015-09-23 16:11:03 -05001083
1084 return 0;
1085}
1086EXPORT_SYMBOL(dprc_get_obj_irq);
1087
J. German Riverae9bf3f22015-09-24 14:26:54 -05001088/**
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 Rivera31c88962015-03-05 19:29:09 -06001100int dprc_get_res_count(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001101 u32 cmd_flags,
1102 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -06001103 char *type,
1104 int *res_count)
1105{
1106 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001107 struct dprc_cmd_get_res_count *cmd_params;
1108 struct dprc_rsp_get_res_count *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -06001109 int err;
1110
J. German Rivera31c88962015-03-05 19:29:09 -06001111 /* prepare command */
1112 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001113 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001114 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 Rivera31c88962015-03-05 19:29:09 -06001117
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 Radulescu9989b592016-06-22 16:40:52 -05001124 rsp_params = (struct dprc_rsp_get_res_count *)cmd.params;
1125 *res_count = le32_to_cpu(rsp_params->res_count);
J. German Rivera31c88962015-03-05 19:29:09 -06001126
1127 return 0;
1128}
1129EXPORT_SYMBOL(dprc_get_res_count);
1130
J. German Riverae9bf3f22015-09-24 14:26:54 -05001131/**
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 Rivera31c88962015-03-05 19:29:09 -06001141int dprc_get_res_ids(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001142 u32 cmd_flags,
1143 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -06001144 char *type,
1145 struct dprc_res_ids_range_desc *range_desc)
1146{
1147 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001148 struct dprc_cmd_get_res_ids *cmd_params;
1149 struct dprc_rsp_get_res_ids *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -06001150 int err;
1151
1152 /* prepare command */
1153 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001154 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001155 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 Rivera31c88962015-03-05 19:29:09 -06001161
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 Radulescu9989b592016-06-22 16:40:52 -05001168 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 Rivera31c88962015-03-05 19:29:09 -06001172
1173 return 0;
1174}
1175EXPORT_SYMBOL(dprc_get_res_ids);
1176
J. German Riverae9bf3f22015-09-24 14:26:54 -05001177/**
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 Rivera31c88962015-03-05 19:29:09 -06001189int dprc_get_obj_region(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001190 u32 cmd_flags,
1191 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -06001192 char *obj_type,
1193 int obj_id,
J. German Riveraba72f252015-09-25 11:21:01 -05001194 u8 region_index,
J. German Rivera31c88962015-03-05 19:29:09 -06001195 struct dprc_region_desc *region_desc)
1196{
1197 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001198 struct dprc_cmd_get_obj_region *cmd_params;
1199 struct dprc_rsp_get_obj_region *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -06001200 int err;
1201
1202 /* prepare command */
1203 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001204 cmd_flags, token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001205 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 Rivera31c88962015-03-05 19:29:09 -06001210
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 Radulescu9989b592016-06-22 16:40:52 -05001217 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 Rivera31c88962015-03-05 19:29:09 -06001220
1221 return 0;
1222}
1223EXPORT_SYMBOL(dprc_get_obj_region);
1224
J. German Riverae9bf3f22015-09-24 14:26:54 -05001225/**
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 Rivera1ee695f2015-09-23 16:11:03 -05001236int dprc_set_obj_label(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001237 u32 cmd_flags,
1238 u16 token,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001239 char *obj_type,
1240 int obj_id,
1241 char *label)
1242{
1243 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001244 struct dprc_cmd_set_obj_label *cmd_params;
J. German Rivera1ee695f2015-09-23 16:11:03 -05001245
1246 /* prepare command */
1247 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
1248 cmd_flags,
1249 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001250 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 Rivera1ee695f2015-09-23 16:11:03 -05001256
1257 /* send command to mc*/
1258 return mc_send_command(mc_io, &cmd);
1259}
1260EXPORT_SYMBOL(dprc_set_obj_label);
1261
J. German Riverae9bf3f22015-09-24 14:26:54 -05001262/**
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 Yoderac061992016-04-11 11:48:59 -05001270 * connections made to DPMAC objects, where rate is retrieved from the
1271 * MAC configuration.
J. German Riverae9bf3f22015-09-24 14:26:54 -05001272 *
1273 * Return: '0' on Success; Error code otherwise.
1274 */
J. German Rivera31c88962015-03-05 19:29:09 -06001275int dprc_connect(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001276 u32 cmd_flags,
1277 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -06001278 const struct dprc_endpoint *endpoint1,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001279 const struct dprc_endpoint *endpoint2,
1280 const struct dprc_connection_cfg *cfg)
J. German Rivera31c88962015-03-05 19:29:09 -06001281{
1282 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001283 struct dprc_cmd_connect *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -06001284
1285 /* prepare command */
1286 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001287 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -06001288 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001289 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 Rivera31c88962015-03-05 19:29:09 -06001300
1301 /* send command to mc*/
1302 return mc_send_command(mc_io, &cmd);
1303}
1304
J. German Riverae9bf3f22015-09-24 14:26:54 -05001305/**
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 Rivera31c88962015-03-05 19:29:09 -06001314int dprc_disconnect(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001315 u32 cmd_flags,
1316 u16 token,
J. German Rivera31c88962015-03-05 19:29:09 -06001317 const struct dprc_endpoint *endpoint)
1318{
1319 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001320 struct dprc_cmd_disconnect *cmd_params;
J. German Rivera31c88962015-03-05 19:29:09 -06001321
1322 /* prepare command */
1323 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001324 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -06001325 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001326 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 Rivera31c88962015-03-05 19:29:09 -06001331
1332 /* send command to mc*/
1333 return mc_send_command(mc_io, &cmd);
1334}
1335
J. German Riverae9bf3f22015-09-24 14:26:54 -05001336/**
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 Yoderac061992016-04-11 11:48:59 -05001344* @state: Returned link state:
1345* 1 - link is up;
1346* 0 - link is down;
1347* -1 - no connection (endpoint2 information is irrelevant)
J. German Riverae9bf3f22015-09-24 14:26:54 -05001348*
1349* Return: '0' on Success; -ENAVAIL if connection does not exist.
1350*/
J. German Rivera31c88962015-03-05 19:29:09 -06001351int dprc_get_connection(struct fsl_mc_io *mc_io,
J. German Riveraba72f252015-09-25 11:21:01 -05001352 u32 cmd_flags,
1353 u16 token,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001354 const struct dprc_endpoint *endpoint1,
1355 struct dprc_endpoint *endpoint2,
1356 int *state)
J. German Rivera31c88962015-03-05 19:29:09 -06001357{
1358 struct mc_command cmd = { 0 };
Ioana Radulescu9989b592016-06-22 16:40:52 -05001359 struct dprc_cmd_get_connection *cmd_params;
1360 struct dprc_rsp_get_connection *rsp_params;
J. German Rivera31c88962015-03-05 19:29:09 -06001361 int err;
1362
1363 /* prepare command */
1364 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
J. German Rivera1ee695f2015-09-23 16:11:03 -05001365 cmd_flags,
J. German Rivera31c88962015-03-05 19:29:09 -06001366 token);
Ioana Radulescu9989b592016-06-22 16:40:52 -05001367 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 Rivera31c88962015-03-05 19:29:09 -06001372
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 Radulescu9989b592016-06-22 16:40:52 -05001379 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 Rivera31c88962015-03-05 19:29:09 -06001385
1386 return 0;
1387}