xref: /openbmc/linux/drivers/bus/fsl-mc/dpcon.c (revision 6d99a79c)
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /*
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  *
5  */
6 #include <linux/kernel.h>
7 #include <linux/fsl/mc.h>
8 #include <linux/fsl/mc.h>
9 
10 #include "fsl-mc-private.h"
11 
12 /**
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
18  *
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.
26  *
27  * Return:	'0' on Success; Error code otherwise.
28  */
29 int dpcon_open(struct fsl_mc_io *mc_io,
30 	       u32 cmd_flags,
31 	       int dpcon_id,
32 	       u16 *token)
33 {
34 	struct fsl_mc_command cmd = { 0 };
35 	struct dpcon_cmd_open *dpcon_cmd;
36 	int err;
37 
38 	/* prepare command */
39 	cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
40 					  cmd_flags,
41 					  0);
42 	dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
43 	dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
44 
45 	/* send command to mc*/
46 	err = mc_send_command(mc_io, &cmd);
47 	if (err)
48 		return err;
49 
50 	/* retrieve response parameters */
51 	*token = mc_cmd_hdr_read_token(&cmd);
52 
53 	return 0;
54 }
55 EXPORT_SYMBOL_GPL(dpcon_open);
56 
57 /**
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
62  *
63  * After this function is called, no further operations are
64  * allowed on the object without opening a new control session.
65  *
66  * Return:	'0' on Success; Error code otherwise.
67  */
68 int dpcon_close(struct fsl_mc_io *mc_io,
69 		u32 cmd_flags,
70 		u16 token)
71 {
72 	struct fsl_mc_command cmd = { 0 };
73 
74 	/* prepare command */
75 	cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
76 					  cmd_flags,
77 					  token);
78 
79 	/* send command to mc*/
80 	return mc_send_command(mc_io, &cmd);
81 }
82 EXPORT_SYMBOL_GPL(dpcon_close);
83 
84 /**
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
89  *
90  * Return:	'0' on Success; Error code otherwise
91  */
92 int dpcon_enable(struct fsl_mc_io *mc_io,
93 		 u32 cmd_flags,
94 		 u16 token)
95 {
96 	struct fsl_mc_command cmd = { 0 };
97 
98 	/* prepare command */
99 	cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
100 					  cmd_flags,
101 					  token);
102 
103 	/* send command to mc*/
104 	return mc_send_command(mc_io, &cmd);
105 }
106 EXPORT_SYMBOL_GPL(dpcon_enable);
107 
108 /**
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
113  *
114  * Return:	'0' on Success; Error code otherwise
115  */
116 int dpcon_disable(struct fsl_mc_io *mc_io,
117 		  u32 cmd_flags,
118 		  u16 token)
119 {
120 	struct fsl_mc_command cmd = { 0 };
121 
122 	/* prepare command */
123 	cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
124 					  cmd_flags,
125 					  token);
126 
127 	/* send command to mc*/
128 	return mc_send_command(mc_io, &cmd);
129 }
130 EXPORT_SYMBOL_GPL(dpcon_disable);
131 
132 /**
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
137  *
138  * Return:	'0' on Success; Error code otherwise.
139  */
140 int dpcon_reset(struct fsl_mc_io *mc_io,
141 		u32 cmd_flags,
142 		u16 token)
143 {
144 	struct fsl_mc_command cmd = { 0 };
145 
146 	/* prepare command */
147 	cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
148 					  cmd_flags, token);
149 
150 	/* send command to mc*/
151 	return mc_send_command(mc_io, &cmd);
152 }
153 EXPORT_SYMBOL_GPL(dpcon_reset);
154 
155 /**
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
161  *
162  * Return:	'0' on Success; Error code otherwise.
163  */
164 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
165 			 u32 cmd_flags,
166 			 u16 token,
167 			 struct dpcon_attr *attr)
168 {
169 	struct fsl_mc_command cmd = { 0 };
170 	struct dpcon_rsp_get_attr *dpcon_rsp;
171 	int err;
172 
173 	/* prepare command */
174 	cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
175 					  cmd_flags,
176 					  token);
177 
178 	/* send command to mc*/
179 	err = mc_send_command(mc_io, &cmd);
180 	if (err)
181 		return err;
182 
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;
188 
189 	return 0;
190 }
191 EXPORT_SYMBOL_GPL(dpcon_get_attributes);
192 
193 /**
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
199  *
200  * Return:	'0' on Success; Error code otherwise
201  */
202 int dpcon_set_notification(struct fsl_mc_io *mc_io,
203 			   u32 cmd_flags,
204 			   u16 token,
205 			   struct dpcon_notification_cfg *cfg)
206 {
207 	struct fsl_mc_command cmd = { 0 };
208 	struct dpcon_cmd_set_notification *dpcon_cmd;
209 
210 	/* prepare command */
211 	cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
212 					  cmd_flags,
213 					  token);
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);
218 
219 	/* send command to mc*/
220 	return mc_send_command(mc_io, &cmd);
221 }
222 EXPORT_SYMBOL_GPL(dpcon_set_notification);
223