]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/fsl-mc/bus/dpbp.c
Merge branch 'for-4.8/core' of git://git.kernel.dk/linux-block
[karo-tx-linux.git] / drivers / staging / fsl-mc / bus / dpbp.c
1 /* Copyright 2013-2016 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/dpbp.h"
35 #include "../include/dpbp-cmd.h"
36
37 /**
38  * dpbp_open() - Open a control session for the specified object.
39  * @mc_io:      Pointer to MC portal's I/O object
40  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
41  * @dpbp_id:    DPBP unique ID
42  * @token:      Returned token; use in subsequent API calls
43  *
44  * This function can be used to open a control session for an
45  * already created object; an object may have been declared in
46  * the DPL or by calling the dpbp_create function.
47  * This function returns a unique authentication token,
48  * associated with the specific object ID and the specific MC
49  * portal; this token must be used in all subsequent commands for
50  * this specific object
51  *
52  * Return:      '0' on Success; Error code otherwise.
53  */
54 int dpbp_open(struct fsl_mc_io *mc_io,
55               u32 cmd_flags,
56               int dpbp_id,
57               u16 *token)
58 {
59         struct mc_command cmd = { 0 };
60         struct dpbp_cmd_open *cmd_params;
61         int err;
62
63         /* prepare command */
64         cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
65                                           cmd_flags, 0);
66         cmd_params = (struct dpbp_cmd_open *)cmd.params;
67         cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
68
69         /* send command to mc*/
70         err = mc_send_command(mc_io, &cmd);
71         if (err)
72                 return err;
73
74         /* retrieve response parameters */
75         *token = mc_cmd_hdr_read_token(&cmd);
76
77         return err;
78 }
79 EXPORT_SYMBOL(dpbp_open);
80
81 /**
82  * dpbp_close() - Close the control session of the object
83  * @mc_io:      Pointer to MC portal's I/O object
84  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
85  * @token:      Token of DPBP object
86  *
87  * After this function is called, no further operations are
88  * allowed on the object without opening a new control session.
89  *
90  * Return:      '0' on Success; Error code otherwise.
91  */
92 int dpbp_close(struct fsl_mc_io *mc_io,
93                u32 cmd_flags,
94                u16 token)
95 {
96         struct mc_command cmd = { 0 };
97
98         /* prepare command */
99         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
100                                           token);
101
102         /* send command to mc*/
103         return mc_send_command(mc_io, &cmd);
104 }
105 EXPORT_SYMBOL(dpbp_close);
106
107 /**
108  * dpbp_create() - Create the DPBP object.
109  * @mc_io:      Pointer to MC portal's I/O object
110  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
111  * @cfg:        Configuration structure
112  * @token:      Returned token; use in subsequent API calls
113  *
114  * Create the DPBP object, allocate required resources and
115  * perform required initialization.
116  *
117  * The object can be created either by declaring it in the
118  * DPL file, or by calling this function.
119  * This function returns a unique authentication token,
120  * associated with the specific object ID and the specific MC
121  * portal; this token must be used in all subsequent calls to
122  * this specific object. For objects that are created using the
123  * DPL file, call dpbp_open function to get an authentication
124  * token first.
125  *
126  * Return:      '0' on Success; Error code otherwise.
127  */
128 int dpbp_create(struct fsl_mc_io *mc_io,
129                 u32 cmd_flags,
130                 const struct dpbp_cfg *cfg,
131                 u16 *token)
132 {
133         struct mc_command cmd = { 0 };
134         int err;
135
136         (void)(cfg); /* unused */
137
138         /* prepare command */
139         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
140                                           cmd_flags, 0);
141
142         /* send command to mc*/
143         err = mc_send_command(mc_io, &cmd);
144         if (err)
145                 return err;
146
147         /* retrieve response parameters */
148         *token = mc_cmd_hdr_read_token(&cmd);
149
150         return 0;
151 }
152
153 /**
154  * dpbp_destroy() - Destroy the DPBP object and release all its resources.
155  * @mc_io:      Pointer to MC portal's I/O object
156  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
157  * @token:      Token of DPBP object
158  *
159  * Return:      '0' on Success; error code otherwise.
160  */
161 int dpbp_destroy(struct fsl_mc_io *mc_io,
162                  u32 cmd_flags,
163                  u16 token)
164 {
165         struct mc_command cmd = { 0 };
166
167         /* prepare command */
168         cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
169                                           cmd_flags, token);
170
171         /* send command to mc*/
172         return mc_send_command(mc_io, &cmd);
173 }
174
175 /**
176  * dpbp_enable() - Enable the DPBP.
177  * @mc_io:      Pointer to MC portal's I/O object
178  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
179  * @token:      Token of DPBP object
180  *
181  * Return:      '0' on Success; Error code otherwise.
182  */
183 int dpbp_enable(struct fsl_mc_io *mc_io,
184                 u32 cmd_flags,
185                 u16 token)
186 {
187         struct mc_command cmd = { 0 };
188
189         /* prepare command */
190         cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
191                                           token);
192
193         /* send command to mc*/
194         return mc_send_command(mc_io, &cmd);
195 }
196 EXPORT_SYMBOL(dpbp_enable);
197
198 /**
199  * dpbp_disable() - Disable the DPBP.
200  * @mc_io:      Pointer to MC portal's I/O object
201  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
202  * @token:      Token of DPBP object
203  *
204  * Return:      '0' on Success; Error code otherwise.
205  */
206 int dpbp_disable(struct fsl_mc_io *mc_io,
207                  u32 cmd_flags,
208                  u16 token)
209 {
210         struct mc_command cmd = { 0 };
211
212         /* prepare command */
213         cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
214                                           cmd_flags, token);
215
216         /* send command to mc*/
217         return mc_send_command(mc_io, &cmd);
218 }
219 EXPORT_SYMBOL(dpbp_disable);
220
221 /**
222  * dpbp_is_enabled() - Check if the DPBP is enabled.
223  * @mc_io:      Pointer to MC portal's I/O object
224  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
225  * @token:      Token of DPBP object
226  * @en:         Returns '1' if object is enabled; '0' otherwise
227  *
228  * Return:      '0' on Success; Error code otherwise.
229  */
230 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
231                     u32 cmd_flags,
232                     u16 token,
233                     int *en)
234 {
235         struct mc_command cmd = { 0 };
236         struct dpbp_rsp_is_enabled *rsp_params;
237         int err;
238         /* prepare command */
239         cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
240                                           token);
241
242         /* send command to mc*/
243         err = mc_send_command(mc_io, &cmd);
244         if (err)
245                 return err;
246
247         /* retrieve response parameters */
248         rsp_params = (struct dpbp_rsp_is_enabled *)cmd.params;
249         *en = rsp_params->enabled & DPBP_ENABLE;
250
251         return 0;
252 }
253
254 /**
255  * dpbp_reset() - Reset the DPBP, returns the object to initial state.
256  * @mc_io:      Pointer to MC portal's I/O object
257  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
258  * @token:      Token of DPBP object
259  *
260  * Return:      '0' on Success; Error code otherwise.
261  */
262 int dpbp_reset(struct fsl_mc_io *mc_io,
263                u32 cmd_flags,
264                u16 token)
265 {
266         struct mc_command cmd = { 0 };
267
268         /* prepare command */
269         cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
270                                           cmd_flags, token);
271
272         /* send command to mc*/
273         return mc_send_command(mc_io, &cmd);
274 }
275
276 /**
277  * dpbp_set_irq() - Set IRQ information for the DPBP to trigger an interrupt.
278  * @mc_io:      Pointer to MC portal's I/O object
279  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
280  * @token:      Token of DPBP object
281  * @irq_index:  Identifies the interrupt index to configure
282  * @irq_cfg:    IRQ configuration
283  *
284  * Return:      '0' on Success; Error code otherwise.
285  */
286 int dpbp_set_irq(struct fsl_mc_io *mc_io,
287                  u32 cmd_flags,
288                  u16 token,
289                  u8 irq_index,
290                  struct dpbp_irq_cfg *irq_cfg)
291 {
292         struct mc_command cmd = { 0 };
293         struct dpbp_cmd_set_irq *cmd_params;
294
295         /* prepare command */
296         cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
297                                           cmd_flags, token);
298         cmd_params = (struct dpbp_cmd_set_irq *)cmd.params;
299         cmd_params->irq_index = irq_index;
300         cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
301         cmd_params->irq_addr = cpu_to_le64(irq_cfg->addr);
302         cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
303
304         /* send command to mc*/
305         return mc_send_command(mc_io, &cmd);
306 }
307
308 /**
309  * dpbp_get_irq() - Get IRQ information from the DPBP.
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 DPBP object
313  * @irq_index:  The interrupt index to configure
314  * @type:       Interrupt type: 0 represents message interrupt
315  *              type (both irq_addr and irq_val are valid)
316  * @irq_cfg:    IRQ attributes
317  *
318  * Return:      '0' on Success; Error code otherwise.
319  */
320 int dpbp_get_irq(struct fsl_mc_io *mc_io,
321                  u32 cmd_flags,
322                  u16 token,
323                  u8 irq_index,
324                  int *type,
325                  struct dpbp_irq_cfg *irq_cfg)
326 {
327         struct mc_command cmd = { 0 };
328         struct dpbp_cmd_get_irq *cmd_params;
329         struct dpbp_rsp_get_irq *rsp_params;
330         int err;
331
332         /* prepare command */
333         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
334                                           cmd_flags, token);
335         cmd_params = (struct dpbp_cmd_get_irq *)cmd.params;
336         cmd_params->irq_index = irq_index;
337
338         /* send command to mc*/
339         err = mc_send_command(mc_io, &cmd);
340         if (err)
341                 return err;
342
343         /* retrieve response parameters */
344         rsp_params = (struct dpbp_rsp_get_irq *)cmd.params;
345         irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
346         irq_cfg->addr = le64_to_cpu(rsp_params->irq_addr);
347         irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
348         *type = le32_to_cpu(rsp_params->type);
349
350         return 0;
351 }
352
353 /**
354  * dpbp_set_irq_enable() - Set overall interrupt state.
355  * @mc_io:      Pointer to MC portal's I/O object
356  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
357  * @token:      Token of DPBP object
358  * @irq_index:  The interrupt index to configure
359  * @en: Interrupt state - enable = 1, disable = 0
360  *
361  * Allows GPP software to control when interrupts are generated.
362  * Each interrupt can have up to 32 causes.  The enable/disable control's the
363  * overall interrupt state. if the interrupt is disabled no causes will cause
364  * an interrupt.
365  *
366  * Return:      '0' on Success; Error code otherwise.
367  */
368 int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
369                         u32 cmd_flags,
370                         u16 token,
371                         u8 irq_index,
372                         u8 en)
373 {
374         struct mc_command cmd = { 0 };
375         struct dpbp_cmd_set_irq_enable *cmd_params;
376
377         /* prepare command */
378         cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
379                                           cmd_flags, token);
380         cmd_params = (struct dpbp_cmd_set_irq_enable *)cmd.params;
381         cmd_params->enable = en & DPBP_ENABLE;
382         cmd_params->irq_index = irq_index;
383
384         /* send command to mc*/
385         return mc_send_command(mc_io, &cmd);
386 }
387
388 /**
389  * dpbp_get_irq_enable() - Get overall interrupt state
390  * @mc_io:      Pointer to MC portal's I/O object
391  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
392  * @token:      Token of DPBP object
393  * @irq_index:  The interrupt index to configure
394  * @en:         Returned interrupt state - enable = 1, disable = 0
395  *
396  * Return:      '0' on Success; Error code otherwise.
397  */
398 int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
399                         u32 cmd_flags,
400                         u16 token,
401                         u8 irq_index,
402                         u8 *en)
403 {
404         struct mc_command cmd = { 0 };
405         struct dpbp_cmd_get_irq_enable *cmd_params;
406         struct dpbp_rsp_get_irq_enable *rsp_params;
407         int err;
408
409         /* prepare command */
410         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
411                                           cmd_flags, token);
412         cmd_params = (struct dpbp_cmd_get_irq_enable *)cmd.params;
413         cmd_params->irq_index = irq_index;
414
415         /* send command to mc*/
416         err = mc_send_command(mc_io, &cmd);
417         if (err)
418                 return err;
419
420         /* retrieve response parameters */
421         rsp_params = (struct dpbp_rsp_get_irq_enable *)cmd.params;
422         *en = rsp_params->enabled & DPBP_ENABLE;
423         return 0;
424 }
425
426 /**
427  * dpbp_set_irq_mask() - Set interrupt mask.
428  * @mc_io:      Pointer to MC portal's I/O object
429  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
430  * @token:      Token of DPBP object
431  * @irq_index:  The interrupt index to configure
432  * @mask:       Event mask to trigger interrupt;
433  *                      each bit:
434  *                              0 = ignore event
435  *                              1 = consider event for asserting IRQ
436  *
437  * Every interrupt can have up to 32 causes and the interrupt model supports
438  * masking/unmasking each cause independently
439  *
440  * Return:      '0' on Success; Error code otherwise.
441  */
442 int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
443                       u32 cmd_flags,
444                       u16 token,
445                       u8 irq_index,
446                       u32 mask)
447 {
448         struct mc_command cmd = { 0 };
449         struct dpbp_cmd_set_irq_mask *cmd_params;
450
451         /* prepare command */
452         cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
453                                           cmd_flags, token);
454         cmd_params = (struct dpbp_cmd_set_irq_mask *)cmd.params;
455         cmd_params->mask = cpu_to_le32(mask);
456         cmd_params->irq_index = irq_index;
457
458         /* send command to mc*/
459         return mc_send_command(mc_io, &cmd);
460 }
461
462 /**
463  * dpbp_get_irq_mask() - Get interrupt mask.
464  * @mc_io:      Pointer to MC portal's I/O object
465  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
466  * @token:      Token of DPBP object
467  * @irq_index:  The interrupt index to configure
468  * @mask:       Returned event mask to trigger interrupt
469  *
470  * Every interrupt can have up to 32 causes and the interrupt model supports
471  * masking/unmasking each cause independently
472  *
473  * Return:      '0' on Success; Error code otherwise.
474  */
475 int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
476                       u32 cmd_flags,
477                       u16 token,
478                       u8 irq_index,
479                       u32 *mask)
480 {
481         struct mc_command cmd = { 0 };
482         struct dpbp_cmd_get_irq_mask *cmd_params;
483         struct dpbp_rsp_get_irq_mask *rsp_params;
484         int err;
485
486         /* prepare command */
487         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
488                                           cmd_flags, token);
489         cmd_params = (struct dpbp_cmd_get_irq_mask *)cmd.params;
490         cmd_params->irq_index = irq_index;
491
492         /* send command to mc*/
493         err = mc_send_command(mc_io, &cmd);
494         if (err)
495                 return err;
496
497         /* retrieve response parameters */
498         rsp_params = (struct dpbp_rsp_get_irq_mask *)cmd.params;
499         *mask = le32_to_cpu(rsp_params->mask);
500
501         return 0;
502 }
503
504 /**
505  * dpbp_get_irq_status() - Get the current status of any pending interrupts.
506  *
507  * @mc_io:      Pointer to MC portal's I/O object
508  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
509  * @token:      Token of DPBP object
510  * @irq_index:  The interrupt index to configure
511  * @status:     Returned interrupts status - one bit per cause:
512  *                      0 = no interrupt pending
513  *                      1 = interrupt pending
514  *
515  * Return:      '0' on Success; Error code otherwise.
516  */
517 int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
518                         u32 cmd_flags,
519                         u16 token,
520                         u8 irq_index,
521                         u32 *status)
522 {
523         struct mc_command cmd = { 0 };
524         struct dpbp_cmd_get_irq_status *cmd_params;
525         struct dpbp_rsp_get_irq_status *rsp_params;
526         int err;
527
528         /* prepare command */
529         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
530                                           cmd_flags, token);
531         cmd_params = (struct dpbp_cmd_get_irq_status *)cmd.params;
532         cmd_params->status = cpu_to_le32(*status);
533         cmd_params->irq_index = irq_index;
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         rsp_params = (struct dpbp_rsp_get_irq_status *)cmd.params;
542         *status = le32_to_cpu(rsp_params->status);
543
544         return 0;
545 }
546
547 /**
548  * dpbp_clear_irq_status() - Clear a pending interrupt's status
549  *
550  * @mc_io:      Pointer to MC portal's I/O object
551  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
552  * @token:      Token of DPBP object
553  * @irq_index:  The interrupt index to configure
554  * @status:     Bits to clear (W1C) - one bit per cause:
555  *                                      0 = don't change
556  *                                      1 = clear status bit
557  *
558  * Return:      '0' on Success; Error code otherwise.
559  */
560 int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
561                           u32 cmd_flags,
562                           u16 token,
563                           u8 irq_index,
564                           u32 status)
565 {
566         struct mc_command cmd = { 0 };
567         struct dpbp_cmd_clear_irq_status *cmd_params;
568
569         /* prepare command */
570         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
571                                           cmd_flags, token);
572         cmd_params = (struct dpbp_cmd_clear_irq_status *)cmd.params;
573         cmd_params->status = cpu_to_le32(status);
574         cmd_params->irq_index = irq_index;
575
576         /* send command to mc*/
577         return mc_send_command(mc_io, &cmd);
578 }
579
580 /**
581  * dpbp_get_attributes - Retrieve DPBP attributes.
582  *
583  * @mc_io:      Pointer to MC portal's I/O object
584  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
585  * @token:      Token of DPBP object
586  * @attr:       Returned object's attributes
587  *
588  * Return:      '0' on Success; Error code otherwise.
589  */
590 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
591                         u32 cmd_flags,
592                         u16 token,
593                         struct dpbp_attr *attr)
594 {
595         struct mc_command cmd = { 0 };
596         struct dpbp_rsp_get_attributes *rsp_params;
597         int err;
598
599         /* prepare command */
600         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
601                                           cmd_flags, token);
602
603         /* send command to mc*/
604         err = mc_send_command(mc_io, &cmd);
605         if (err)
606                 return err;
607
608         /* retrieve response parameters */
609         rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
610         attr->bpid = le16_to_cpu(rsp_params->bpid);
611         attr->id = le32_to_cpu(rsp_params->id);
612         attr->version.major = le16_to_cpu(rsp_params->version_major);
613         attr->version.minor = le16_to_cpu(rsp_params->version_minor);
614
615         return 0;
616 }
617 EXPORT_SYMBOL(dpbp_get_attributes);
618
619 /**
620  * dpbp_set_notifications() - Set notifications towards software
621  * @mc_io:      Pointer to MC portal's I/O object
622  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
623  * @token:      Token of DPBP object
624  * @cfg:        notifications configuration
625  *
626  * Return:      '0' on Success; Error code otherwise.
627  */
628 int dpbp_set_notifications(struct fsl_mc_io *mc_io,
629                            u32 cmd_flags,
630                            u16 token,
631                            struct dpbp_notification_cfg *cfg)
632 {
633         struct mc_command cmd = { 0 };
634         struct dpbp_cmd_set_notifications *cmd_params;
635
636         /* prepare command */
637         cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_NOTIFICATIONS,
638                                           cmd_flags, token);
639         cmd_params = (struct dpbp_cmd_set_notifications *)cmd.params;
640         cmd_params->depletion_entry = cpu_to_le32(cfg->depletion_entry);
641         cmd_params->depletion_exit = cpu_to_le32(cfg->depletion_exit);
642         cmd_params->surplus_entry = cpu_to_le32(cfg->surplus_entry);
643         cmd_params->surplus_exit = cpu_to_le32(cfg->surplus_exit);
644         cmd_params->options = cpu_to_le16(cfg->options);
645         cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
646         cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
647
648         /* send command to mc*/
649         return mc_send_command(mc_io, &cmd);
650 }
651
652 /**
653  * dpbp_get_notifications() - Get the notifications configuration
654  * @mc_io:      Pointer to MC portal's I/O object
655  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
656  * @token:      Token of DPBP object
657  * @cfg:        notifications configuration
658  *
659  * Return:      '0' on Success; Error code otherwise.
660  */
661 int dpbp_get_notifications(struct fsl_mc_io *mc_io,
662                            u32 cmd_flags,
663                            u16 token,
664                            struct dpbp_notification_cfg *cfg)
665 {
666         struct mc_command cmd = { 0 };
667         struct dpbp_rsp_get_notifications *rsp_params;
668         int err;
669
670         /* prepare command */
671         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_NOTIFICATIONS,
672                                           cmd_flags,
673                                           token);
674
675         /* send command to mc*/
676         err = mc_send_command(mc_io, &cmd);
677         if (err)
678                 return err;
679
680         /* retrieve response parameters */
681         rsp_params = (struct dpbp_rsp_get_notifications *)cmd.params;
682         cfg->depletion_entry = le32_to_cpu(rsp_params->depletion_entry);
683         cfg->depletion_exit = le32_to_cpu(rsp_params->depletion_exit);
684         cfg->surplus_entry = le32_to_cpu(rsp_params->surplus_entry);
685         cfg->surplus_exit = le32_to_cpu(rsp_params->surplus_exit);
686         cfg->options = le16_to_cpu(rsp_params->options);
687         cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
688         cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
689
690         return 0;
691 }