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 * dpcon_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 * @dpcon_id: DPCON 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 dpcon_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 dpcon_open(struct fsl_mc_io
*mc_io
,
33 struct fsl_mc_command cmd
= { 0 };
34 struct dpcon_cmd_open
*dpcon_cmd
;
38 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_OPEN
,
41 dpcon_cmd
= (struct dpcon_cmd_open
*)cmd
.params
;
42 dpcon_cmd
->dpcon_id
= cpu_to_le32(dpcon_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(dpcon_open
);
57 * dpcon_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 DPCON 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 dpcon_close(struct fsl_mc_io
*mc_io
,
71 struct fsl_mc_command cmd
= { 0 };
74 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_CLOSE
,
78 /* send command to mc*/
79 return mc_send_command(mc_io
, &cmd
);
81 EXPORT_SYMBOL_GPL(dpcon_close
);
84 * dpcon_enable() - Enable the DPCON
85 * @mc_io: Pointer to MC portal's I/O object
86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
87 * @token: Token of DPCON object
89 * Return: '0' on Success; Error code otherwise
91 int dpcon_enable(struct fsl_mc_io
*mc_io
,
95 struct fsl_mc_command cmd
= { 0 };
98 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_ENABLE
,
102 /* send command to mc*/
103 return mc_send_command(mc_io
, &cmd
);
105 EXPORT_SYMBOL_GPL(dpcon_enable
);
108 * dpcon_disable() - Disable the DPCON
109 * @mc_io: Pointer to MC portal's I/O object
110 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
111 * @token: Token of DPCON object
113 * Return: '0' on Success; Error code otherwise
115 int dpcon_disable(struct fsl_mc_io
*mc_io
,
119 struct fsl_mc_command cmd
= { 0 };
121 /* prepare command */
122 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_DISABLE
,
126 /* send command to mc*/
127 return mc_send_command(mc_io
, &cmd
);
129 EXPORT_SYMBOL_GPL(dpcon_disable
);
132 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
133 * @mc_io: Pointer to MC portal's I/O object
134 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
135 * @token: Token of DPCON object
137 * Return: '0' on Success; Error code otherwise.
139 int dpcon_reset(struct fsl_mc_io
*mc_io
,
143 struct fsl_mc_command cmd
= { 0 };
145 /* prepare command */
146 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_RESET
,
149 /* send command to mc*/
150 return mc_send_command(mc_io
, &cmd
);
152 EXPORT_SYMBOL_GPL(dpcon_reset
);
155 * dpcon_get_attributes() - Retrieve DPCON attributes.
156 * @mc_io: Pointer to MC portal's I/O object
157 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
158 * @token: Token of DPCON object
159 * @attr: Object's attributes
161 * Return: '0' on Success; Error code otherwise.
163 int dpcon_get_attributes(struct fsl_mc_io
*mc_io
,
166 struct dpcon_attr
*attr
)
168 struct fsl_mc_command cmd
= { 0 };
169 struct dpcon_rsp_get_attr
*dpcon_rsp
;
172 /* prepare command */
173 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_GET_ATTR
,
177 /* send command to mc*/
178 err
= mc_send_command(mc_io
, &cmd
);
182 /* retrieve response parameters */
183 dpcon_rsp
= (struct dpcon_rsp_get_attr
*)cmd
.params
;
184 attr
->id
= le32_to_cpu(dpcon_rsp
->id
);
185 attr
->qbman_ch_id
= le16_to_cpu(dpcon_rsp
->qbman_ch_id
);
186 attr
->num_priorities
= dpcon_rsp
->num_priorities
;
190 EXPORT_SYMBOL_GPL(dpcon_get_attributes
);
193 * dpcon_set_notification() - Set DPCON notification destination
194 * @mc_io: Pointer to MC portal's I/O object
195 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
196 * @token: Token of DPCON object
197 * @cfg: Notification parameters
199 * Return: '0' on Success; Error code otherwise
201 int dpcon_set_notification(struct fsl_mc_io
*mc_io
,
204 struct dpcon_notification_cfg
*cfg
)
206 struct fsl_mc_command cmd
= { 0 };
207 struct dpcon_cmd_set_notification
*dpcon_cmd
;
209 /* prepare command */
210 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION
,
213 dpcon_cmd
= (struct dpcon_cmd_set_notification
*)cmd
.params
;
214 dpcon_cmd
->dpio_id
= cpu_to_le32(cfg
->dpio_id
);
215 dpcon_cmd
->priority
= cfg
->priority
;
216 dpcon_cmd
->user_ctx
= cpu_to_le64(cfg
->user_ctx
);
218 /* send command to mc*/
219 return mc_send_command(mc_io
, &cmd
);
221 EXPORT_SYMBOL_GPL(dpcon_set_notification
);