1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
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.
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
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.
32 #include "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
34 #include "../include/dprc.h"
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
44 * Return: '0' on Success; Error code otherwise.
46 * @warning Required before any operation on the object.
48 int dprc_open(struct fsl_mc_io *mc_io,
53 struct mc_command cmd = { 0 };
54 struct dprc_cmd_open *cmd_params;
58 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
60 cmd_params = (struct dprc_cmd_open *)cmd.params;
61 cmd_params->container_id = cpu_to_le32(container_id);
63 /* send command to mc*/
64 err = mc_send_command(mc_io, &cmd);
68 /* retrieve response parameters */
69 *token = mc_cmd_hdr_read_token(&cmd);
73 EXPORT_SYMBOL(dprc_open);
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
81 * After this function is called, no further operations are
82 * allowed on the object without opening a new control session.
84 * Return: '0' on Success; Error code otherwise.
86 int dprc_close(struct fsl_mc_io *mc_io,
90 struct mc_command cmd = { 0 };
93 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
96 /* send command to mc*/
97 return mc_send_command(mc_io, &cmd);
99 EXPORT_SYMBOL(dprc_close);
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
110 * Return: '0' on Success; Error code otherwise.
112 int dprc_create_container(struct fsl_mc_io *mc_io,
115 struct dprc_cfg *cfg,
116 int *child_container_id,
117 u64 *child_portal_offset)
119 struct mc_command cmd = { 0 };
120 struct dprc_cmd_create_container *cmd_params;
121 struct dprc_rsp_create_container *rsp_params;
124 /* prepare command */
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';
132 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
135 /* send command to mc*/
136 err = mc_send_command(mc_io, &cmd);
140 /* retrieve response parameters */
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);
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
155 * This function terminates the child container, so following this call the
156 * child container ID becomes invalid.
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.
164 * warning: Only the parent container is allowed to destroy a child policy
165 * Container 0 can't be destroyed
167 * Return: '0' on Success; Error code otherwise.
170 int dprc_destroy_container(struct fsl_mc_io *mc_io,
173 int child_container_id)
175 struct mc_command cmd = { 0 };
176 struct dprc_cmd_destroy_container *cmd_params;
178 /* prepare command */
179 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
181 cmd_params = (struct dprc_cmd_destroy_container *)cmd.params;
182 cmd_params->child_container_id = cpu_to_le32(child_container_id);
184 /* send command to mc*/
185 return mc_send_command(mc_io, &cmd);
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
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
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
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
208 * Return: '0' on Success; Error code otherwise.
210 int dprc_reset_container(struct fsl_mc_io *mc_io,
213 int child_container_id)
215 struct mc_command cmd = { 0 };
216 struct dprc_cmd_reset_container *cmd_params;
218 /* prepare command */
219 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
221 cmd_params = (struct dprc_cmd_reset_container *)cmd.params;
222 cmd_params->child_container_id = cpu_to_le32(child_container_id);
224 /* send command to mc*/
225 return mc_send_command(mc_io, &cmd);
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
238 * Return: '0' on Success; Error code otherwise.
240 int dprc_get_irq(struct fsl_mc_io *mc_io,
245 struct dprc_irq_cfg *irq_cfg)
247 struct mc_command cmd = { 0 };
248 struct dprc_cmd_get_irq *cmd_params;
249 struct dprc_rsp_get_irq *rsp_params;
252 /* prepare command */
253 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
256 cmd_params = (struct dprc_cmd_get_irq *)cmd.params;
257 cmd_params->irq_index = irq_index;
259 /* send command to mc*/
260 err = mc_send_command(mc_io, &cmd);
264 /* retrieve response parameters */
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);
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
282 * Return: '0' on Success; Error code otherwise.
284 int dprc_set_irq(struct fsl_mc_io *mc_io,
288 struct dprc_irq_cfg *irq_cfg)
290 struct mc_command cmd = { 0 };
291 struct dprc_cmd_set_irq *cmd_params;
293 /* prepare command */
294 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
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);
303 /* send command to mc*/
304 return mc_send_command(mc_io, &cmd);
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
315 * Return: '0' on Success; Error code otherwise.
317 int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
323 struct mc_command cmd = { 0 };
324 struct dprc_cmd_get_irq_enable *cmd_params;
325 struct dprc_rsp_get_irq_enable *rsp_params;
328 /* prepare command */
329 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
331 cmd_params = (struct dprc_cmd_get_irq_enable *)cmd.params;
332 cmd_params->irq_index = irq_index;
334 /* send command to mc*/
335 err = mc_send_command(mc_io, &cmd);
339 /* retrieve response parameters */
340 rsp_params = (struct dprc_rsp_get_irq_enable *)cmd.params;
341 *en = rsp_params->enabled & DPRC_ENABLE;
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
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
359 * Return: '0' on Success; Error code otherwise.
361 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
367 struct mc_command cmd = { 0 };
368 struct dprc_cmd_set_irq_enable *cmd_params;
370 /* prepare command */
371 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
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;
377 /* send command to mc*/
378 return mc_send_command(mc_io, &cmd);
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
389 * Every interrupt can have up to 32 causes and the interrupt model supports
390 * masking/unmasking each cause independently
392 * Return: '0' on Success; Error code otherwise.
394 int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
400 struct mc_command cmd = { 0 };
401 struct dprc_cmd_get_irq_mask *cmd_params;
402 struct dprc_rsp_get_irq_mask *rsp_params;
405 /* prepare command */
406 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
408 cmd_params = (struct dprc_cmd_get_irq_mask *)cmd.params;
409 cmd_params->irq_index = irq_index;
411 /* send command to mc*/
412 err = mc_send_command(mc_io, &cmd);
416 /* retrieve response parameters */
417 rsp_params = (struct dprc_rsp_get_irq_mask *)cmd.params;
418 *mask = le32_to_cpu(rsp_params->mask);
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;
432 * 1 = consider event for asserting irq
434 * Every interrupt can have up to 32 causes and the interrupt model supports
435 * masking/unmasking each cause independently
437 * Return: '0' on Success; Error code otherwise.
439 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
445 struct mc_command cmd = { 0 };
446 struct dprc_cmd_set_irq_mask *cmd_params;
448 /* prepare command */
449 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
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;
455 /* send command to mc*/
456 return mc_send_command(mc_io, &cmd);
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
469 * Return: '0' on Success; Error code otherwise.
471 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
477 struct mc_command cmd = { 0 };
478 struct dprc_cmd_get_irq_status *cmd_params;
479 struct dprc_rsp_get_irq_status *rsp_params;
482 /* prepare command */
483 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
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;
489 /* send command to mc*/
490 err = mc_send_command(mc_io, &cmd);
494 /* retrieve response parameters */
495 rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
496 *status = le32_to_cpu(rsp_params->status);
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:
509 * 1 = clear status bit
511 * Return: '0' on Success; Error code otherwise.
513 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
519 struct mc_command cmd = { 0 };
520 struct dprc_cmd_clear_irq_status *cmd_params;
522 /* prepare command */
523 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
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;
529 /* send command to mc*/
530 return mc_send_command(mc_io, &cmd);
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
540 * Return: '0' on Success; Error code otherwise.
542 int dprc_get_attributes(struct fsl_mc_io *mc_io,
545 struct dprc_attributes *attr)
547 struct mc_command cmd = { 0 };
548 struct dprc_rsp_get_attributes *rsp_params;
551 /* prepare command */
552 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
556 /* send command to mc*/
557 err = mc_send_command(mc_io, &cmd);
561 /* retrieve response parameters */
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);
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
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.
590 * This function sets allocation policy for a specific resource type.
591 * The default policy for all resource types matches the container's 'global'
594 * Return: '0' on Success; Error code otherwise.
596 * @warning Only the parent container is allowed to change a child policy.
598 int dprc_set_res_quota(struct fsl_mc_io *mc_io,
601 int child_container_id,
605 struct mc_command cmd = { 0 };
606 struct dprc_cmd_set_res_quota *cmd_params;
608 /* prepare command */
609 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
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';
617 /* send command to mc*/
618 return mc_send_command(mc_io, &cmd);
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
634 * Return: '0' on Success; Error code otherwise.
636 int dprc_get_res_quota(struct fsl_mc_io *mc_io,
639 int child_container_id,
643 struct mc_command cmd = { 0 };
644 struct dprc_cmd_get_res_quota *cmd_params;
645 struct dprc_rsp_get_res_quota *rsp_params;
648 /* prepare command */
649 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
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';
656 /* send command to mc*/
657 err = mc_send_command(mc_io, &cmd);
661 /* retrieve response parameters */
662 rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params;
663 *quota = le16_to_cpu(rsp_params->quota);
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
677 * Assignment is usually done by a parent (this DPRC) to one of its child
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.
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.
692 * A container may use this function with its own ID in order to change a
693 * object state to plugged or unplugged.
695 * If IRQ information has been set in the child DPRC, it will signal an
696 * interrupt following every change in its object assignment.
698 * Return: '0' on Success; Error code otherwise.
700 int dprc_assign(struct fsl_mc_io *mc_io,
704 struct dprc_res_req *res_req)
706 struct mc_command cmd = { 0 };
707 struct dprc_cmd_assign *cmd_params;
709 /* prepare command */
710 cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
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';
720 /* send command to mc*/
721 return mc_send_command(mc_io, &cmd);
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
734 * Un-assignment of objects can succeed only if the object is not in the
735 * plugged or opened state.
737 * Return: '0' on Success; Error code otherwise.
739 int dprc_unassign(struct fsl_mc_io *mc_io,
742 int child_container_id,
743 struct dprc_res_req *res_req)
745 struct mc_command cmd = { 0 };
746 struct dprc_cmd_unassign *cmd_params;
748 /* prepare command */
749 cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
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';
760 /* send command to mc*/
761 return mc_send_command(mc_io, &cmd);
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
771 * Return: '0' on Success; Error code otherwise.
773 int dprc_get_pool_count(struct fsl_mc_io *mc_io,
778 struct mc_command cmd = { 0 };
779 struct dprc_rsp_get_pool_count *rsp_params;
782 /* prepare command */
783 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
786 /* send command to mc*/
787 err = mc_send_command(mc_io, &cmd);
791 /* retrieve response parameters */
792 rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params;
793 *pool_count = le32_to_cpu(rsp_params->pool_count);
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
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().
811 * Return: '0' on Success; Error code otherwise.
813 int dprc_get_pool(struct fsl_mc_io *mc_io,
819 struct mc_command cmd = { 0 };
820 struct dprc_cmd_get_pool *cmd_params;
821 struct dprc_rsp_get_pool *rsp_params;
824 /* prepare command */
825 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
828 cmd_params = (struct dprc_cmd_get_pool *)cmd.params;
829 cmd_params->pool_index = cpu_to_le32(pool_index);
831 /* send command to mc*/
832 err = mc_send_command(mc_io, &cmd);
836 /* retrieve response parameters */
837 rsp_params = (struct dprc_rsp_get_pool *)cmd.params;
838 strncpy(type, rsp_params->type, 16);
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
851 * Return: '0' on Success; Error code otherwise.
853 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
858 struct mc_command cmd = { 0 };
859 struct dprc_rsp_get_obj_count *rsp_params;
862 /* prepare command */
863 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
866 /* send command to mc*/
867 err = mc_send_command(mc_io, &cmd);
871 /* retrieve response parameters */
872 rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
873 *obj_count = le32_to_cpu(rsp_params->obj_count);
877 EXPORT_SYMBOL(dprc_get_obj_count);
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
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().
892 * Return: '0' on Success; Error code otherwise.
894 int dprc_get_obj(struct fsl_mc_io *mc_io,
898 struct dprc_obj_desc *obj_desc)
900 struct mc_command cmd = { 0 };
901 struct dprc_cmd_get_obj *cmd_params;
902 struct dprc_rsp_get_obj *rsp_params;
905 /* prepare command */
906 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
909 cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
910 cmd_params->obj_index = cpu_to_le32(obj_index);
912 /* send command to mc*/
913 err = mc_send_command(mc_io, &cmd);
917 /* retrieve response parameters */
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);
928 obj_desc->type[15] = '\0';
929 strncpy(obj_desc->label, rsp_params->label, 16);
930 obj_desc->label[15] = '\0';
933 EXPORT_SYMBOL(dprc_get_obj);
936 * dprc_get_obj_desc() - Get object descriptor.
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
945 * Return: '0' on Success; Error code otherwise.
948 int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
953 struct dprc_obj_desc *obj_desc)
955 struct mc_command cmd = { 0 };
956 struct dprc_cmd_get_obj_desc *cmd_params;
957 struct dprc_rsp_get_obj_desc *rsp_params;
960 /* prepare command */
961 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
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';
969 /* send command to mc*/
970 err = mc_send_command(mc_io, &cmd);
974 /* retrieve response parameters */
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';
991 EXPORT_SYMBOL(dprc_get_obj_desc);
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
1003 * Return: '0' on Success; Error code otherwise.
1005 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
1011 struct dprc_irq_cfg *irq_cfg)
1013 struct mc_command cmd = { 0 };
1014 struct dprc_cmd_set_obj_irq *cmd_params;
1016 /* prepare command */
1017 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
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';
1029 /* send command to mc*/
1030 return mc_send_command(mc_io, &cmd);
1032 EXPORT_SYMBOL(dprc_set_obj_irq);
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
1046 * Return: '0' on Success; Error code otherwise.
1048 int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
1055 struct dprc_irq_cfg *irq_cfg)
1057 struct mc_command cmd = { 0 };
1058 struct dprc_cmd_get_obj_irq *cmd_params;
1059 struct dprc_rsp_get_obj_irq *rsp_params;
1062 /* prepare command */
1063 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
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';
1072 /* send command to mc*/
1073 err = mc_send_command(mc_io, &cmd);
1077 /* retrieve response parameters */
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);
1086 EXPORT_SYMBOL(dprc_get_obj_irq);
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
1095 * @res_count: Returned number of free resources of the given
1096 * resource type that are assigned to this DPRC
1098 * Return: '0' on Success; Error code otherwise.
1100 int dprc_get_res_count(struct fsl_mc_io *mc_io,
1106 struct mc_command cmd = { 0 };
1107 struct dprc_cmd_get_res_count *cmd_params;
1108 struct dprc_rsp_get_res_count *rsp_params;
1111 /* prepare command */
1112 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
1114 cmd_params = (struct dprc_cmd_get_res_count *)cmd.params;
1115 strncpy(cmd_params->type, type, 16);
1116 cmd_params->type[15] = '\0';
1118 /* send command to mc*/
1119 err = mc_send_command(mc_io, &cmd);
1123 /* retrieve response parameters */
1124 rsp_params = (struct dprc_rsp_get_res_count *)cmd.params;
1125 *res_count = le32_to_cpu(rsp_params->res_count);
1129 EXPORT_SYMBOL(dprc_get_res_count);
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
1137 * @range_desc: range descriptor
1139 * Return: '0' on Success; Error code otherwise.
1141 int dprc_get_res_ids(struct fsl_mc_io *mc_io,
1145 struct dprc_res_ids_range_desc *range_desc)
1147 struct mc_command cmd = { 0 };
1148 struct dprc_cmd_get_res_ids *cmd_params;
1149 struct dprc_rsp_get_res_ids *rsp_params;
1152 /* prepare command */
1153 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
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';
1162 /* send command to mc*/
1163 err = mc_send_command(mc_io, &cmd);
1167 /* retrieve response parameters */
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);
1175 EXPORT_SYMBOL(dprc_get_res_ids);
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
1187 * Return: '0' on Success; Error code otherwise.
1189 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
1195 struct dprc_region_desc *region_desc)
1197 struct mc_command cmd = { 0 };
1198 struct dprc_cmd_get_obj_region *cmd_params;
1199 struct dprc_rsp_get_obj_region *rsp_params;
1202 /* prepare command */
1203 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
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';
1211 /* send command to mc*/
1212 err = mc_send_command(mc_io, &cmd);
1216 /* retrieve response parameters */
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);
1223 EXPORT_SYMBOL(dprc_get_obj_region);
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.
1234 * Return: '0' on Success; Error code otherwise.
1236 int dprc_set_obj_label(struct fsl_mc_io *mc_io,
1243 struct mc_command cmd = { 0 };
1244 struct dprc_cmd_set_obj_label *cmd_params;
1246 /* prepare command */
1247 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
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';
1257 /* send command to mc*/
1258 return mc_send_command(mc_io, &cmd);
1260 EXPORT_SYMBOL(dprc_set_obj_label);
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
1270 * connections made to DPMAC objects, where rate is retrieved from the
1271 * MAC configuration.
1273 * Return: '0' on Success; Error code otherwise.
1275 int dprc_connect(struct fsl_mc_io *mc_io,
1278 const struct dprc_endpoint *endpoint1,
1279 const struct dprc_endpoint *endpoint2,
1280 const struct dprc_connection_cfg *cfg)
1282 struct mc_command cmd = { 0 };
1283 struct dprc_cmd_connect *cmd_params;
1285 /* prepare command */
1286 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
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';
1301 /* send command to mc*/
1302 return mc_send_command(mc_io, &cmd);
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
1312 * Return: '0' on Success; Error code otherwise.
1314 int dprc_disconnect(struct fsl_mc_io *mc_io,
1317 const struct dprc_endpoint *endpoint)
1319 struct mc_command cmd = { 0 };
1320 struct dprc_cmd_disconnect *cmd_params;
1322 /* prepare command */
1323 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
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';
1332 /* send command to mc*/
1333 return mc_send_command(mc_io, &cmd);
1337 * dprc_get_connection() - Get connected endpoint and link status if connection
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
1344 * @state: Returned link state:
1347 * -1 - no connection (endpoint2 information is irrelevant)
1349 * Return: '0' on Success; -ENAVAIL if connection does not exist.
1351 int dprc_get_connection(struct fsl_mc_io *mc_io,
1354 const struct dprc_endpoint *endpoint1,
1355 struct dprc_endpoint *endpoint2,
1358 struct mc_command cmd = { 0 };
1359 struct dprc_cmd_get_connection *cmd_params;
1360 struct dprc_rsp_get_connection *rsp_params;
1363 /* prepare command */
1364 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
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';
1373 /* send command to mc*/
1374 err = mc_send_command(mc_io, &cmd);
1378 /* retrieve response parameters */
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);