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