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>
9 #include "fsl-mc-private.h"
12 * dpbp_open() - Open a control session for the specified object.
13 * @mc_io: Pointer to MC portal's I/O object
14 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
15 * @dpbp_id: DPBP unique ID
16 * @token: Returned token; use in subsequent API calls
18 * This function can be used to open a control session for an
19 * already created object; an object may have been declared in
20 * the DPL or by calling the dpbp_create function.
21 * This function returns a unique authentication token,
22 * associated with the specific object ID and the specific MC
23 * portal; this token must be used in all subsequent commands for
24 * this specific object
26 * Return: '0' on Success; Error code otherwise.
28 int dpbp_open(struct fsl_mc_io
*mc_io
,
33 struct fsl_mc_command cmd
= { 0 };
34 struct dpbp_cmd_open
*cmd_params
;
38 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_OPEN
,
40 cmd_params
= (struct dpbp_cmd_open
*)cmd
.params
;
41 cmd_params
->dpbp_id
= cpu_to_le32(dpbp_id
);
43 /* send command to mc*/
44 err
= mc_send_command(mc_io
, &cmd
);
48 /* retrieve response parameters */
49 *token
= mc_cmd_hdr_read_token(&cmd
);
53 EXPORT_SYMBOL_GPL(dpbp_open
);
56 * dpbp_close() - Close the control session of the object
57 * @mc_io: Pointer to MC portal's I/O object
58 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
59 * @token: Token of DPBP object
61 * After this function is called, no further operations are
62 * allowed on the object without opening a new control session.
64 * Return: '0' on Success; Error code otherwise.
66 int dpbp_close(struct fsl_mc_io
*mc_io
,
70 struct fsl_mc_command cmd
= { 0 };
73 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_CLOSE
, cmd_flags
,
76 /* send command to mc*/
77 return mc_send_command(mc_io
, &cmd
);
79 EXPORT_SYMBOL_GPL(dpbp_close
);
82 * dpbp_enable() - Enable the DPBP.
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 * Return: '0' on Success; Error code otherwise.
89 int dpbp_enable(struct fsl_mc_io
*mc_io
,
93 struct fsl_mc_command cmd
= { 0 };
96 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_ENABLE
, cmd_flags
,
99 /* send command to mc*/
100 return mc_send_command(mc_io
, &cmd
);
102 EXPORT_SYMBOL_GPL(dpbp_enable
);
105 * dpbp_disable() - Disable the DPBP.
106 * @mc_io: Pointer to MC portal's I/O object
107 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
108 * @token: Token of DPBP object
110 * Return: '0' on Success; Error code otherwise.
112 int dpbp_disable(struct fsl_mc_io
*mc_io
,
116 struct fsl_mc_command cmd
= { 0 };
118 /* prepare command */
119 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_DISABLE
,
122 /* send command to mc*/
123 return mc_send_command(mc_io
, &cmd
);
125 EXPORT_SYMBOL_GPL(dpbp_disable
);
128 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
129 * @mc_io: Pointer to MC portal's I/O object
130 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
131 * @token: Token of DPBP object
133 * Return: '0' on Success; Error code otherwise.
135 int dpbp_reset(struct fsl_mc_io
*mc_io
,
139 struct fsl_mc_command cmd
= { 0 };
141 /* prepare command */
142 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_RESET
,
145 /* send command to mc*/
146 return mc_send_command(mc_io
, &cmd
);
148 EXPORT_SYMBOL_GPL(dpbp_reset
);
151 * dpbp_get_attributes - Retrieve DPBP attributes.
153 * @mc_io: Pointer to MC portal's I/O object
154 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
155 * @token: Token of DPBP object
156 * @attr: Returned object's attributes
158 * Return: '0' on Success; Error code otherwise.
160 int dpbp_get_attributes(struct fsl_mc_io
*mc_io
,
163 struct dpbp_attr
*attr
)
165 struct fsl_mc_command cmd
= { 0 };
166 struct dpbp_rsp_get_attributes
*rsp_params
;
169 /* prepare command */
170 cmd
.header
= mc_encode_cmd_header(DPBP_CMDID_GET_ATTR
,
173 /* send command to mc*/
174 err
= mc_send_command(mc_io
, &cmd
);
178 /* retrieve response parameters */
179 rsp_params
= (struct dpbp_rsp_get_attributes
*)cmd
.params
;
180 attr
->bpid
= le16_to_cpu(rsp_params
->bpid
);
181 attr
->id
= le32_to_cpu(rsp_params
->id
);
185 EXPORT_SYMBOL_GPL(dpbp_get_attributes
);