xref: /dpdk/drivers/bus/fslmc/mc/dpdmai.c (revision 2cb2abf304fcecc0e2804b8da61760d4f2cb9a7e)
123e8fcb0SNipun Gupta /* SPDX-License-Identifier: BSD-3-Clause
2*2cb2abf3SHemant Agrawal  * Copyright 2018-2021 NXP
323e8fcb0SNipun Gupta  */
423e8fcb0SNipun Gupta 
523e8fcb0SNipun Gupta #include <fsl_mc_sys.h>
623e8fcb0SNipun Gupta #include <fsl_mc_cmd.h>
723e8fcb0SNipun Gupta #include <fsl_dpdmai.h>
823e8fcb0SNipun Gupta #include <fsl_dpdmai_cmd.h>
923e8fcb0SNipun Gupta 
1023e8fcb0SNipun Gupta /**
1123e8fcb0SNipun Gupta  * dpdmai_open() - Open a control session for the specified object
1223e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
1323e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1423e8fcb0SNipun Gupta  * @dpdmai_id:	DPDMAI unique ID
1523e8fcb0SNipun Gupta  * @token:	Returned token; use in subsequent API calls
1623e8fcb0SNipun Gupta  *
1723e8fcb0SNipun Gupta  * This function can be used to open a control session for an
1823e8fcb0SNipun Gupta  * already created object; an object may have been declared in
1923e8fcb0SNipun Gupta  * the DPL or by calling the dpdmai_create() function.
2023e8fcb0SNipun Gupta  * This function returns a unique authentication token,
2123e8fcb0SNipun Gupta  * associated with the specific object ID and the specific MC
2223e8fcb0SNipun Gupta  * portal; this token must be used in all subsequent commands for
2323e8fcb0SNipun Gupta  * this specific object.
2423e8fcb0SNipun Gupta  *
2523e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
2623e8fcb0SNipun Gupta  */
dpdmai_open(struct fsl_mc_io * mc_io,uint32_t cmd_flags,int dpdmai_id,uint16_t * token)2723e8fcb0SNipun Gupta int dpdmai_open(struct fsl_mc_io *mc_io,
2823e8fcb0SNipun Gupta 		uint32_t cmd_flags,
2923e8fcb0SNipun Gupta 		int dpdmai_id,
3023e8fcb0SNipun Gupta 		uint16_t *token)
3123e8fcb0SNipun Gupta {
3223e8fcb0SNipun Gupta 	struct dpdmai_cmd_open *cmd_params;
3323e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
3423e8fcb0SNipun Gupta 	int err;
3523e8fcb0SNipun Gupta 
3623e8fcb0SNipun Gupta 	/* prepare command */
3723e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
3823e8fcb0SNipun Gupta 					  cmd_flags,
3923e8fcb0SNipun Gupta 					  0);
4023e8fcb0SNipun Gupta 	cmd_params = (struct dpdmai_cmd_open *)cmd.params;
4123e8fcb0SNipun Gupta 	cmd_params->dpdmai_id = cpu_to_le32(dpdmai_id);
4223e8fcb0SNipun Gupta 
4323e8fcb0SNipun Gupta 	/* send command to mc*/
4423e8fcb0SNipun Gupta 	err = mc_send_command(mc_io, &cmd);
4523e8fcb0SNipun Gupta 	if (err)
4623e8fcb0SNipun Gupta 		return err;
4723e8fcb0SNipun Gupta 
4823e8fcb0SNipun Gupta 	/* retrieve response parameters */
4923e8fcb0SNipun Gupta 	*token = mc_cmd_hdr_read_token(&cmd);
5023e8fcb0SNipun Gupta 
5123e8fcb0SNipun Gupta 	return 0;
5223e8fcb0SNipun Gupta }
5323e8fcb0SNipun Gupta 
5423e8fcb0SNipun Gupta /**
5523e8fcb0SNipun Gupta  * dpdmai_close() - Close the control session of the object
5623e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
5723e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
5823e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
5923e8fcb0SNipun Gupta  *
6023e8fcb0SNipun Gupta  * After this function is called, no further operations are
6123e8fcb0SNipun Gupta  * allowed on the object without opening a new control session.
6223e8fcb0SNipun Gupta  *
6323e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
6423e8fcb0SNipun Gupta  */
dpdmai_close(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)6523e8fcb0SNipun Gupta int dpdmai_close(struct fsl_mc_io *mc_io,
6623e8fcb0SNipun Gupta 		 uint32_t cmd_flags,
6723e8fcb0SNipun Gupta 		 uint16_t token)
6823e8fcb0SNipun Gupta {
6923e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
7023e8fcb0SNipun Gupta 
7123e8fcb0SNipun Gupta 	/* prepare command */
7223e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
7323e8fcb0SNipun Gupta 					  cmd_flags, token);
7423e8fcb0SNipun Gupta 
7523e8fcb0SNipun Gupta 	/* send command to mc*/
7623e8fcb0SNipun Gupta 	return mc_send_command(mc_io, &cmd);
7723e8fcb0SNipun Gupta }
7823e8fcb0SNipun Gupta 
7923e8fcb0SNipun Gupta /**
8023e8fcb0SNipun Gupta  * dpdmai_create() - Create the DPDMAI object
8123e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
8223e8fcb0SNipun Gupta  * @dprc_token:	Parent container token; '0' for default container
8323e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
8423e8fcb0SNipun Gupta  * @cfg:	Configuration structure
8523e8fcb0SNipun Gupta  * @obj_id:	Returned object id
8623e8fcb0SNipun Gupta  *
8723e8fcb0SNipun Gupta  * Create the DPDMAI object, allocate required resources and
8823e8fcb0SNipun Gupta  * perform required initialization.
8923e8fcb0SNipun Gupta  *
9023e8fcb0SNipun Gupta  * The object can be created either by declaring it in the
9123e8fcb0SNipun Gupta  * DPL file, or by calling this function.
9223e8fcb0SNipun Gupta  *
9323e8fcb0SNipun Gupta  * The function accepts an authentication token of a parent
9423e8fcb0SNipun Gupta  * container that this object should be assigned to. The token
9523e8fcb0SNipun Gupta  * can be '0' so the object will be assigned to the default container.
9623e8fcb0SNipun Gupta  * The newly created object can be opened with the returned
9723e8fcb0SNipun Gupta  * object id and using the container's associated tokens and MC portals.
9823e8fcb0SNipun Gupta  *
9923e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
10023e8fcb0SNipun Gupta  */
dpdmai_create(struct fsl_mc_io * mc_io,uint16_t dprc_token,uint32_t cmd_flags,const struct dpdmai_cfg * cfg,uint32_t * obj_id)10123e8fcb0SNipun Gupta int dpdmai_create(struct fsl_mc_io *mc_io,
10223e8fcb0SNipun Gupta 		  uint16_t dprc_token,
10323e8fcb0SNipun Gupta 		  uint32_t cmd_flags,
10423e8fcb0SNipun Gupta 		  const struct dpdmai_cfg *cfg,
10523e8fcb0SNipun Gupta 		  uint32_t *obj_id)
10623e8fcb0SNipun Gupta {
10723e8fcb0SNipun Gupta 	struct dpdmai_cmd_create *cmd_params;
10823e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
10923e8fcb0SNipun Gupta 	int err;
11023e8fcb0SNipun Gupta 
11123e8fcb0SNipun Gupta 	/* prepare command */
11223e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
11323e8fcb0SNipun Gupta 					  cmd_flags,
11423e8fcb0SNipun Gupta 					  dprc_token);
11523e8fcb0SNipun Gupta 	cmd_params = (struct dpdmai_cmd_create *)cmd.params;
116b4a63e60SHemant Agrawal 	cmd_params->num_queues = cfg->num_queues;
11723e8fcb0SNipun Gupta 	cmd_params->priorities[0] = cfg->priorities[0];
11823e8fcb0SNipun Gupta 	cmd_params->priorities[1] = cfg->priorities[1];
119*2cb2abf3SHemant Agrawal 	cmd_params->options = cpu_to_le32(cfg->adv.options);
12023e8fcb0SNipun Gupta 
12123e8fcb0SNipun Gupta 	/* send command to mc*/
12223e8fcb0SNipun Gupta 	err = mc_send_command(mc_io, &cmd);
12323e8fcb0SNipun Gupta 	if (err)
12423e8fcb0SNipun Gupta 		return err;
12523e8fcb0SNipun Gupta 
12623e8fcb0SNipun Gupta 	/* retrieve response parameters */
12723e8fcb0SNipun Gupta 	*obj_id = mc_cmd_read_object_id(&cmd);
12823e8fcb0SNipun Gupta 
12923e8fcb0SNipun Gupta 	return 0;
13023e8fcb0SNipun Gupta }
13123e8fcb0SNipun Gupta 
13223e8fcb0SNipun Gupta /**
13323e8fcb0SNipun Gupta  * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
13423e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
13523e8fcb0SNipun Gupta  * @dprc_token: Parent container token; '0' for default container
13623e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
13723e8fcb0SNipun Gupta  * @object_id:	The object id; it must be a valid id within the container that
13823e8fcb0SNipun Gupta  *		created this object;
13923e8fcb0SNipun Gupta  *
14023e8fcb0SNipun Gupta  * The function accepts the authentication token of the parent container that
14123e8fcb0SNipun Gupta  * created the object (not the one that currently owns the object). The object
14223e8fcb0SNipun Gupta  * is searched within parent using the provided 'object_id'.
14323e8fcb0SNipun Gupta  * All tokens to the object must be closed before calling destroy.
14423e8fcb0SNipun Gupta  *
14523e8fcb0SNipun Gupta  * Return:	'0' on Success; error code otherwise.
14623e8fcb0SNipun Gupta  */
dpdmai_destroy(struct fsl_mc_io * mc_io,uint16_t dprc_token,uint32_t cmd_flags,uint32_t object_id)14723e8fcb0SNipun Gupta int dpdmai_destroy(struct fsl_mc_io *mc_io,
14823e8fcb0SNipun Gupta 		   uint16_t dprc_token,
14923e8fcb0SNipun Gupta 		   uint32_t cmd_flags,
15023e8fcb0SNipun Gupta 		   uint32_t object_id)
15123e8fcb0SNipun Gupta {
15223e8fcb0SNipun Gupta 	struct dpdmai_cmd_destroy *cmd_params;
15323e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
15423e8fcb0SNipun Gupta 
15523e8fcb0SNipun Gupta 	/* prepare command */
15623e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
15723e8fcb0SNipun Gupta 					  cmd_flags,
15823e8fcb0SNipun Gupta 					  dprc_token);
15923e8fcb0SNipun Gupta 	cmd_params = (struct dpdmai_cmd_destroy *)cmd.params;
16023e8fcb0SNipun Gupta 	cmd_params->dpdmai_id = cpu_to_le32(object_id);
16123e8fcb0SNipun Gupta 
16223e8fcb0SNipun Gupta 	/* send command to mc*/
16323e8fcb0SNipun Gupta 	return mc_send_command(mc_io, &cmd);
16423e8fcb0SNipun Gupta }
16523e8fcb0SNipun Gupta 
16623e8fcb0SNipun Gupta /**
16723e8fcb0SNipun Gupta  * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
16823e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
16923e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
17023e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
17123e8fcb0SNipun Gupta  *
17223e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
17323e8fcb0SNipun Gupta  */
dpdmai_enable(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)17423e8fcb0SNipun Gupta int dpdmai_enable(struct fsl_mc_io *mc_io,
17523e8fcb0SNipun Gupta 		  uint32_t cmd_flags,
17623e8fcb0SNipun Gupta 		  uint16_t token)
17723e8fcb0SNipun Gupta {
17823e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
17923e8fcb0SNipun Gupta 
18023e8fcb0SNipun Gupta 	/* prepare command */
18123e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
18223e8fcb0SNipun Gupta 					  cmd_flags,
18323e8fcb0SNipun Gupta 					  token);
18423e8fcb0SNipun Gupta 
18523e8fcb0SNipun Gupta 	/* send command to mc*/
18623e8fcb0SNipun Gupta 	return mc_send_command(mc_io, &cmd);
18723e8fcb0SNipun Gupta }
18823e8fcb0SNipun Gupta 
18923e8fcb0SNipun Gupta /**
19023e8fcb0SNipun Gupta  * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
19123e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
19223e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
19323e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
19423e8fcb0SNipun Gupta  *
19523e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
19623e8fcb0SNipun Gupta  */
dpdmai_disable(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)19723e8fcb0SNipun Gupta int dpdmai_disable(struct fsl_mc_io *mc_io,
19823e8fcb0SNipun Gupta 		   uint32_t cmd_flags,
19923e8fcb0SNipun Gupta 		   uint16_t token)
20023e8fcb0SNipun Gupta {
20123e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
20223e8fcb0SNipun Gupta 
20323e8fcb0SNipun Gupta 	/* prepare command */
20423e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
20523e8fcb0SNipun Gupta 					  cmd_flags,
20623e8fcb0SNipun Gupta 					  token);
20723e8fcb0SNipun Gupta 
20823e8fcb0SNipun Gupta 	/* send command to mc*/
20923e8fcb0SNipun Gupta 	return mc_send_command(mc_io, &cmd);
21023e8fcb0SNipun Gupta }
21123e8fcb0SNipun Gupta 
21223e8fcb0SNipun Gupta /**
21323e8fcb0SNipun Gupta  * dpdmai_is_enabled() - Check if the DPDMAI is enabled.
21423e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
21523e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
21623e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
21723e8fcb0SNipun Gupta  * @en:		Returns '1' if object is enabled; '0' otherwise
21823e8fcb0SNipun Gupta  *
21923e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
22023e8fcb0SNipun Gupta  */
dpdmai_is_enabled(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,int * en)22123e8fcb0SNipun Gupta int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
22223e8fcb0SNipun Gupta 		      uint32_t cmd_flags,
22323e8fcb0SNipun Gupta 		      uint16_t token,
22423e8fcb0SNipun Gupta 		      int *en)
22523e8fcb0SNipun Gupta {
22623e8fcb0SNipun Gupta 	struct dpdmai_rsp_is_enabled *rsp_params;
22723e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
22823e8fcb0SNipun Gupta 	int err;
22923e8fcb0SNipun Gupta 
23023e8fcb0SNipun Gupta 	/* prepare command */
23123e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_IS_ENABLED,
23223e8fcb0SNipun Gupta 					  cmd_flags,
23323e8fcb0SNipun Gupta 					  token);
23423e8fcb0SNipun Gupta 
23523e8fcb0SNipun Gupta 	/* send command to mc*/
23623e8fcb0SNipun Gupta 	err = mc_send_command(mc_io, &cmd);
23723e8fcb0SNipun Gupta 	if (err)
23823e8fcb0SNipun Gupta 		return err;
23923e8fcb0SNipun Gupta 
24023e8fcb0SNipun Gupta 	/* retrieve response parameters */
24123e8fcb0SNipun Gupta 	rsp_params = (struct dpdmai_rsp_is_enabled *)cmd.params;
24223e8fcb0SNipun Gupta 	*en = dpdmai_get_field(rsp_params->en, ENABLE);
24323e8fcb0SNipun Gupta 
24423e8fcb0SNipun Gupta 	return 0;
24523e8fcb0SNipun Gupta }
24623e8fcb0SNipun Gupta 
24723e8fcb0SNipun Gupta /**
24823e8fcb0SNipun Gupta  * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
24923e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
25023e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
25123e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
25223e8fcb0SNipun Gupta  *
25323e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
25423e8fcb0SNipun Gupta  */
dpdmai_reset(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)25523e8fcb0SNipun Gupta int dpdmai_reset(struct fsl_mc_io *mc_io,
25623e8fcb0SNipun Gupta 		 uint32_t cmd_flags,
25723e8fcb0SNipun Gupta 		 uint16_t token)
25823e8fcb0SNipun Gupta {
25923e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
26023e8fcb0SNipun Gupta 
26123e8fcb0SNipun Gupta 	/* prepare command */
26223e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
26323e8fcb0SNipun Gupta 					  cmd_flags,
26423e8fcb0SNipun Gupta 					  token);
26523e8fcb0SNipun Gupta 
26623e8fcb0SNipun Gupta 	/* send command to mc*/
26723e8fcb0SNipun Gupta 	return mc_send_command(mc_io, &cmd);
26823e8fcb0SNipun Gupta }
26923e8fcb0SNipun Gupta 
27023e8fcb0SNipun Gupta /**
27123e8fcb0SNipun Gupta  * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
27223e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
27323e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
27423e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
27523e8fcb0SNipun Gupta  * @attr:	Returned object's attributes
27623e8fcb0SNipun Gupta  *
27723e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
27823e8fcb0SNipun Gupta  */
dpdmai_get_attributes(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,struct dpdmai_attr * attr)27923e8fcb0SNipun Gupta int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
28023e8fcb0SNipun Gupta 			  uint32_t cmd_flags,
28123e8fcb0SNipun Gupta 			  uint16_t token,
28223e8fcb0SNipun Gupta 			  struct dpdmai_attr *attr)
28323e8fcb0SNipun Gupta {
28423e8fcb0SNipun Gupta 	struct dpdmai_rsp_get_attr *rsp_params;
28523e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
28623e8fcb0SNipun Gupta 	int err;
28723e8fcb0SNipun Gupta 
28823e8fcb0SNipun Gupta 	/* prepare command */
28923e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
29023e8fcb0SNipun Gupta 					  cmd_flags,
29123e8fcb0SNipun Gupta 					  token);
29223e8fcb0SNipun Gupta 
29323e8fcb0SNipun Gupta 	/* send command to mc*/
29423e8fcb0SNipun Gupta 	err = mc_send_command(mc_io, &cmd);
29523e8fcb0SNipun Gupta 	if (err)
29623e8fcb0SNipun Gupta 		return err;
29723e8fcb0SNipun Gupta 
29823e8fcb0SNipun Gupta 	/* retrieve response parameters */
29923e8fcb0SNipun Gupta 	rsp_params = (struct dpdmai_rsp_get_attr *)cmd.params;
30023e8fcb0SNipun Gupta 	attr->id = le32_to_cpu(rsp_params->id);
30123e8fcb0SNipun Gupta 	attr->num_of_priorities = rsp_params->num_of_priorities;
302b4a63e60SHemant Agrawal 	attr->num_of_queues = rsp_params->num_of_queues;
303*2cb2abf3SHemant Agrawal 	attr->options = le32_to_cpu(rsp_params->options);
30423e8fcb0SNipun Gupta 
30523e8fcb0SNipun Gupta 	return 0;
30623e8fcb0SNipun Gupta }
30723e8fcb0SNipun Gupta 
30823e8fcb0SNipun Gupta /**
30923e8fcb0SNipun Gupta  * dpdmai_set_rx_queue() - Set Rx queue configuration
31023e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
31123e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
31223e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
313b4a63e60SHemant Agrawal  * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
314b4a63e60SHemant Agrawal  *		parameter provided in dpdmai_create
31523e8fcb0SNipun Gupta  * @priority:	Select the queue relative to number of
31623e8fcb0SNipun Gupta  *		priorities configured at DPDMAI creation; use
31723e8fcb0SNipun Gupta  *		DPDMAI_ALL_QUEUES to configure all Rx queues
31823e8fcb0SNipun Gupta  *		identically.
31923e8fcb0SNipun Gupta  * @cfg:	Rx queue configuration
32023e8fcb0SNipun Gupta  *
32123e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
32223e8fcb0SNipun Gupta  */
dpdmai_set_rx_queue(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,uint8_t queue_idx,uint8_t priority,const struct dpdmai_rx_queue_cfg * cfg)32323e8fcb0SNipun Gupta int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
32423e8fcb0SNipun Gupta 			uint32_t cmd_flags,
32523e8fcb0SNipun Gupta 			uint16_t token,
326b4a63e60SHemant Agrawal 			uint8_t queue_idx,
32723e8fcb0SNipun Gupta 			uint8_t priority,
32823e8fcb0SNipun Gupta 			const struct dpdmai_rx_queue_cfg *cfg)
32923e8fcb0SNipun Gupta {
33023e8fcb0SNipun Gupta 	struct dpdmai_cmd_set_rx_queue *cmd_params;
33123e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
33223e8fcb0SNipun Gupta 
33323e8fcb0SNipun Gupta 	/* prepare command */
33423e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
33523e8fcb0SNipun Gupta 					  cmd_flags,
33623e8fcb0SNipun Gupta 					  token);
33723e8fcb0SNipun Gupta 	cmd_params = (struct dpdmai_cmd_set_rx_queue *)cmd.params;
33823e8fcb0SNipun Gupta 	cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
33923e8fcb0SNipun Gupta 	cmd_params->dest_priority = cfg->dest_cfg.priority;
34023e8fcb0SNipun Gupta 	cmd_params->priority = priority;
341b4a63e60SHemant Agrawal 	cmd_params->queue_idx = queue_idx;
34223e8fcb0SNipun Gupta 	cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
34323e8fcb0SNipun Gupta 	cmd_params->options = cpu_to_le32(cfg->options);
34423e8fcb0SNipun Gupta 	dpdmai_set_field(cmd_params->dest_type,
34523e8fcb0SNipun Gupta 			 DEST_TYPE,
34623e8fcb0SNipun Gupta 			 cfg->dest_cfg.dest_type);
34723e8fcb0SNipun Gupta 
34823e8fcb0SNipun Gupta 	/* send command to mc*/
34923e8fcb0SNipun Gupta 	return mc_send_command(mc_io, &cmd);
35023e8fcb0SNipun Gupta }
35123e8fcb0SNipun Gupta 
35223e8fcb0SNipun Gupta /**
35323e8fcb0SNipun Gupta  * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
35423e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
35523e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
35623e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
357b4a63e60SHemant Agrawal  * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
358b4a63e60SHemant Agrawal  *		parameter provided in dpdmai_create
35923e8fcb0SNipun Gupta  * @priority:	Select the queue relative to number of
36023e8fcb0SNipun Gupta  *		priorities configured at DPDMAI creation
36123e8fcb0SNipun Gupta  * @attr:	Returned Rx queue attributes
36223e8fcb0SNipun Gupta  *
36323e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
36423e8fcb0SNipun Gupta  */
dpdmai_get_rx_queue(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,uint8_t queue_idx,uint8_t priority,struct dpdmai_rx_queue_attr * attr)36523e8fcb0SNipun Gupta int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
36623e8fcb0SNipun Gupta 			uint32_t cmd_flags,
36723e8fcb0SNipun Gupta 			uint16_t token,
368b4a63e60SHemant Agrawal 			uint8_t queue_idx,
36923e8fcb0SNipun Gupta 			uint8_t priority,
37023e8fcb0SNipun Gupta 			struct dpdmai_rx_queue_attr *attr)
37123e8fcb0SNipun Gupta {
37223e8fcb0SNipun Gupta 	struct dpdmai_cmd_get_queue *cmd_params;
37323e8fcb0SNipun Gupta 	struct dpdmai_rsp_get_rx_queue *rsp_params;
37423e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
37523e8fcb0SNipun Gupta 	int err;
37623e8fcb0SNipun Gupta 
37723e8fcb0SNipun Gupta 	/* prepare command */
37823e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
37923e8fcb0SNipun Gupta 					  cmd_flags,
38023e8fcb0SNipun Gupta 					  token);
38123e8fcb0SNipun Gupta 	cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
38223e8fcb0SNipun Gupta 	cmd_params->priority = priority;
383b4a63e60SHemant Agrawal 	cmd_params->queue_idx = queue_idx;
38423e8fcb0SNipun Gupta 
38523e8fcb0SNipun Gupta 	/* send command to mc*/
38623e8fcb0SNipun Gupta 	err = mc_send_command(mc_io, &cmd);
38723e8fcb0SNipun Gupta 	if (err)
38823e8fcb0SNipun Gupta 		return err;
38923e8fcb0SNipun Gupta 
39023e8fcb0SNipun Gupta 	/* retrieve response parameters */
39123e8fcb0SNipun Gupta 	rsp_params = (struct dpdmai_rsp_get_rx_queue *)cmd.params;
39223e8fcb0SNipun Gupta 	attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
39323e8fcb0SNipun Gupta 	attr->fqid = le32_to_cpu(rsp_params->fqid);
39423e8fcb0SNipun Gupta 	attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
39523e8fcb0SNipun Gupta 	attr->dest_cfg.priority = le32_to_cpu(rsp_params->dest_priority);
39623e8fcb0SNipun Gupta 	attr->dest_cfg.dest_type = dpdmai_get_field(rsp_params->dest_type,
39723e8fcb0SNipun Gupta 						    DEST_TYPE);
39823e8fcb0SNipun Gupta 
39923e8fcb0SNipun Gupta 	return 0;
40023e8fcb0SNipun Gupta }
40123e8fcb0SNipun Gupta 
40223e8fcb0SNipun Gupta /**
40323e8fcb0SNipun Gupta  * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
40423e8fcb0SNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
40523e8fcb0SNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
40623e8fcb0SNipun Gupta  * @token:	Token of DPDMAI object
407b4a63e60SHemant Agrawal  * @queue_idx: Tx queue index. Accepted values are form 0 to num_queues
408b4a63e60SHemant Agrawal  *		parameter provided in dpdmai_create
40923e8fcb0SNipun Gupta  * @priority:	Select the queue relative to number of
41023e8fcb0SNipun Gupta  *		priorities configured at DPDMAI creation
41123e8fcb0SNipun Gupta  * @attr:	Returned Tx queue attributes
41223e8fcb0SNipun Gupta  *
41323e8fcb0SNipun Gupta  * Return:	'0' on Success; Error code otherwise.
41423e8fcb0SNipun Gupta  */
dpdmai_get_tx_queue(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,uint8_t queue_idx,uint8_t priority,struct dpdmai_tx_queue_attr * attr)41523e8fcb0SNipun Gupta int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
41623e8fcb0SNipun Gupta 			uint32_t cmd_flags,
41723e8fcb0SNipun Gupta 			uint16_t token,
418b4a63e60SHemant Agrawal 			uint8_t queue_idx,
41923e8fcb0SNipun Gupta 			uint8_t priority,
42023e8fcb0SNipun Gupta 			struct dpdmai_tx_queue_attr *attr)
42123e8fcb0SNipun Gupta {
42223e8fcb0SNipun Gupta 	struct dpdmai_cmd_get_queue *cmd_params;
42323e8fcb0SNipun Gupta 	struct dpdmai_rsp_get_tx_queue *rsp_params;
42423e8fcb0SNipun Gupta 	struct mc_command cmd = { 0 };
42523e8fcb0SNipun Gupta 	int err;
42623e8fcb0SNipun Gupta 
42723e8fcb0SNipun Gupta 	/* prepare command */
42823e8fcb0SNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
42923e8fcb0SNipun Gupta 					  cmd_flags,
43023e8fcb0SNipun Gupta 					  token);
43123e8fcb0SNipun Gupta 	cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
43223e8fcb0SNipun Gupta 	cmd_params->priority = priority;
433b4a63e60SHemant Agrawal 	cmd_params->queue_idx = queue_idx;
43423e8fcb0SNipun Gupta 
43523e8fcb0SNipun Gupta 	/* send command to mc*/
43623e8fcb0SNipun Gupta 	err = mc_send_command(mc_io, &cmd);
43723e8fcb0SNipun Gupta 	if (err)
43823e8fcb0SNipun Gupta 		return err;
43923e8fcb0SNipun Gupta 
44023e8fcb0SNipun Gupta 	/* retrieve response parameters */
44123e8fcb0SNipun Gupta 	rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
44223e8fcb0SNipun Gupta 	attr->fqid = le32_to_cpu(rsp_params->fqid);
44323e8fcb0SNipun Gupta 
44423e8fcb0SNipun Gupta 	return 0;
44523e8fcb0SNipun Gupta }
446