1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
6 #include <linux/kernel.h>
7 #include <linux/fsl/mc.h>
8 #include <linux/fsl/mc.h>
10 #include "fsl-mc-private.h"
13 * dpbp_open() - Open a control session for the specified object.
14 * @mc_io: Pointer to MC portal's I/O object
15 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
16 * @dpbp_id: DPBP unique ID
17 * @token: Returned token; use in subsequent API calls
19 * This function can be used to open a control session for an
20 * already created object; an object may have been declared in
21 * the DPL or by calling the dpbp_create function.
22 * This function returns a unique authentication token,
23 * associated with the specific object ID and the specific MC
24 * portal; this token must be used in all subsequent commands for
25 * this specific object
27 * Return: '0' on Success; Error code otherwise.
29 int dpbp_open(struct fsl_mc_io
*mc_io
,
34 struct fsl_mc_command cmd
= { 0 };
35 struct dpbp_cmd_open
*cmd_params
;
39 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_OPEN
,
41 cmd_params
= (struct dpbp_cmd_open
*)cmd
.params
;
42 cmd_params
->dpbp_id
= cpu_to_le32(dpbp_id
);
44 /* send command to mc*/
45 err
= mc_send_command(mc_io
, &cmd
);
49 /* retrieve response parameters */
50 *token
= mc_cmd_hdr_read_token(&cmd
);
54 EXPORT_SYMBOL_GPL(dpbp_open
);
57 * dpbp_close() - Close the control session of the object
58 * @mc_io: Pointer to MC portal's I/O object
59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
60 * @token: Token of DPBP object
62 * After this function is called, no further operations are
63 * allowed on the object without opening a new control session.
65 * Return: '0' on Success; Error code otherwise.
67 int dpbp_close(struct fsl_mc_io
*mc_io
,
71 struct fsl_mc_command cmd
= { 0 };
74 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_CLOSE
, cmd_flags
,
77 /* send command to mc*/
78 return mc_send_command(mc_io
, &cmd
);
80 EXPORT_SYMBOL_GPL(dpbp_close
);
83 * dpbp_enable() - Enable the DPBP.
84 * @mc_io: Pointer to MC portal's I/O object
85 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
86 * @token: Token of DPBP object
88 * Return: '0' on Success; Error code otherwise.
90 int dpbp_enable(struct fsl_mc_io
*mc_io
,
94 struct fsl_mc_command cmd
= { 0 };
97 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_ENABLE
, cmd_flags
,
100 /* send command to mc*/
101 return mc_send_command(mc_io
, &cmd
);
103 EXPORT_SYMBOL_GPL(dpbp_enable
);
106 * dpbp_disable() - Disable the DPBP.
107 * @mc_io: Pointer to MC portal's I/O object
108 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
109 * @token: Token of DPBP object
111 * Return: '0' on Success; Error code otherwise.
113 int dpbp_disable(struct fsl_mc_io
*mc_io
,
117 struct fsl_mc_command cmd
= { 0 };
119 /* prepare command */
120 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_DISABLE
,
123 /* send command to mc*/
124 return mc_send_command(mc_io
, &cmd
);
126 EXPORT_SYMBOL_GPL(dpbp_disable
);
129 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
130 * @mc_io: Pointer to MC portal's I/O object
131 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
132 * @token: Token of DPBP object
134 * Return: '0' on Success; Error code otherwise.
136 int dpbp_reset(struct fsl_mc_io
*mc_io
,
140 struct fsl_mc_command cmd
= { 0 };
142 /* prepare command */
143 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_RESET
,
146 /* send command to mc*/
147 return mc_send_command(mc_io
, &cmd
);
149 EXPORT_SYMBOL_GPL(dpbp_reset
);
152 * dpbp_get_attributes - Retrieve DPBP attributes.
154 * @mc_io: Pointer to MC portal's I/O object
155 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
156 * @token: Token of DPBP object
157 * @attr: Returned object's attributes
159 * Return: '0' on Success; Error code otherwise.
161 int dpbp_get_attributes(struct fsl_mc_io
*mc_io
,
164 struct dpbp_attr
*attr
)
166 struct fsl_mc_command cmd
= { 0 };
167 struct dpbp_rsp_get_attributes
*rsp_params
;
170 /* prepare command */
171 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_GET_ATTR
,
174 /* send command to mc*/
175 err
= mc_send_command(mc_io
, &cmd
);
179 /* retrieve response parameters */
180 rsp_params
= (struct dpbp_rsp_get_attributes
*)cmd
.params
;
181 attr
->bpid
= le16_to_cpu(rsp_params
->bpid
);
182 attr
->id
= le32_to_cpu(rsp_params
->id
);
186 EXPORT_SYMBOL_GPL(dpbp_get_attributes
);