xref: /OK3568_Linux_fs/kernel/drivers/dma/fsl-dpaa2-qdma/dpdmai.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun // Copyright 2019 NXP
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #include <linux/module.h>
5*4882a593Smuzhiyun #include <linux/types.h>
6*4882a593Smuzhiyun #include <linux/io.h>
7*4882a593Smuzhiyun #include <linux/fsl/mc.h>
8*4882a593Smuzhiyun #include "dpdmai.h"
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun struct dpdmai_rsp_get_attributes {
11*4882a593Smuzhiyun 	__le32 id;
12*4882a593Smuzhiyun 	u8 num_of_priorities;
13*4882a593Smuzhiyun 	u8 pad0[3];
14*4882a593Smuzhiyun 	__le16 major;
15*4882a593Smuzhiyun 	__le16 minor;
16*4882a593Smuzhiyun };
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun struct dpdmai_cmd_queue {
19*4882a593Smuzhiyun 	__le32 dest_id;
20*4882a593Smuzhiyun 	u8 priority;
21*4882a593Smuzhiyun 	u8 queue;
22*4882a593Smuzhiyun 	u8 dest_type;
23*4882a593Smuzhiyun 	u8 pad;
24*4882a593Smuzhiyun 	__le64 user_ctx;
25*4882a593Smuzhiyun 	union {
26*4882a593Smuzhiyun 		__le32 options;
27*4882a593Smuzhiyun 		__le32 fqid;
28*4882a593Smuzhiyun 	};
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun struct dpdmai_rsp_get_tx_queue {
32*4882a593Smuzhiyun 	__le64 pad;
33*4882a593Smuzhiyun 	__le32 fqid;
34*4882a593Smuzhiyun };
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \
37*4882a593Smuzhiyun 	((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg))
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /* cmd, param, offset, width, type, arg_name */
40*4882a593Smuzhiyun #define DPDMAI_CMD_CREATE(cmd, cfg) \
41*4882a593Smuzhiyun do { \
42*4882a593Smuzhiyun 	MC_CMD_OP(cmd, 0, 8,  8,  u8,  (cfg)->priorities[0]);\
43*4882a593Smuzhiyun 	MC_CMD_OP(cmd, 0, 16, 8,  u8,  (cfg)->priorities[1]);\
44*4882a593Smuzhiyun } while (0)
45*4882a593Smuzhiyun 
mc_enc(int lsoffset,int width,u64 val)46*4882a593Smuzhiyun static inline u64 mc_enc(int lsoffset, int width, u64 val)
47*4882a593Smuzhiyun {
48*4882a593Smuzhiyun 	return (val & MAKE_UMASK64(width)) << lsoffset;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /**
52*4882a593Smuzhiyun  * dpdmai_open() - Open a control session for the specified object
53*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
54*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
55*4882a593Smuzhiyun  * @dpdmai_id:	DPDMAI unique ID
56*4882a593Smuzhiyun  * @token:	Returned token; use in subsequent API calls
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  * This function can be used to open a control session for an
59*4882a593Smuzhiyun  * already created object; an object may have been declared in
60*4882a593Smuzhiyun  * the DPL or by calling the dpdmai_create() function.
61*4882a593Smuzhiyun  * This function returns a unique authentication token,
62*4882a593Smuzhiyun  * associated with the specific object ID and the specific MC
63*4882a593Smuzhiyun  * portal; this token must be used in all subsequent commands for
64*4882a593Smuzhiyun  * this specific object.
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
67*4882a593Smuzhiyun  */
dpdmai_open(struct fsl_mc_io * mc_io,u32 cmd_flags,int dpdmai_id,u16 * token)68*4882a593Smuzhiyun int dpdmai_open(struct fsl_mc_io *mc_io, u32 cmd_flags,
69*4882a593Smuzhiyun 		int dpdmai_id, u16 *token)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
72*4882a593Smuzhiyun 	__le64 *cmd_dpdmai_id;
73*4882a593Smuzhiyun 	int err;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	/* prepare command */
76*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
77*4882a593Smuzhiyun 					  cmd_flags, 0);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	cmd_dpdmai_id = cmd.params;
80*4882a593Smuzhiyun 	*cmd_dpdmai_id = cpu_to_le32(dpdmai_id);
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	/* send command to mc*/
83*4882a593Smuzhiyun 	err = mc_send_command(mc_io, &cmd);
84*4882a593Smuzhiyun 	if (err)
85*4882a593Smuzhiyun 		return err;
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun 	/* retrieve response parameters */
88*4882a593Smuzhiyun 	*token = mc_cmd_hdr_read_token(&cmd);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	return 0;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_open);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /**
95*4882a593Smuzhiyun  * dpdmai_close() - Close the control session of the object
96*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
97*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
98*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
99*4882a593Smuzhiyun  *
100*4882a593Smuzhiyun  * After this function is called, no further operations are
101*4882a593Smuzhiyun  * allowed on the object without opening a new control session.
102*4882a593Smuzhiyun  *
103*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
104*4882a593Smuzhiyun  */
dpdmai_close(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)105*4882a593Smuzhiyun int dpdmai_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	/* prepare command */
110*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
111*4882a593Smuzhiyun 					  cmd_flags, token);
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	/* send command to mc*/
114*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_close);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /**
119*4882a593Smuzhiyun  * dpdmai_create() - Create the DPDMAI object
120*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
121*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
122*4882a593Smuzhiyun  * @cfg:	Configuration structure
123*4882a593Smuzhiyun  * @token:	Returned token; use in subsequent API calls
124*4882a593Smuzhiyun  *
125*4882a593Smuzhiyun  * Create the DPDMAI object, allocate required resources and
126*4882a593Smuzhiyun  * perform required initialization.
127*4882a593Smuzhiyun  *
128*4882a593Smuzhiyun  * The object can be created either by declaring it in the
129*4882a593Smuzhiyun  * DPL file, or by calling this function.
130*4882a593Smuzhiyun  *
131*4882a593Smuzhiyun  * This function returns a unique authentication token,
132*4882a593Smuzhiyun  * associated with the specific object ID and the specific MC
133*4882a593Smuzhiyun  * portal; this token must be used in all subsequent calls to
134*4882a593Smuzhiyun  * this specific object. For objects that are created using the
135*4882a593Smuzhiyun  * DPL file, call dpdmai_open() function to get an authentication
136*4882a593Smuzhiyun  * token first.
137*4882a593Smuzhiyun  *
138*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
139*4882a593Smuzhiyun  */
dpdmai_create(struct fsl_mc_io * mc_io,u32 cmd_flags,const struct dpdmai_cfg * cfg,u16 * token)140*4882a593Smuzhiyun int dpdmai_create(struct fsl_mc_io *mc_io, u32 cmd_flags,
141*4882a593Smuzhiyun 		  const struct dpdmai_cfg *cfg, u16 *token)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
144*4882a593Smuzhiyun 	int err;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	/* prepare command */
147*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
148*4882a593Smuzhiyun 					  cmd_flags, 0);
149*4882a593Smuzhiyun 	DPDMAI_CMD_CREATE(cmd, cfg);
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	/* send command to mc*/
152*4882a593Smuzhiyun 	err = mc_send_command(mc_io, &cmd);
153*4882a593Smuzhiyun 	if (err)
154*4882a593Smuzhiyun 		return err;
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 	/* retrieve response parameters */
157*4882a593Smuzhiyun 	*token = mc_cmd_hdr_read_token(&cmd);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	return 0;
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun /**
163*4882a593Smuzhiyun  * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
164*4882a593Smuzhiyun  * @mc_io:      Pointer to MC portal's I/O object
165*4882a593Smuzhiyun  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
166*4882a593Smuzhiyun  * @token:      Token of DPDMAI object
167*4882a593Smuzhiyun  *
168*4882a593Smuzhiyun  * Return:      '0' on Success; error code otherwise.
169*4882a593Smuzhiyun  */
dpdmai_destroy(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)170*4882a593Smuzhiyun int dpdmai_destroy(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	/* prepare command */
175*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
176*4882a593Smuzhiyun 					  cmd_flags, token);
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	/* send command to mc*/
179*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_destroy);
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /**
184*4882a593Smuzhiyun  * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
185*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
186*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
187*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
188*4882a593Smuzhiyun  *
189*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
190*4882a593Smuzhiyun  */
dpdmai_enable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)191*4882a593Smuzhiyun int dpdmai_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
192*4882a593Smuzhiyun {
193*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	/* prepare command */
196*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
197*4882a593Smuzhiyun 					  cmd_flags, token);
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	/* send command to mc*/
200*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_enable);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /**
205*4882a593Smuzhiyun  * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
206*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
207*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
208*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
209*4882a593Smuzhiyun  *
210*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
211*4882a593Smuzhiyun  */
dpdmai_disable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)212*4882a593Smuzhiyun int dpdmai_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 	/* prepare command */
217*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
218*4882a593Smuzhiyun 					  cmd_flags, token);
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	/* send command to mc*/
221*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
222*4882a593Smuzhiyun }
223*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_disable);
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun /**
226*4882a593Smuzhiyun  * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
227*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
228*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
229*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
230*4882a593Smuzhiyun  *
231*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
232*4882a593Smuzhiyun  */
dpdmai_reset(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)233*4882a593Smuzhiyun int dpdmai_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
234*4882a593Smuzhiyun {
235*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun 	/* prepare command */
238*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
239*4882a593Smuzhiyun 					  cmd_flags, token);
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	/* send command to mc*/
242*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_reset);
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun /**
247*4882a593Smuzhiyun  * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
248*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
249*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
250*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
251*4882a593Smuzhiyun  * @attr:	Returned object's attributes
252*4882a593Smuzhiyun  *
253*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
254*4882a593Smuzhiyun  */
dpdmai_get_attributes(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,struct dpdmai_attr * attr)255*4882a593Smuzhiyun int dpdmai_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
256*4882a593Smuzhiyun 			  u16 token, struct dpdmai_attr *attr)
257*4882a593Smuzhiyun {
258*4882a593Smuzhiyun 	struct dpdmai_rsp_get_attributes *rsp_params;
259*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
260*4882a593Smuzhiyun 	int err;
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 	/* prepare command */
263*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
264*4882a593Smuzhiyun 					  cmd_flags, token);
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	/* send command to mc*/
267*4882a593Smuzhiyun 	err = mc_send_command(mc_io, &cmd);
268*4882a593Smuzhiyun 	if (err)
269*4882a593Smuzhiyun 		return err;
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun 	/* retrieve response parameters */
272*4882a593Smuzhiyun 	rsp_params = (struct dpdmai_rsp_get_attributes *)cmd.params;
273*4882a593Smuzhiyun 	attr->id = le32_to_cpu(rsp_params->id);
274*4882a593Smuzhiyun 	attr->version.major = le16_to_cpu(rsp_params->major);
275*4882a593Smuzhiyun 	attr->version.minor = le16_to_cpu(rsp_params->minor);
276*4882a593Smuzhiyun 	attr->num_of_priorities = rsp_params->num_of_priorities;
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun 	return 0;
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_get_attributes);
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun /**
283*4882a593Smuzhiyun  * dpdmai_set_rx_queue() - Set Rx queue configuration
284*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
285*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
286*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
287*4882a593Smuzhiyun  * @priority:	Select the queue relative to number of
288*4882a593Smuzhiyun  *		priorities configured at DPDMAI creation
289*4882a593Smuzhiyun  * @cfg:	Rx queue configuration
290*4882a593Smuzhiyun  *
291*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
292*4882a593Smuzhiyun  */
dpdmai_set_rx_queue(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u8 priority,const struct dpdmai_rx_queue_cfg * cfg)293*4882a593Smuzhiyun int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
294*4882a593Smuzhiyun 			u8 priority, const struct dpdmai_rx_queue_cfg *cfg)
295*4882a593Smuzhiyun {
296*4882a593Smuzhiyun 	struct dpdmai_cmd_queue *cmd_params;
297*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun 	/* prepare command */
300*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
301*4882a593Smuzhiyun 					  cmd_flags, token);
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun 	cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
304*4882a593Smuzhiyun 	cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
305*4882a593Smuzhiyun 	cmd_params->priority = cfg->dest_cfg.priority;
306*4882a593Smuzhiyun 	cmd_params->queue = priority;
307*4882a593Smuzhiyun 	cmd_params->dest_type = cfg->dest_cfg.dest_type;
308*4882a593Smuzhiyun 	cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
309*4882a593Smuzhiyun 	cmd_params->options = cpu_to_le32(cfg->options);
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	/* send command to mc*/
312*4882a593Smuzhiyun 	return mc_send_command(mc_io, &cmd);
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_set_rx_queue);
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun /**
317*4882a593Smuzhiyun  * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
318*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
319*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
320*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
321*4882a593Smuzhiyun  * @priority:	Select the queue relative to number of
322*4882a593Smuzhiyun  *				priorities configured at DPDMAI creation
323*4882a593Smuzhiyun  * @attr:	Returned Rx queue attributes
324*4882a593Smuzhiyun  *
325*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
326*4882a593Smuzhiyun  */
dpdmai_get_rx_queue(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u8 priority,struct dpdmai_rx_queue_attr * attr)327*4882a593Smuzhiyun int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
328*4882a593Smuzhiyun 			u8 priority, struct dpdmai_rx_queue_attr *attr)
329*4882a593Smuzhiyun {
330*4882a593Smuzhiyun 	struct dpdmai_cmd_queue *cmd_params;
331*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
332*4882a593Smuzhiyun 	int err;
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	/* prepare command */
335*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
336*4882a593Smuzhiyun 					  cmd_flags, token);
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun 	cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
339*4882a593Smuzhiyun 	cmd_params->queue = priority;
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 	/* send command to mc*/
342*4882a593Smuzhiyun 	err = mc_send_command(mc_io, &cmd);
343*4882a593Smuzhiyun 	if (err)
344*4882a593Smuzhiyun 		return err;
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun 	/* retrieve response parameters */
347*4882a593Smuzhiyun 	attr->dest_cfg.dest_id = le32_to_cpu(cmd_params->dest_id);
348*4882a593Smuzhiyun 	attr->dest_cfg.priority = cmd_params->priority;
349*4882a593Smuzhiyun 	attr->dest_cfg.dest_type = cmd_params->dest_type;
350*4882a593Smuzhiyun 	attr->user_ctx = le64_to_cpu(cmd_params->user_ctx);
351*4882a593Smuzhiyun 	attr->fqid = le32_to_cpu(cmd_params->fqid);
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun 	return 0;
354*4882a593Smuzhiyun }
355*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_get_rx_queue);
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun /**
358*4882a593Smuzhiyun  * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
359*4882a593Smuzhiyun  * @mc_io:	Pointer to MC portal's I/O object
360*4882a593Smuzhiyun  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
361*4882a593Smuzhiyun  * @token:	Token of DPDMAI object
362*4882a593Smuzhiyun  * @priority:	Select the queue relative to number of
363*4882a593Smuzhiyun  *			priorities configured at DPDMAI creation
364*4882a593Smuzhiyun  * @fqid:	Returned Tx queue
365*4882a593Smuzhiyun  *
366*4882a593Smuzhiyun  * Return:	'0' on Success; Error code otherwise.
367*4882a593Smuzhiyun  */
dpdmai_get_tx_queue(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u8 priority,u32 * fqid)368*4882a593Smuzhiyun int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags,
369*4882a593Smuzhiyun 			u16 token, u8 priority, u32 *fqid)
370*4882a593Smuzhiyun {
371*4882a593Smuzhiyun 	struct dpdmai_rsp_get_tx_queue *rsp_params;
372*4882a593Smuzhiyun 	struct dpdmai_cmd_queue *cmd_params;
373*4882a593Smuzhiyun 	struct fsl_mc_command cmd = { 0 };
374*4882a593Smuzhiyun 	int err;
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	/* prepare command */
377*4882a593Smuzhiyun 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
378*4882a593Smuzhiyun 					  cmd_flags, token);
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun 	cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
381*4882a593Smuzhiyun 	cmd_params->queue = priority;
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun 	/* send command to mc*/
384*4882a593Smuzhiyun 	err = mc_send_command(mc_io, &cmd);
385*4882a593Smuzhiyun 	if (err)
386*4882a593Smuzhiyun 		return err;
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun 	/* retrieve response parameters */
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
391*4882a593Smuzhiyun 	*fqid = le32_to_cpu(rsp_params->fqid);
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun 	return 0;
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(dpdmai_get_tx_queue);
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
398