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