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"
39 * dprc_open() - Open DPRC object for use
40 * @mc_io: Pointer to MC portal's I/O object
41 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
42 * @container_id: Container ID to open
43 * @token: Returned token of DPRC object
45 * Return: '0' on Success; Error code otherwise.
47 * @warning Required before any operation on the object.
49 int dprc_open(struct fsl_mc_io *mc_io,
54 struct mc_command cmd = { 0 };
55 struct dprc_cmd_open *cmd_params;
59 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
61 cmd_params = (struct dprc_cmd_open *)cmd.params;
62 cmd_params->container_id = cpu_to_le32(container_id);
64 /* send command to mc*/
65 err = mc_send_command(mc_io, &cmd);
69 /* retrieve response parameters */
70 *token = mc_cmd_hdr_read_token(&cmd);
74 EXPORT_SYMBOL(dprc_open);
77 * dprc_close() - Close the control session of the object
78 * @mc_io: Pointer to MC portal's I/O object
79 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
80 * @token: Token of DPRC object
82 * After this function is called, no further operations are
83 * allowed on the object without opening a new control session.
85 * Return: '0' on Success; Error code otherwise.
87 int dprc_close(struct fsl_mc_io *mc_io,
91 struct mc_command cmd = { 0 };
94 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
97 /* send command to mc*/
98 return mc_send_command(mc_io, &cmd);
100 EXPORT_SYMBOL(dprc_close);
103 * dprc_create_container() - Create child container
104 * @mc_io: Pointer to MC portal's I/O object
105 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
106 * @token: Token of DPRC object
107 * @cfg: Child container configuration
108 * @child_container_id: Returned child container ID
109 * @child_portal_offset: Returned child portal offset from MC portal base
111 * Return: '0' on Success; Error code otherwise.
113 int dprc_create_container(struct fsl_mc_io *mc_io,
116 struct dprc_cfg *cfg,
117 int *child_container_id,
118 u64 *child_portal_offset)
120 struct mc_command cmd = { 0 };
121 struct dprc_cmd_create_container *cmd_params;
122 struct dprc_rsp_create_container *rsp_params;
125 /* prepare command */
126 cmd_params = (struct dprc_cmd_create_container *)cmd.params;
127 cmd_params->options = cpu_to_le32(cfg->options);
128 cmd_params->icid = cpu_to_le16(cfg->icid);
129 cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
130 strncpy(cmd_params->label, cfg->label, 16);
131 cmd_params->label[15] = '\0';
133 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
136 /* send command to mc*/
137 err = mc_send_command(mc_io, &cmd);
141 /* retrieve response parameters */
142 rsp_params = (struct dprc_rsp_create_container *)cmd.params;
143 *child_container_id = le32_to_cpu(rsp_params->child_container_id);
144 *child_portal_offset = le64_to_cpu(rsp_params->child_portal_addr);
150 * dprc_destroy_container() - Destroy child container.
151 * @mc_io: Pointer to MC portal's I/O object
152 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
153 * @token: Token of DPRC object
154 * @child_container_id: ID of the container to destroy
156 * This function terminates the child container, so following this call the
157 * child container ID becomes invalid.
160 * - All resources and objects of the destroyed container are returned to the
161 * parent container or destroyed if were created be the destroyed container.
162 * - This function destroy all the child containers of the specified
163 * container prior to destroying the container itself.
165 * warning: Only the parent container is allowed to destroy a child policy
166 * Container 0 can't be destroyed
168 * Return: '0' on Success; Error code otherwise.
171 int dprc_destroy_container(struct fsl_mc_io *mc_io,
174 int child_container_id)
176 struct mc_command cmd = { 0 };
177 struct dprc_cmd_destroy_container *cmd_params;
179 /* prepare command */
180 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
182 cmd_params = (struct dprc_cmd_destroy_container *)cmd.params;
183 cmd_params->child_container_id = cpu_to_le32(child_container_id);
185 /* send command to mc*/
186 return mc_send_command(mc_io, &cmd);
190 * dprc_reset_container - Reset child container.
191 * @mc_io: Pointer to MC portal's I/O object
192 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
193 * @token: Token of DPRC object
194 * @child_container_id: ID of the container to reset
196 * In case a software context crashes or becomes non-responsive, the parent
197 * may wish to reset its resources container before the software context is
200 * This routine informs all objects assigned to the child container that the
201 * container is being reset, so they may perform any cleanup operations that are
202 * needed. All objects handles that were owned by the child container shall be
205 * Note that such request may be submitted even if the child software context
206 * has not crashed, but the resulting object cleanup operations will not be
209 * Return: '0' on Success; Error code otherwise.
211 int dprc_reset_container(struct fsl_mc_io *mc_io,
214 int child_container_id)
216 struct mc_command cmd = { 0 };
217 struct dprc_cmd_reset_container *cmd_params;
219 /* prepare command */
220 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
222 cmd_params = (struct dprc_cmd_reset_container *)cmd.params;
223 cmd_params->child_container_id = cpu_to_le32(child_container_id);
225 /* send command to mc*/
226 return mc_send_command(mc_io, &cmd);
230 * dprc_get_irq() - Get IRQ information from the DPRC.
231 * @mc_io: Pointer to MC portal's I/O object
232 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
233 * @token: Token of DPRC object
234 * @irq_index: The interrupt index to configure
235 * @type: Interrupt type: 0 represents message interrupt
236 * type (both irq_addr and irq_val are valid)
237 * @irq_cfg: IRQ attributes
239 * Return: '0' on Success; Error code otherwise.
241 int dprc_get_irq(struct fsl_mc_io *mc_io,
246 struct dprc_irq_cfg *irq_cfg)
248 struct mc_command cmd = { 0 };
249 struct dprc_cmd_get_irq *cmd_params;
250 struct dprc_rsp_get_irq *rsp_params;
253 /* prepare command */
254 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
257 cmd_params = (struct dprc_cmd_get_irq *)cmd.params;
258 cmd_params->irq_index = irq_index;
260 /* send command to mc*/
261 err = mc_send_command(mc_io, &cmd);
265 /* retrieve response parameters */
266 rsp_params = (struct dprc_rsp_get_irq *)cmd.params;
267 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
268 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
269 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
270 *type = le32_to_cpu(rsp_params->type);
276 * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
277 * @mc_io: Pointer to MC portal's I/O object
278 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
279 * @token: Token of DPRC object
280 * @irq_index: Identifies the interrupt index to configure
281 * @irq_cfg: IRQ configuration
283 * Return: '0' on Success; Error code otherwise.
285 int dprc_set_irq(struct fsl_mc_io *mc_io,
289 struct dprc_irq_cfg *irq_cfg)
291 struct mc_command cmd = { 0 };
292 struct dprc_cmd_set_irq *cmd_params;
294 /* prepare command */
295 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
298 cmd_params = (struct dprc_cmd_set_irq *)cmd.params;
299 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
300 cmd_params->irq_index = irq_index;
301 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
302 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
304 /* send command to mc*/
305 return mc_send_command(mc_io, &cmd);
309 * dprc_get_irq_enable() - Get overall interrupt state.
310 * @mc_io: Pointer to MC portal's I/O object
311 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
312 * @token: Token of DPRC object
313 * @irq_index: The interrupt index to configure
314 * @en: Returned interrupt state - enable = 1, disable = 0
316 * Return: '0' on Success; Error code otherwise.
318 int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
324 struct mc_command cmd = { 0 };
325 struct dprc_cmd_get_irq_enable *cmd_params;
326 struct dprc_rsp_get_irq_enable *rsp_params;
329 /* prepare command */
330 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
332 cmd_params = (struct dprc_cmd_get_irq_enable *)cmd.params;
333 cmd_params->irq_index = irq_index;
335 /* send command to mc*/
336 err = mc_send_command(mc_io, &cmd);
340 /* retrieve response parameters */
341 rsp_params = (struct dprc_rsp_get_irq_enable *)cmd.params;
342 *en = rsp_params->enabled & DPRC_ENABLE;
348 * dprc_set_irq_enable() - Set overall interrupt state.
349 * @mc_io: Pointer to MC portal's I/O object
350 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
351 * @token: Token of DPRC object
352 * @irq_index: The interrupt index to configure
353 * @en: Interrupt state - enable = 1, disable = 0
355 * Allows GPP software to control when interrupts are generated.
356 * Each interrupt can have up to 32 causes. The enable/disable control's the
357 * overall interrupt state. if the interrupt is disabled no causes will cause
360 * Return: '0' on Success; Error code otherwise.
362 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
368 struct mc_command cmd = { 0 };
369 struct dprc_cmd_set_irq_enable *cmd_params;
371 /* prepare command */
372 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
374 cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params;
375 cmd_params->enable = en & DPRC_ENABLE;
376 cmd_params->irq_index = irq_index;
378 /* send command to mc*/
379 return mc_send_command(mc_io, &cmd);
383 * dprc_get_irq_mask() - Get interrupt mask.
384 * @mc_io: Pointer to MC portal's I/O object
385 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
386 * @token: Token of DPRC object
387 * @irq_index: The interrupt index to configure
388 * @mask: Returned event mask to trigger interrupt
390 * Every interrupt can have up to 32 causes and the interrupt model supports
391 * masking/unmasking each cause independently
393 * Return: '0' on Success; Error code otherwise.
395 int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
401 struct mc_command cmd = { 0 };
402 struct dprc_cmd_get_irq_mask *cmd_params;
403 struct dprc_rsp_get_irq_mask *rsp_params;
406 /* prepare command */
407 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
409 cmd_params = (struct dprc_cmd_get_irq_mask *)cmd.params;
410 cmd_params->irq_index = irq_index;
412 /* send command to mc*/
413 err = mc_send_command(mc_io, &cmd);
417 /* retrieve response parameters */
418 rsp_params = (struct dprc_rsp_get_irq_mask *)cmd.params;
419 *mask = le32_to_cpu(rsp_params->mask);
425 * dprc_set_irq_mask() - Set interrupt mask.
426 * @mc_io: Pointer to MC portal's I/O object
427 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
428 * @token: Token of DPRC object
429 * @irq_index: The interrupt index to configure
430 * @mask: event mask to trigger interrupt;
433 * 1 = consider event for asserting irq
435 * Every interrupt can have up to 32 causes and the interrupt model supports
436 * masking/unmasking each cause independently
438 * Return: '0' on Success; Error code otherwise.
440 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
446 struct mc_command cmd = { 0 };
447 struct dprc_cmd_set_irq_mask *cmd_params;
449 /* prepare command */
450 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
452 cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params;
453 cmd_params->mask = cpu_to_le32(mask);
454 cmd_params->irq_index = irq_index;
456 /* send command to mc*/
457 return mc_send_command(mc_io, &cmd);
461 * dprc_get_irq_status() - Get the current status of any pending interrupts.
462 * @mc_io: Pointer to MC portal's I/O object
463 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
464 * @token: Token of DPRC object
465 * @irq_index: The interrupt index to configure
466 * @status: Returned interrupts status - one bit per cause:
467 * 0 = no interrupt pending
468 * 1 = interrupt pending
470 * Return: '0' on Success; Error code otherwise.
472 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
478 struct mc_command cmd = { 0 };
479 struct dprc_cmd_get_irq_status *cmd_params;
480 struct dprc_rsp_get_irq_status *rsp_params;
483 /* prepare command */
484 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
486 cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params;
487 cmd_params->status = cpu_to_le32(*status);
488 cmd_params->irq_index = irq_index;
490 /* send command to mc*/
491 err = mc_send_command(mc_io, &cmd);
495 /* retrieve response parameters */
496 rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
497 *status = le32_to_cpu(rsp_params->status);
503 * dprc_clear_irq_status() - Clear a pending interrupt's status
504 * @mc_io: Pointer to MC portal's I/O object
505 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
506 * @token: Token of DPRC object
507 * @irq_index: The interrupt index to configure
508 * @status: bits to clear (W1C) - one bit per cause:
510 * 1 = clear status bit
512 * Return: '0' on Success; Error code otherwise.
514 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
520 struct mc_command cmd = { 0 };
521 struct dprc_cmd_clear_irq_status *cmd_params;
523 /* prepare command */
524 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
526 cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params;
527 cmd_params->status = cpu_to_le32(status);
528 cmd_params->irq_index = irq_index;
530 /* send command to mc*/
531 return mc_send_command(mc_io, &cmd);
535 * dprc_get_attributes() - Obtains container attributes
536 * @mc_io: Pointer to MC portal's I/O object
537 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
538 * @token: Token of DPRC object
539 * @attributes Returned container attributes
541 * Return: '0' on Success; Error code otherwise.
543 int dprc_get_attributes(struct fsl_mc_io *mc_io,
546 struct dprc_attributes *attr)
548 struct mc_command cmd = { 0 };
549 struct dprc_rsp_get_attributes *rsp_params;
552 /* prepare command */
553 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
557 /* send command to mc*/
558 err = mc_send_command(mc_io, &cmd);
562 /* retrieve response parameters */
563 rsp_params = (struct dprc_rsp_get_attributes *)cmd.params;
564 attr->container_id = le32_to_cpu(rsp_params->container_id);
565 attr->icid = le16_to_cpu(rsp_params->icid);
566 attr->options = le32_to_cpu(rsp_params->options);
567 attr->portal_id = le32_to_cpu(rsp_params->portal_id);
568 attr->version.major = le16_to_cpu(rsp_params->version_major);
569 attr->version.minor = le16_to_cpu(rsp_params->version_minor);
575 * dprc_set_res_quota() - Set allocation policy for a specific resource/object
576 * type in a child container
577 * @mc_io: Pointer to MC portal's I/O object
578 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
579 * @token: Token of DPRC object
580 * @child_container_id: ID of the child container
581 * @type: Resource/object type
582 * @quota: Sets the maximum number of resources of the selected type
583 * that the child container is allowed to allocate from its parent;
584 * when quota is set to -1, the policy is the same as container's
587 * Allocation policy determines whether or not a container may allocate
588 * resources from its parent. Each container has a 'global' allocation policy
589 * that is set when the container is created.
591 * This function sets allocation policy for a specific resource type.
592 * The default policy for all resource types matches the container's 'global'
595 * Return: '0' on Success; Error code otherwise.
597 * @warning Only the parent container is allowed to change a child policy.
599 int dprc_set_res_quota(struct fsl_mc_io *mc_io,
602 int child_container_id,
606 struct mc_command cmd = { 0 };
607 struct dprc_cmd_set_res_quota *cmd_params;
609 /* prepare command */
610 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
612 cmd_params = (struct dprc_cmd_set_res_quota *)cmd.params;
613 cmd_params->child_container_id = cpu_to_le32(child_container_id);
614 cmd_params->quota = cpu_to_le16(quota);
615 strncpy(cmd_params->type, type, 16);
616 cmd_params->type[15] = '\0';
618 /* send command to mc*/
619 return mc_send_command(mc_io, &cmd);
623 * dprc_get_res_quota() - Gets the allocation policy of a specific
624 * resource/object type in a child container
625 * @mc_io: Pointer to MC portal's I/O object
626 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
627 * @token: Token of DPRC object
628 * @child_container_id; ID of the child container
629 * @type: resource/object type
630 * @quota: Returnes the maximum number of resources of the selected type
631 * that the child container is allowed to allocate from the parent;
632 * when quota is set to -1, the policy is the same as container's
635 * Return: '0' on Success; Error code otherwise.
637 int dprc_get_res_quota(struct fsl_mc_io *mc_io,
640 int child_container_id,
644 struct mc_command cmd = { 0 };
645 struct dprc_cmd_get_res_quota *cmd_params;
646 struct dprc_rsp_get_res_quota *rsp_params;
649 /* prepare command */
650 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
652 cmd_params = (struct dprc_cmd_get_res_quota *)cmd.params;
653 cmd_params->child_container_id = cpu_to_le32(child_container_id);
654 strncpy(cmd_params->type, type, 16);
655 cmd_params->type[15] = '\0';
657 /* send command to mc*/
658 err = mc_send_command(mc_io, &cmd);
662 /* retrieve response parameters */
663 rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params;
664 *quota = le16_to_cpu(rsp_params->quota);
670 * dprc_assign() - Assigns objects or resource to a child container.
671 * @mc_io: Pointer to MC portal's I/O object
672 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
673 * @token: Token of DPRC object
674 * @container_id: ID of the child container
675 * @res_req: Describes the type and amount of resources to
676 * assign to the given container
678 * Assignment is usually done by a parent (this DPRC) to one of its child
681 * According to the DPRC allocation policy, the assigned resources may be taken
682 * (allocated) from the container's ancestors, if not enough resources are
683 * available in the container itself.
685 * The type of assignment depends on the dprc_res_req options, as follows:
686 * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
687 * the explicit base ID specified at the id_base_align field of res_req.
688 * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
689 * aligned to the value given at id_base_align field of res_req.
690 * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
691 * and indicates that the object must be set to the plugged state.
693 * A container may use this function with its own ID in order to change a
694 * object state to plugged or unplugged.
696 * If IRQ information has been set in the child DPRC, it will signal an
697 * interrupt following every change in its object assignment.
699 * Return: '0' on Success; Error code otherwise.
701 int dprc_assign(struct fsl_mc_io *mc_io,
705 struct dprc_res_req *res_req)
707 struct mc_command cmd = { 0 };
708 struct dprc_cmd_assign *cmd_params;
710 /* prepare command */
711 cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
713 cmd_params = (struct dprc_cmd_assign *)cmd.params;
714 cmd_params->container_id = cpu_to_le32(container_id);
715 cmd_params->options = cpu_to_le32(res_req->options);
716 cmd_params->num = cpu_to_le32(res_req->num);
717 cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
718 strncpy(cmd_params->type, res_req->type, 16);
719 cmd_params->type[15] = '\0';
721 /* send command to mc*/
722 return mc_send_command(mc_io, &cmd);
726 * dprc_unassign() - Un-assigns objects or resources from a child container
727 * and moves them into this (parent) DPRC.
728 * @mc_io: Pointer to MC portal's I/O object
729 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
730 * @token: Token of DPRC object
731 * @child_container_id: ID of the child container
732 * @res_req: Describes the type and amount of resources to un-assign from
733 * the child container
735 * Un-assignment of objects can succeed only if the object is not in the
736 * plugged or opened state.
738 * Return: '0' on Success; Error code otherwise.
740 int dprc_unassign(struct fsl_mc_io *mc_io,
743 int child_container_id,
744 struct dprc_res_req *res_req)
746 struct mc_command cmd = { 0 };
747 struct dprc_cmd_unassign *cmd_params;
749 /* prepare command */
750 cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
753 cmd_params = (struct dprc_cmd_unassign *)cmd.params;
754 cmd_params->child_container_id = cpu_to_le32(child_container_id);
755 cmd_params->options = cpu_to_le32(res_req->options);
756 cmd_params->num = cpu_to_le32(res_req->num);
757 cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
758 strncpy(cmd_params->type, res_req->type, 16);
759 cmd_params->type[15] = '\0';
761 /* send command to mc*/
762 return mc_send_command(mc_io, &cmd);
766 * dprc_get_pool_count() - Get the number of dprc's pools
767 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
768 * @mc_io: Pointer to MC portal's I/O object
769 * @token: Token of DPRC object
770 * @pool_count: Returned number of resource pools in the dprc
772 * Return: '0' on Success; Error code otherwise.
774 int dprc_get_pool_count(struct fsl_mc_io *mc_io,
779 struct mc_command cmd = { 0 };
780 struct dprc_rsp_get_pool_count *rsp_params;
783 /* prepare command */
784 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
787 /* send command to mc*/
788 err = mc_send_command(mc_io, &cmd);
792 /* retrieve response parameters */
793 rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params;
794 *pool_count = le32_to_cpu(rsp_params->pool_count);
800 * dprc_get_pool() - Get the type (string) of a certain dprc's pool
801 * @mc_io: Pointer to MC portal's I/O object
802 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
803 * @token: Token of DPRC object
804 * @pool_index; Index of the pool to be queried (< pool_count)
805 * @type: The type of the pool
807 * The pool types retrieved one by one by incrementing
808 * pool_index up to (not including) the value of pool_count returned
809 * from dprc_get_pool_count(). dprc_get_pool_count() must
810 * be called prior to dprc_get_pool().
812 * Return: '0' on Success; Error code otherwise.
814 int dprc_get_pool(struct fsl_mc_io *mc_io,
820 struct mc_command cmd = { 0 };
821 struct dprc_cmd_get_pool *cmd_params;
822 struct dprc_rsp_get_pool *rsp_params;
825 /* prepare command */
826 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
829 cmd_params = (struct dprc_cmd_get_pool *)cmd.params;
830 cmd_params->pool_index = cpu_to_le32(pool_index);
832 /* send command to mc*/
833 err = mc_send_command(mc_io, &cmd);
837 /* retrieve response parameters */
838 rsp_params = (struct dprc_rsp_get_pool *)cmd.params;
839 strncpy(type, rsp_params->type, 16);
846 * dprc_get_obj_count() - Obtains the number of objects in the DPRC
847 * @mc_io: Pointer to MC portal's I/O object
848 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
849 * @token: Token of DPRC object
850 * @obj_count: Number of objects assigned to the DPRC
852 * Return: '0' on Success; Error code otherwise.
854 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
859 struct mc_command cmd = { 0 };
860 struct dprc_rsp_get_obj_count *rsp_params;
863 /* prepare command */
864 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
867 /* send command to mc*/
868 err = mc_send_command(mc_io, &cmd);
872 /* retrieve response parameters */
873 rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
874 *obj_count = le32_to_cpu(rsp_params->obj_count);
878 EXPORT_SYMBOL(dprc_get_obj_count);
881 * dprc_get_obj() - Get general information on an object
882 * @mc_io: Pointer to MC portal's I/O object
883 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
884 * @token: Token of DPRC object
885 * @obj_index: Index of the object to be queried (< obj_count)
886 * @obj_desc: Returns the requested object descriptor
888 * The object descriptors are retrieved one by one by incrementing
889 * obj_index up to (not including) the value of obj_count returned
890 * from dprc_get_obj_count(). dprc_get_obj_count() must
891 * be called prior to dprc_get_obj().
893 * Return: '0' on Success; Error code otherwise.
895 int dprc_get_obj(struct fsl_mc_io *mc_io,
899 struct dprc_obj_desc *obj_desc)
901 struct mc_command cmd = { 0 };
902 struct dprc_cmd_get_obj *cmd_params;
903 struct dprc_rsp_get_obj *rsp_params;
906 /* prepare command */
907 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
910 cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
911 cmd_params->obj_index = cpu_to_le32(obj_index);
913 /* send command to mc*/
914 err = mc_send_command(mc_io, &cmd);
918 /* retrieve response parameters */
919 rsp_params = (struct dprc_rsp_get_obj *)cmd.params;
920 obj_desc->id = le32_to_cpu(rsp_params->id);
921 obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
922 obj_desc->irq_count = rsp_params->irq_count;
923 obj_desc->region_count = rsp_params->region_count;
924 obj_desc->state = le32_to_cpu(rsp_params->state);
925 obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
926 obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
927 obj_desc->flags = le16_to_cpu(rsp_params->flags);
928 strncpy(obj_desc->type, rsp_params->type, 16);
929 obj_desc->type[15] = '\0';
930 strncpy(obj_desc->label, rsp_params->label, 16);
931 obj_desc->label[15] = '\0';
934 EXPORT_SYMBOL(dprc_get_obj);
937 * dprc_get_obj_desc() - Get object descriptor.
939 * @mc_io: Pointer to MC portal's I/O object
940 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
941 * @token: Token of DPRC object
942 * @obj_type: The type of the object to get its descriptor.
943 * @obj_id: The id of the object to get its descriptor
944 * @obj_desc: The returned descriptor to fill and return to the user
946 * Return: '0' on Success; Error code otherwise.
949 int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
954 struct dprc_obj_desc *obj_desc)
956 struct mc_command cmd = { 0 };
957 struct dprc_cmd_get_obj_desc *cmd_params;
958 struct dprc_rsp_get_obj_desc *rsp_params;
961 /* prepare command */
962 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
965 cmd_params = (struct dprc_cmd_get_obj_desc *)cmd.params;
966 cmd_params->obj_id = cpu_to_le32(obj_id);
967 strncpy(cmd_params->type, obj_type, 16);
968 cmd_params->type[15] = '\0';
970 /* send command to mc*/
971 err = mc_send_command(mc_io, &cmd);
975 /* retrieve response parameters */
976 rsp_params = (struct dprc_rsp_get_obj_desc *)cmd.params;
977 obj_desc->id = le32_to_cpu(rsp_params->id);
978 obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
979 obj_desc->irq_count = rsp_params->irq_count;
980 obj_desc->region_count = rsp_params->region_count;
981 obj_desc->state = le32_to_cpu(rsp_params->state);
982 obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
983 obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
984 obj_desc->flags = le16_to_cpu(rsp_params->flags);
985 strncpy(obj_desc->type, rsp_params->type, 16);
986 obj_desc->type[15] = '\0';
987 strncpy(obj_desc->label, rsp_params->label, 16);
988 obj_desc->label[15] = '\0';
992 EXPORT_SYMBOL(dprc_get_obj_desc);
995 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
996 * @mc_io: Pointer to MC portal's I/O object
997 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
998 * @token: Token of DPRC object
999 * @obj_type: Type of the object to set its IRQ
1000 * @obj_id: ID of the object to set its IRQ
1001 * @irq_index: The interrupt index to configure
1002 * @irq_cfg: IRQ configuration
1004 * Return: '0' on Success; Error code otherwise.
1006 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
1012 struct dprc_irq_cfg *irq_cfg)
1014 struct mc_command cmd = { 0 };
1015 struct dprc_cmd_set_obj_irq *cmd_params;
1017 /* prepare command */
1018 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
1021 cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params;
1022 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
1023 cmd_params->irq_index = irq_index;
1024 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
1025 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
1026 cmd_params->obj_id = cpu_to_le32(obj_id);
1027 strncpy(cmd_params->obj_type, obj_type, 16);
1028 cmd_params->obj_type[15] = '\0';
1030 /* send command to mc*/
1031 return mc_send_command(mc_io, &cmd);
1033 EXPORT_SYMBOL(dprc_set_obj_irq);
1036 * dprc_get_obj_irq() - Get IRQ information from object.
1037 * @mc_io: Pointer to MC portal's I/O object
1038 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1039 * @token: Token of DPRC object
1040 * @obj_type: Type od the object to get its IRQ
1041 * @obj_id: ID of the object to get its IRQ
1042 * @irq_index: The interrupt index to configure
1043 * @type: Interrupt type: 0 represents message interrupt
1044 * type (both irq_addr and irq_val are valid)
1045 * @irq_cfg: The returned IRQ attributes
1047 * Return: '0' on Success; Error code otherwise.
1049 int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
1056 struct dprc_irq_cfg *irq_cfg)
1058 struct mc_command cmd = { 0 };
1059 struct dprc_cmd_get_obj_irq *cmd_params;
1060 struct dprc_rsp_get_obj_irq *rsp_params;
1063 /* prepare command */
1064 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
1067 cmd_params = (struct dprc_cmd_get_obj_irq *)cmd.params;
1068 cmd_params->obj_id = cpu_to_le32(obj_id);
1069 cmd_params->irq_index = irq_index;
1070 strncpy(cmd_params->obj_type, obj_type, 16);
1071 cmd_params->obj_type[15] = '\0';
1073 /* send command to mc*/
1074 err = mc_send_command(mc_io, &cmd);
1078 /* retrieve response parameters */
1079 rsp_params = (struct dprc_rsp_get_obj_irq *)cmd.params;
1080 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
1081 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_addr);
1082 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
1083 *type = le32_to_cpu(rsp_params->type);
1087 EXPORT_SYMBOL(dprc_get_obj_irq);
1090 * dprc_get_res_count() - Obtains the number of free resources that are assigned
1091 * to this container, by pool type
1092 * @mc_io: Pointer to MC portal's I/O object
1093 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1094 * @token: Token of DPRC object
1096 * @res_count: Returned number of free resources of the given
1097 * resource type that are assigned to this DPRC
1099 * Return: '0' on Success; Error code otherwise.
1101 int dprc_get_res_count(struct fsl_mc_io *mc_io,
1107 struct mc_command cmd = { 0 };
1108 struct dprc_cmd_get_res_count *cmd_params;
1109 struct dprc_rsp_get_res_count *rsp_params;
1112 /* prepare command */
1113 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
1115 cmd_params = (struct dprc_cmd_get_res_count *)cmd.params;
1116 strncpy(cmd_params->type, type, 16);
1117 cmd_params->type[15] = '\0';
1119 /* send command to mc*/
1120 err = mc_send_command(mc_io, &cmd);
1124 /* retrieve response parameters */
1125 rsp_params = (struct dprc_rsp_get_res_count *)cmd.params;
1126 *res_count = le32_to_cpu(rsp_params->res_count);
1130 EXPORT_SYMBOL(dprc_get_res_count);
1133 * dprc_get_res_ids() - Obtains IDs of free resources in the container
1134 * @mc_io: Pointer to MC portal's I/O object
1135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1136 * @token: Token of DPRC object
1138 * @range_desc: range descriptor
1140 * Return: '0' on Success; Error code otherwise.
1142 int dprc_get_res_ids(struct fsl_mc_io *mc_io,
1146 struct dprc_res_ids_range_desc *range_desc)
1148 struct mc_command cmd = { 0 };
1149 struct dprc_cmd_get_res_ids *cmd_params;
1150 struct dprc_rsp_get_res_ids *rsp_params;
1153 /* prepare command */
1154 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
1156 cmd_params = (struct dprc_cmd_get_res_ids *)cmd.params;
1157 cmd_params->iter_status = range_desc->iter_status;
1158 cmd_params->base_id = cpu_to_le32(range_desc->base_id);
1159 cmd_params->last_id = cpu_to_le32(range_desc->last_id);
1160 strncpy(cmd_params->type, type, 16);
1161 cmd_params->type[15] = '\0';
1163 /* send command to mc*/
1164 err = mc_send_command(mc_io, &cmd);
1168 /* retrieve response parameters */
1169 rsp_params = (struct dprc_rsp_get_res_ids *)cmd.params;
1170 range_desc->iter_status = rsp_params->iter_status;
1171 range_desc->base_id = le32_to_cpu(rsp_params->base_id);
1172 range_desc->last_id = le32_to_cpu(rsp_params->last_id);
1176 EXPORT_SYMBOL(dprc_get_res_ids);
1179 * dprc_get_obj_region() - Get region information for a specified object.
1180 * @mc_io: Pointer to MC portal's I/O object
1181 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1182 * @token: Token of DPRC object
1183 * @obj_type; Object type as returned in dprc_get_obj()
1184 * @obj_id: Unique object instance as returned in dprc_get_obj()
1185 * @region_index: The specific region to query
1186 * @region_desc: Returns the requested region descriptor
1188 * Return: '0' on Success; Error code otherwise.
1190 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
1196 struct dprc_region_desc *region_desc)
1198 struct mc_command cmd = { 0 };
1199 struct dprc_cmd_get_obj_region *cmd_params;
1200 struct dprc_rsp_get_obj_region *rsp_params;
1203 /* prepare command */
1204 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
1206 cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params;
1207 cmd_params->obj_id = cpu_to_le32(obj_id);
1208 cmd_params->region_index = region_index;
1209 strncpy(cmd_params->obj_type, obj_type, 16);
1210 cmd_params->obj_type[15] = '\0';
1212 /* send command to mc*/
1213 err = mc_send_command(mc_io, &cmd);
1217 /* retrieve response parameters */
1218 rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
1219 region_desc->base_offset = le64_to_cpu(rsp_params->base_addr);
1220 region_desc->size = le32_to_cpu(rsp_params->size);
1224 EXPORT_SYMBOL(dprc_get_obj_region);
1227 * dprc_set_obj_label() - Set object label.
1228 * @mc_io: Pointer to MC portal's I/O object
1229 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1230 * @token: Token of DPRC object
1231 * @obj_type: Object's type
1232 * @obj_id: Object's ID
1233 * @label: The required label. The maximum length is 16 chars.
1235 * Return: '0' on Success; Error code otherwise.
1237 int dprc_set_obj_label(struct fsl_mc_io *mc_io,
1244 struct mc_command cmd = { 0 };
1245 struct dprc_cmd_set_obj_label *cmd_params;
1247 /* prepare command */
1248 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
1251 cmd_params = (struct dprc_cmd_set_obj_label *)cmd.params;
1252 cmd_params->obj_id = cpu_to_le32(obj_id);
1253 strncpy(cmd_params->label, label, 16);
1254 cmd_params->label[15] = '\0';
1255 strncpy(cmd_params->obj_type, obj_type, 16);
1256 cmd_params->obj_type[15] = '\0';
1258 /* send command to mc*/
1259 return mc_send_command(mc_io, &cmd);
1261 EXPORT_SYMBOL(dprc_set_obj_label);
1264 * dprc_connect() - Connect two endpoints to create a network link between them
1265 * @mc_io: Pointer to MC portal's I/O object
1266 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1267 * @token: Token of DPRC object
1268 * @endpoint1: Endpoint 1 configuration parameters
1269 * @endpoint2: Endpoint 2 configuration parameters
1270 * @cfg: Connection configuration. The connection configuration is ignored for
1271 * connections made to DPMAC objects, where rate is retrieved from the
1272 * MAC configuration.
1274 * Return: '0' on Success; Error code otherwise.
1276 int dprc_connect(struct fsl_mc_io *mc_io,
1279 const struct dprc_endpoint *endpoint1,
1280 const struct dprc_endpoint *endpoint2,
1281 const struct dprc_connection_cfg *cfg)
1283 struct mc_command cmd = { 0 };
1284 struct dprc_cmd_connect *cmd_params;
1286 /* prepare command */
1287 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
1290 cmd_params = (struct dprc_cmd_connect *)cmd.params;
1291 cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
1292 cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
1293 cmd_params->ep2_id = cpu_to_le32(endpoint2->id);
1294 cmd_params->ep2_interface_id = cpu_to_le32(endpoint2->if_id);
1295 strncpy(cmd_params->ep1_type, endpoint1->type, 16);
1296 cmd_params->ep1_type[15] = '\0';
1297 cmd_params->max_rate = cpu_to_le32(cfg->max_rate);
1298 cmd_params->committed_rate = cpu_to_le32(cfg->committed_rate);
1299 strncpy(cmd_params->ep2_type, endpoint2->type, 16);
1300 cmd_params->ep2_type[15] = '\0';
1302 /* send command to mc*/
1303 return mc_send_command(mc_io, &cmd);
1307 * dprc_disconnect() - Disconnect one endpoint to remove its network connection
1308 * @mc_io: Pointer to MC portal's I/O object
1309 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1310 * @token: Token of DPRC object
1311 * @endpoint: Endpoint configuration parameters
1313 * Return: '0' on Success; Error code otherwise.
1315 int dprc_disconnect(struct fsl_mc_io *mc_io,
1318 const struct dprc_endpoint *endpoint)
1320 struct mc_command cmd = { 0 };
1321 struct dprc_cmd_disconnect *cmd_params;
1323 /* prepare command */
1324 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
1327 cmd_params = (struct dprc_cmd_disconnect *)cmd.params;
1328 cmd_params->id = cpu_to_le32(endpoint->id);
1329 cmd_params->interface_id = cpu_to_le32(endpoint->if_id);
1330 strncpy(cmd_params->type, endpoint->type, 16);
1331 cmd_params->type[15] = '\0';
1333 /* send command to mc*/
1334 return mc_send_command(mc_io, &cmd);
1338 * dprc_get_connection() - Get connected endpoint and link status if connection
1340 * @mc_io: Pointer to MC portal's I/O object
1341 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1342 * @token: Token of DPRC object
1343 * @endpoint1: Endpoint 1 configuration parameters
1344 * @endpoint2: Returned endpoint 2 configuration parameters
1345 * @state: Returned link state:
1348 * -1 - no connection (endpoint2 information is irrelevant)
1350 * Return: '0' on Success; -ENAVAIL if connection does not exist.
1352 int dprc_get_connection(struct fsl_mc_io *mc_io,
1355 const struct dprc_endpoint *endpoint1,
1356 struct dprc_endpoint *endpoint2,
1359 struct mc_command cmd = { 0 };
1360 struct dprc_cmd_get_connection *cmd_params;
1361 struct dprc_rsp_get_connection *rsp_params;
1364 /* prepare command */
1365 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
1368 cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
1369 cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
1370 cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
1371 strncpy(cmd_params->ep1_type, endpoint1->type, 16);
1372 cmd_params->ep1_type[15] = '\0';
1374 /* send command to mc*/
1375 err = mc_send_command(mc_io, &cmd);
1379 /* retrieve response parameters */
1380 rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
1381 endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
1382 endpoint2->if_id = le32_to_cpu(rsp_params->ep2_interface_id);
1383 strncpy(endpoint2->type, rsp_params->ep2_type, 16);
1384 endpoint2->type[15] = '\0';
1385 *state = le32_to_cpu(rsp_params->state);