interconnect: qcom: Fix Kconfig indentation
[linux/fpc-iii.git] / drivers / dma / fsl-dpaa2-qdma / dpdmai.c
blobf8d22115154a1887f4bc787bd1bfc2bfe1381d68
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright 2019 NXP
4 #include <linux/module.h>
5 #include <linux/types.h>
6 #include <linux/io.h>
7 #include <linux/fsl/mc.h>
8 #include "dpdmai.h"
10 struct dpdmai_rsp_get_attributes {
11 __le32 id;
12 u8 num_of_priorities;
13 u8 pad0[3];
14 __le16 major;
15 __le16 minor;
18 struct dpdmai_cmd_queue {
19 __le32 dest_id;
20 u8 priority;
21 u8 queue;
22 u8 dest_type;
23 u8 pad;
24 __le64 user_ctx;
25 union {
26 __le32 options;
27 __le32 fqid;
31 struct dpdmai_rsp_get_tx_queue {
32 __le64 pad;
33 __le32 fqid;
36 #define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \
37 ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg))
39 /* cmd, param, offset, width, type, arg_name */
40 #define DPDMAI_CMD_CREATE(cmd, cfg) \
41 do { \
42 MC_CMD_OP(cmd, 0, 8, 8, u8, (cfg)->priorities[0]);\
43 MC_CMD_OP(cmd, 0, 16, 8, u8, (cfg)->priorities[1]);\
44 } while (0)
46 static inline u64 mc_enc(int lsoffset, int width, u64 val)
48 return (val & MAKE_UMASK64(width)) << lsoffset;
51 /**
52 * dpdmai_open() - Open a control session for the specified object
53 * @mc_io: Pointer to MC portal's I/O object
54 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
55 * @dpdmai_id: DPDMAI unique ID
56 * @token: Returned token; use in subsequent API calls
58 * This function can be used to open a control session for an
59 * already created object; an object may have been declared in
60 * the DPL or by calling the dpdmai_create() function.
61 * This function returns a unique authentication token,
62 * associated with the specific object ID and the specific MC
63 * portal; this token must be used in all subsequent commands for
64 * this specific object.
66 * Return: '0' on Success; Error code otherwise.
68 int dpdmai_open(struct fsl_mc_io *mc_io, u32 cmd_flags,
69 int dpdmai_id, u16 *token)
71 struct fsl_mc_command cmd = { 0 };
72 __le64 *cmd_dpdmai_id;
73 int err;
75 /* prepare command */
76 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
77 cmd_flags, 0);
79 cmd_dpdmai_id = cmd.params;
80 *cmd_dpdmai_id = cpu_to_le32(dpdmai_id);
82 /* send command to mc*/
83 err = mc_send_command(mc_io, &cmd);
84 if (err)
85 return err;
87 /* retrieve response parameters */
88 *token = mc_cmd_hdr_read_token(&cmd);
90 return 0;
92 EXPORT_SYMBOL_GPL(dpdmai_open);
94 /**
95 * dpdmai_close() - Close the control session of the object
96 * @mc_io: Pointer to MC portal's I/O object
97 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
98 * @token: Token of DPDMAI object
100 * After this function is called, no further operations are
101 * allowed on the object without opening a new control session.
103 * Return: '0' on Success; Error code otherwise.
105 int dpdmai_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
107 struct fsl_mc_command cmd = { 0 };
109 /* prepare command */
110 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
111 cmd_flags, token);
113 /* send command to mc*/
114 return mc_send_command(mc_io, &cmd);
116 EXPORT_SYMBOL_GPL(dpdmai_close);
119 * dpdmai_create() - Create the DPDMAI object
120 * @mc_io: Pointer to MC portal's I/O object
121 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
122 * @cfg: Configuration structure
123 * @token: Returned token; use in subsequent API calls
125 * Create the DPDMAI object, allocate required resources and
126 * perform required initialization.
128 * The object can be created either by declaring it in the
129 * DPL file, or by calling this function.
131 * This function returns a unique authentication token,
132 * associated with the specific object ID and the specific MC
133 * portal; this token must be used in all subsequent calls to
134 * this specific object. For objects that are created using the
135 * DPL file, call dpdmai_open() function to get an authentication
136 * token first.
138 * Return: '0' on Success; Error code otherwise.
140 int dpdmai_create(struct fsl_mc_io *mc_io, u32 cmd_flags,
141 const struct dpdmai_cfg *cfg, u16 *token)
143 struct fsl_mc_command cmd = { 0 };
144 int err;
146 /* prepare command */
147 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
148 cmd_flags, 0);
149 DPDMAI_CMD_CREATE(cmd, cfg);
151 /* send command to mc*/
152 err = mc_send_command(mc_io, &cmd);
153 if (err)
154 return err;
156 /* retrieve response parameters */
157 *token = mc_cmd_hdr_read_token(&cmd);
159 return 0;
163 * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
164 * @mc_io: Pointer to MC portal's I/O object
165 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
166 * @token: Token of DPDMAI object
168 * Return: '0' on Success; Error code otherwise.
170 int dpdmai_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
172 struct fsl_mc_command cmd = { 0 };
174 /* prepare command */
175 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
176 cmd_flags, token);
178 /* send command to mc*/
179 return mc_send_command(mc_io, &cmd);
181 EXPORT_SYMBOL_GPL(dpdmai_enable);
184 * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
185 * @mc_io: Pointer to MC portal's I/O object
186 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
187 * @token: Token of DPDMAI object
189 * Return: '0' on Success; Error code otherwise.
191 int dpdmai_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
193 struct fsl_mc_command cmd = { 0 };
195 /* prepare command */
196 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
197 cmd_flags, token);
199 /* send command to mc*/
200 return mc_send_command(mc_io, &cmd);
202 EXPORT_SYMBOL_GPL(dpdmai_disable);
205 * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
206 * @mc_io: Pointer to MC portal's I/O object
207 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
208 * @token: Token of DPDMAI object
210 * Return: '0' on Success; Error code otherwise.
212 int dpdmai_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
214 struct fsl_mc_command cmd = { 0 };
216 /* prepare command */
217 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
218 cmd_flags, token);
220 /* send command to mc*/
221 return mc_send_command(mc_io, &cmd);
223 EXPORT_SYMBOL_GPL(dpdmai_reset);
226 * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
227 * @mc_io: Pointer to MC portal's I/O object
228 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
229 * @token: Token of DPDMAI object
230 * @attr: Returned object's attributes
232 * Return: '0' on Success; Error code otherwise.
234 int dpdmai_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
235 u16 token, struct dpdmai_attr *attr)
237 struct dpdmai_rsp_get_attributes *rsp_params;
238 struct fsl_mc_command cmd = { 0 };
239 int err;
241 /* prepare command */
242 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
243 cmd_flags, token);
245 /* send command to mc*/
246 err = mc_send_command(mc_io, &cmd);
247 if (err)
248 return err;
250 /* retrieve response parameters */
251 rsp_params = (struct dpdmai_rsp_get_attributes *)cmd.params;
252 attr->id = le32_to_cpu(rsp_params->id);
253 attr->version.major = le16_to_cpu(rsp_params->major);
254 attr->version.minor = le16_to_cpu(rsp_params->minor);
255 attr->num_of_priorities = rsp_params->num_of_priorities;
257 return 0;
259 EXPORT_SYMBOL_GPL(dpdmai_get_attributes);
262 * dpdmai_set_rx_queue() - Set Rx queue configuration
263 * @mc_io: Pointer to MC portal's I/O object
264 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
265 * @token: Token of DPDMAI object
266 * @priority: Select the queue relative to number of
267 * priorities configured at DPDMAI creation
268 * @cfg: Rx queue configuration
270 * Return: '0' on Success; Error code otherwise.
272 int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
273 u8 priority, const struct dpdmai_rx_queue_cfg *cfg)
275 struct dpdmai_cmd_queue *cmd_params;
276 struct fsl_mc_command cmd = { 0 };
278 /* prepare command */
279 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
280 cmd_flags, token);
282 cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
283 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
284 cmd_params->priority = cfg->dest_cfg.priority;
285 cmd_params->queue = priority;
286 cmd_params->dest_type = cfg->dest_cfg.dest_type;
287 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
288 cmd_params->options = cpu_to_le32(cfg->options);
290 /* send command to mc*/
291 return mc_send_command(mc_io, &cmd);
293 EXPORT_SYMBOL_GPL(dpdmai_set_rx_queue);
296 * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
297 * @mc_io: Pointer to MC portal's I/O object
298 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
299 * @token: Token of DPDMAI object
300 * @priority: Select the queue relative to number of
301 * priorities configured at DPDMAI creation
302 * @attr: Returned Rx queue attributes
304 * Return: '0' on Success; Error code otherwise.
306 int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
307 u8 priority, struct dpdmai_rx_queue_attr *attr)
309 struct dpdmai_cmd_queue *cmd_params;
310 struct fsl_mc_command cmd = { 0 };
311 int err;
313 /* prepare command */
314 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
315 cmd_flags, token);
317 cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
318 cmd_params->queue = priority;
320 /* send command to mc*/
321 err = mc_send_command(mc_io, &cmd);
322 if (err)
323 return err;
325 /* retrieve response parameters */
326 attr->dest_cfg.dest_id = le32_to_cpu(cmd_params->dest_id);
327 attr->dest_cfg.priority = cmd_params->priority;
328 attr->dest_cfg.dest_type = cmd_params->dest_type;
329 attr->user_ctx = le64_to_cpu(cmd_params->user_ctx);
330 attr->fqid = le32_to_cpu(cmd_params->fqid);
332 return 0;
334 EXPORT_SYMBOL_GPL(dpdmai_get_rx_queue);
337 * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
338 * @mc_io: Pointer to MC portal's I/O object
339 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
340 * @token: Token of DPDMAI object
341 * @priority: Select the queue relative to number of
342 * priorities configured at DPDMAI creation
343 * @fqid: Returned Tx queue
345 * Return: '0' on Success; Error code otherwise.
347 int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags,
348 u16 token, u8 priority, u32 *fqid)
350 struct dpdmai_rsp_get_tx_queue *rsp_params;
351 struct dpdmai_cmd_queue *cmd_params;
352 struct fsl_mc_command cmd = { 0 };
353 int err;
355 /* prepare command */
356 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
357 cmd_flags, token);
359 cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
360 cmd_params->queue = priority;
362 /* send command to mc*/
363 err = mc_send_command(mc_io, &cmd);
364 if (err)
365 return err;
367 /* retrieve response parameters */
369 rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
370 *fqid = le32_to_cpu(rsp_params->fqid);
372 return 0;
374 EXPORT_SYMBOL_GPL(dpdmai_get_tx_queue);
376 MODULE_LICENSE("GPL v2");