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 * dpcon_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 * @dpcon_id: DPCON 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 dpcon_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 dpcon_open(struct fsl_mc_io
*mc_io
,
34 struct fsl_mc_command cmd
= { 0 };
35 struct dpcon_cmd_open
*dpcon_cmd
;
39 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_OPEN
,
42 dpcon_cmd
= (struct dpcon_cmd_open
*)cmd
.params
;
43 dpcon_cmd
->dpcon_id
= cpu_to_le32(dpcon_id
);
45 /* send command to mc*/
46 err
= mc_send_command(mc_io
, &cmd
);
50 /* retrieve response parameters */
51 *token
= mc_cmd_hdr_read_token(&cmd
);
55 EXPORT_SYMBOL_GPL(dpcon_open
);
58 * dpcon_close() - Close the control session of the object
59 * @mc_io: Pointer to MC portal's I/O object
60 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
61 * @token: Token of DPCON object
63 * After this function is called, no further operations are
64 * allowed on the object without opening a new control session.
66 * Return: '0' on Success; Error code otherwise.
68 int dpcon_close(struct fsl_mc_io
*mc_io
,
72 struct fsl_mc_command cmd
= { 0 };
75 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_CLOSE
,
79 /* send command to mc*/
80 return mc_send_command(mc_io
, &cmd
);
82 EXPORT_SYMBOL_GPL(dpcon_close
);
85 * dpcon_enable() - Enable the DPCON
86 * @mc_io: Pointer to MC portal's I/O object
87 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
88 * @token: Token of DPCON object
90 * Return: '0' on Success; Error code otherwise
92 int dpcon_enable(struct fsl_mc_io
*mc_io
,
96 struct fsl_mc_command cmd
= { 0 };
99 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_ENABLE
,
103 /* send command to mc*/
104 return mc_send_command(mc_io
, &cmd
);
106 EXPORT_SYMBOL_GPL(dpcon_enable
);
109 * dpcon_disable() - Disable the DPCON
110 * @mc_io: Pointer to MC portal's I/O object
111 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
112 * @token: Token of DPCON object
114 * Return: '0' on Success; Error code otherwise
116 int dpcon_disable(struct fsl_mc_io
*mc_io
,
120 struct fsl_mc_command cmd
= { 0 };
122 /* prepare command */
123 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_DISABLE
,
127 /* send command to mc*/
128 return mc_send_command(mc_io
, &cmd
);
130 EXPORT_SYMBOL_GPL(dpcon_disable
);
133 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
134 * @mc_io: Pointer to MC portal's I/O object
135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
136 * @token: Token of DPCON object
138 * Return: '0' on Success; Error code otherwise.
140 int dpcon_reset(struct fsl_mc_io
*mc_io
,
144 struct fsl_mc_command cmd
= { 0 };
146 /* prepare command */
147 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_RESET
,
150 /* send command to mc*/
151 return mc_send_command(mc_io
, &cmd
);
153 EXPORT_SYMBOL_GPL(dpcon_reset
);
156 * dpcon_get_attributes() - Retrieve DPCON attributes.
157 * @mc_io: Pointer to MC portal's I/O object
158 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
159 * @token: Token of DPCON object
160 * @attr: Object's attributes
162 * Return: '0' on Success; Error code otherwise.
164 int dpcon_get_attributes(struct fsl_mc_io
*mc_io
,
167 struct dpcon_attr
*attr
)
169 struct fsl_mc_command cmd
= { 0 };
170 struct dpcon_rsp_get_attr
*dpcon_rsp
;
173 /* prepare command */
174 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_GET_ATTR
,
178 /* send command to mc*/
179 err
= mc_send_command(mc_io
, &cmd
);
183 /* retrieve response parameters */
184 dpcon_rsp
= (struct dpcon_rsp_get_attr
*)cmd
.params
;
185 attr
->id
= le32_to_cpu(dpcon_rsp
->id
);
186 attr
->qbman_ch_id
= le16_to_cpu(dpcon_rsp
->qbman_ch_id
);
187 attr
->num_priorities
= dpcon_rsp
->num_priorities
;
191 EXPORT_SYMBOL_GPL(dpcon_get_attributes
);
194 * dpcon_set_notification() - Set DPCON notification destination
195 * @mc_io: Pointer to MC portal's I/O object
196 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
197 * @token: Token of DPCON object
198 * @cfg: Notification parameters
200 * Return: '0' on Success; Error code otherwise
202 int dpcon_set_notification(struct fsl_mc_io
*mc_io
,
205 struct dpcon_notification_cfg
*cfg
)
207 struct fsl_mc_command cmd
= { 0 };
208 struct dpcon_cmd_set_notification
*dpcon_cmd
;
210 /* prepare command */
211 cmd
.header
= mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION
,
214 dpcon_cmd
= (struct dpcon_cmd_set_notification
*)cmd
.params
;
215 dpcon_cmd
->dpio_id
= cpu_to_le32(cfg
->dpio_id
);
216 dpcon_cmd
->priority
= cfg
->priority
;
217 dpcon_cmd
->user_ctx
= cpu_to_le64(cfg
->user_ctx
);
219 /* send command to mc*/
220 return mc_send_command(mc_io
, &cmd
);
222 EXPORT_SYMBOL_GPL(dpcon_set_notification
);