1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of the above-listed copyright holders nor the
11 * names of any contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
32 #include "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
34 #include "../include/dpbp.h"
35 #include "../include/dpbp-cmd.h"
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
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
52 * Return: '0' on Success; Error code otherwise.
54 int dpbp_open(struct fsl_mc_io *mc_io,
59 struct mc_command cmd = { 0 };
60 struct dpbp_cmd_open *cmd_params;
64 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
66 cmd_params = (struct dpbp_cmd_open *)cmd.params;
67 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
69 /* send command to mc*/
70 err = mc_send_command(mc_io, &cmd);
74 /* retrieve response parameters */
75 *token = mc_cmd_hdr_read_token(&cmd);
79 EXPORT_SYMBOL(dpbp_open);
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
87 * After this function is called, no further operations are
88 * allowed on the object without opening a new control session.
90 * Return: '0' on Success; Error code otherwise.
92 int dpbp_close(struct fsl_mc_io *mc_io,
96 struct mc_command cmd = { 0 };
99 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
102 /* send command to mc*/
103 return mc_send_command(mc_io, &cmd);
105 EXPORT_SYMBOL(dpbp_close);
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
114 * Create the DPBP object, allocate required resources and
115 * perform required initialization.
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
126 * Return: '0' on Success; Error code otherwise.
128 int dpbp_create(struct fsl_mc_io *mc_io,
130 const struct dpbp_cfg *cfg,
133 struct mc_command cmd = { 0 };
136 (void)(cfg); /* unused */
138 /* prepare command */
139 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
142 /* send command to mc*/
143 err = mc_send_command(mc_io, &cmd);
147 /* retrieve response parameters */
148 *token = mc_cmd_hdr_read_token(&cmd);
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
159 * Return: '0' on Success; error code otherwise.
161 int dpbp_destroy(struct fsl_mc_io *mc_io,
165 struct mc_command cmd = { 0 };
167 /* prepare command */
168 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
171 /* send command to mc*/
172 return mc_send_command(mc_io, &cmd);
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
181 * Return: '0' on Success; Error code otherwise.
183 int dpbp_enable(struct fsl_mc_io *mc_io,
187 struct mc_command cmd = { 0 };
189 /* prepare command */
190 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
193 /* send command to mc*/
194 return mc_send_command(mc_io, &cmd);
196 EXPORT_SYMBOL(dpbp_enable);
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
204 * Return: '0' on Success; Error code otherwise.
206 int dpbp_disable(struct fsl_mc_io *mc_io,
210 struct mc_command cmd = { 0 };
212 /* prepare command */
213 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
216 /* send command to mc*/
217 return mc_send_command(mc_io, &cmd);
219 EXPORT_SYMBOL(dpbp_disable);
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
228 * Return: '0' on Success; Error code otherwise.
230 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
235 struct mc_command cmd = { 0 };
236 struct dpbp_rsp_is_enabled *rsp_params;
238 /* prepare command */
239 cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
242 /* send command to mc*/
243 err = mc_send_command(mc_io, &cmd);
247 /* retrieve response parameters */
248 rsp_params = (struct dpbp_rsp_is_enabled *)cmd.params;
249 *en = rsp_params->enabled & DPBP_ENABLE;
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
260 * Return: '0' on Success; Error code otherwise.
262 int dpbp_reset(struct fsl_mc_io *mc_io,
266 struct mc_command cmd = { 0 };
268 /* prepare command */
269 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
272 /* send command to mc*/
273 return mc_send_command(mc_io, &cmd);
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
284 * Return: '0' on Success; Error code otherwise.
286 int dpbp_set_irq(struct fsl_mc_io *mc_io,
290 struct dpbp_irq_cfg *irq_cfg)
292 struct mc_command cmd = { 0 };
293 struct dpbp_cmd_set_irq *cmd_params;
295 /* prepare command */
296 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
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);
304 /* send command to mc*/
305 return mc_send_command(mc_io, &cmd);
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
318 * Return: '0' on Success; Error code otherwise.
320 int dpbp_get_irq(struct fsl_mc_io *mc_io,
325 struct dpbp_irq_cfg *irq_cfg)
327 struct mc_command cmd = { 0 };
328 struct dpbp_cmd_get_irq *cmd_params;
329 struct dpbp_rsp_get_irq *rsp_params;
332 /* prepare command */
333 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
335 cmd_params = (struct dpbp_cmd_get_irq *)cmd.params;
336 cmd_params->irq_index = irq_index;
338 /* send command to mc*/
339 err = mc_send_command(mc_io, &cmd);
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);
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
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
366 * Return: '0' on Success; Error code otherwise.
368 int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
374 struct mc_command cmd = { 0 };
375 struct dpbp_cmd_set_irq_enable *cmd_params;
377 /* prepare command */
378 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
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;
384 /* send command to mc*/
385 return mc_send_command(mc_io, &cmd);
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
396 * Return: '0' on Success; Error code otherwise.
398 int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
404 struct mc_command cmd = { 0 };
405 struct dpbp_cmd_get_irq_enable *cmd_params;
406 struct dpbp_rsp_get_irq_enable *rsp_params;
409 /* prepare command */
410 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
412 cmd_params = (struct dpbp_cmd_get_irq_enable *)cmd.params;
413 cmd_params->irq_index = irq_index;
415 /* send command to mc*/
416 err = mc_send_command(mc_io, &cmd);
420 /* retrieve response parameters */
421 rsp_params = (struct dpbp_rsp_get_irq_enable *)cmd.params;
422 *en = rsp_params->enabled & DPBP_ENABLE;
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;
435 * 1 = consider event for asserting IRQ
437 * Every interrupt can have up to 32 causes and the interrupt model supports
438 * masking/unmasking each cause independently
440 * Return: '0' on Success; Error code otherwise.
442 int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
448 struct mc_command cmd = { 0 };
449 struct dpbp_cmd_set_irq_mask *cmd_params;
451 /* prepare command */
452 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
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;
458 /* send command to mc*/
459 return mc_send_command(mc_io, &cmd);
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
470 * Every interrupt can have up to 32 causes and the interrupt model supports
471 * masking/unmasking each cause independently
473 * Return: '0' on Success; Error code otherwise.
475 int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
481 struct mc_command cmd = { 0 };
482 struct dpbp_cmd_get_irq_mask *cmd_params;
483 struct dpbp_rsp_get_irq_mask *rsp_params;
486 /* prepare command */
487 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
489 cmd_params = (struct dpbp_cmd_get_irq_mask *)cmd.params;
490 cmd_params->irq_index = irq_index;
492 /* send command to mc*/
493 err = mc_send_command(mc_io, &cmd);
497 /* retrieve response parameters */
498 rsp_params = (struct dpbp_rsp_get_irq_mask *)cmd.params;
499 *mask = le32_to_cpu(rsp_params->mask);
505 * dpbp_get_irq_status() - Get the current status of any pending interrupts.
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
515 * Return: '0' on Success; Error code otherwise.
517 int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
523 struct mc_command cmd = { 0 };
524 struct dpbp_cmd_get_irq_status *cmd_params;
525 struct dpbp_rsp_get_irq_status *rsp_params;
528 /* prepare command */
529 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
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;
535 /* send command to mc*/
536 err = mc_send_command(mc_io, &cmd);
540 /* retrieve response parameters */
541 rsp_params = (struct dpbp_rsp_get_irq_status *)cmd.params;
542 *status = le32_to_cpu(rsp_params->status);
548 * dpbp_clear_irq_status() - Clear a pending interrupt's status
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:
556 * 1 = clear status bit
558 * Return: '0' on Success; Error code otherwise.
560 int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
566 struct mc_command cmd = { 0 };
567 struct dpbp_cmd_clear_irq_status *cmd_params;
569 /* prepare command */
570 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
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;
576 /* send command to mc*/
577 return mc_send_command(mc_io, &cmd);
581 * dpbp_get_attributes - Retrieve DPBP attributes.
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
588 * Return: '0' on Success; Error code otherwise.
590 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
593 struct dpbp_attr *attr)
595 struct mc_command cmd = { 0 };
596 struct dpbp_rsp_get_attributes *rsp_params;
599 /* prepare command */
600 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
603 /* send command to mc*/
604 err = mc_send_command(mc_io, &cmd);
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);
617 EXPORT_SYMBOL(dpbp_get_attributes);
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
626 * Return: '0' on Success; Error code otherwise.
628 int dpbp_set_notifications(struct fsl_mc_io *mc_io,
631 struct dpbp_notification_cfg *cfg)
633 struct mc_command cmd = { 0 };
634 struct dpbp_cmd_set_notifications *cmd_params;
636 /* prepare command */
637 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_NOTIFICATIONS,
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);
648 /* send command to mc*/
649 return mc_send_command(mc_io, &cmd);
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
659 * Return: '0' on Success; Error code otherwise.
661 int dpbp_get_notifications(struct fsl_mc_io *mc_io,
664 struct dpbp_notification_cfg *cfg)
666 struct mc_command cmd = { 0 };
667 struct dpbp_rsp_get_notifications *rsp_params;
670 /* prepare command */
671 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_NOTIFICATIONS,
675 /* send command to mc*/
676 err = mc_send_command(mc_io, &cmd);
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);