xref: /dpdk/drivers/net/dpaa2/mc/dpni.c (revision ab3dec55a56d6db3e0f7b8859d1bda31e1e43300)
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  * Copyright 2016 NXP
5  *
6  */
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
9 #include <fsl_dpni.h>
10 #include <fsl_dpni_cmd.h>
11 
12 /**
13  * dpni_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  * @dpni_id:	DPNI 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 dpni_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 dpni_open(struct fsl_mc_io *mc_io,
30 	      uint32_t cmd_flags,
31 	      int dpni_id,
32 	      uint16_t *token)
33 {
34 	struct mc_command cmd = { 0 };
35 	struct dpni_cmd_open *cmd_params;
36 
37 	int err;
38 
39 	/* prepare command */
40 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
41 					  cmd_flags,
42 					  0);
43 	cmd_params = (struct dpni_cmd_open *)cmd.params;
44 	cmd_params->dpni_id = cpu_to_le32(dpni_id);
45 
46 	/* send command to mc*/
47 	err = mc_send_command(mc_io, &cmd);
48 	if (err)
49 		return err;
50 
51 	/* retrieve response parameters */
52 	*token = mc_cmd_hdr_read_token(&cmd);
53 
54 	return 0;
55 }
56 
57 /**
58  * dpni_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 DPNI 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 dpni_close(struct fsl_mc_io *mc_io,
69 	       uint32_t cmd_flags,
70 	       uint16_t token)
71 {
72 	struct mc_command cmd = { 0 };
73 
74 	/* prepare command */
75 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
76 					  cmd_flags,
77 					  token);
78 
79 	/* send command to mc*/
80 	return mc_send_command(mc_io, &cmd);
81 }
82 
83 /**
84  * dpni_create() - Create the DPNI object
85  * @mc_io:	Pointer to MC portal's I/O object
86  * @dprc_token:	Parent container token; '0' for default container
87  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
88  * @cfg:	Configuration structure
89  * @obj_id:	Returned object id
90  *
91  * Create the DPNI object, allocate required resources and
92  * perform required initialization.
93  *
94  * The object can be created either by declaring it in the
95  * DPL file, or by calling this function.
96  *
97  * The function accepts an authentication token of a parent
98  * container that this object should be assigned to. The token
99  * can be '0' so the object will be assigned to the default container.
100  * The newly created object can be opened with the returned
101  * object id and using the container's associated tokens and MC portals.
102  *
103  * Return:	'0' on Success; Error code otherwise.
104  */
105 int dpni_create(struct fsl_mc_io *mc_io,
106 		uint16_t dprc_token,
107 		uint32_t cmd_flags,
108 		const struct dpni_cfg *cfg,
109 		uint32_t *obj_id)
110 {
111 	struct dpni_cmd_create *cmd_params;
112 	struct mc_command cmd = { 0 };
113 	int err;
114 
115 	/* prepare command */
116 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
117 					  cmd_flags,
118 					  dprc_token);
119 	cmd_params = (struct dpni_cmd_create *)cmd.params;
120 	cmd_params->options = cpu_to_le32(cfg->options);
121 	cmd_params->num_queues = cfg->num_queues;
122 	cmd_params->num_tcs = cfg->num_tcs;
123 	cmd_params->mac_filter_entries = cfg->mac_filter_entries;
124 	cmd_params->num_rx_tcs = cfg->num_rx_tcs;
125 	cmd_params->vlan_filter_entries =  cfg->vlan_filter_entries;
126 	cmd_params->qos_entries = cfg->qos_entries;
127 	cmd_params->fs_entries = cpu_to_le16(cfg->fs_entries);
128 
129 	/* send command to mc*/
130 	err = mc_send_command(mc_io, &cmd);
131 	if (err)
132 		return err;
133 
134 	/* retrieve response parameters */
135 	*obj_id = mc_cmd_read_object_id(&cmd);
136 
137 	return 0;
138 }
139 
140 /**
141  * dpni_destroy() - Destroy the DPNI object and release all its resources.
142  * @mc_io:	Pointer to MC portal's I/O object
143  * @dprc_token: Parent container token; '0' for default container
144  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
145  * @object_id:	The object id; it must be a valid id within the container that
146  * created this object;
147  *
148  * The function accepts the authentication token of the parent container that
149  * created the object (not the one that currently owns the object). The object
150  * is searched within parent using the provided 'object_id'.
151  * All tokens to the object must be closed before calling destroy.
152  *
153  * Return:	'0' on Success; error code otherwise.
154  */
155 int dpni_destroy(struct fsl_mc_io *mc_io,
156 		 uint16_t dprc_token,
157 		 uint32_t cmd_flags,
158 		 uint32_t object_id)
159 {
160 	struct dpni_cmd_destroy *cmd_params;
161 	struct mc_command cmd = { 0 };
162 
163 	/* prepare command */
164 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
165 					  cmd_flags,
166 					  dprc_token);
167 	/* set object id to destroy */
168 	cmd_params = (struct dpni_cmd_destroy *)cmd.params;
169 	cmd_params->dpsw_id = cpu_to_le32(object_id);
170 
171 	/* send command to mc*/
172 	return mc_send_command(mc_io, &cmd);
173 }
174 
175 /**
176  * dpni_set_pools() - Set buffer pools configuration
177  * @mc_io:	Pointer to MC portal's I/O object
178  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
179  * @token:	Token of DPNI object
180  * @cfg:	Buffer pools configuration
181  *
182  * mandatory for DPNI operation
183  * warning:Allowed only when DPNI is disabled
184  *
185  * Return:	'0' on Success; Error code otherwise.
186  */
187 int dpni_set_pools(struct fsl_mc_io *mc_io,
188 		   uint32_t cmd_flags,
189 		   uint16_t token,
190 		   const struct dpni_pools_cfg *cfg)
191 {
192 	struct mc_command cmd = { 0 };
193 	struct dpni_cmd_set_pools *cmd_params;
194 	int i;
195 
196 	/* prepare command */
197 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
198 					  cmd_flags,
199 					  token);
200 	cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
201 	cmd_params->num_dpbp = cfg->num_dpbp;
202 	for (i = 0; i < cmd_params->num_dpbp; i++) {
203 		cmd_params->pool[i].dpbp_id =
204 			cpu_to_le16(cfg->pools[i].dpbp_id);
205 		cmd_params->pool[i].priority_mask =
206 			cfg->pools[i].priority_mask;
207 		cmd_params->buffer_size[i] =
208 			cpu_to_le16(cfg->pools[i].buffer_size);
209 		cmd_params->backup_pool_mask |=
210 			DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
211 	}
212 
213 	/* send command to mc*/
214 	return mc_send_command(mc_io, &cmd);
215 }
216 
217 /**
218  * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
219  * @mc_io:	Pointer to MC portal's I/O object
220  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
221  * @token:	Token of DPNI object
222  *
223  * Return:	'0' on Success; Error code otherwise.
224  */
225 int dpni_enable(struct fsl_mc_io *mc_io,
226 		uint32_t cmd_flags,
227 		uint16_t token)
228 {
229 	struct mc_command cmd = { 0 };
230 
231 	/* prepare command */
232 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
233 					  cmd_flags,
234 					  token);
235 
236 	/* send command to mc*/
237 	return mc_send_command(mc_io, &cmd);
238 }
239 
240 /**
241  * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
242  * @mc_io:	Pointer to MC portal's I/O object
243  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
244  * @token:	Token of DPNI object
245  *
246  * Return:	'0' on Success; Error code otherwise.
247  */
248 int dpni_disable(struct fsl_mc_io *mc_io,
249 		 uint32_t cmd_flags,
250 		 uint16_t token)
251 {
252 	struct mc_command cmd = { 0 };
253 
254 	/* prepare command */
255 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
256 					  cmd_flags,
257 					  token);
258 
259 	/* send command to mc*/
260 	return mc_send_command(mc_io, &cmd);
261 }
262 
263 /**
264  * dpni_is_enabled() - Check if the DPNI is enabled.
265  * @mc_io:	Pointer to MC portal's I/O object
266  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
267  * @token:	Token of DPNI object
268  * @en:		Returns '1' if object is enabled; '0' otherwise
269  *
270  * Return:	'0' on Success; Error code otherwise.
271  */
272 int dpni_is_enabled(struct fsl_mc_io *mc_io,
273 		    uint32_t cmd_flags,
274 		    uint16_t token,
275 		    int *en)
276 {
277 	struct mc_command cmd = { 0 };
278 	struct dpni_rsp_is_enabled *rsp_params;
279 	int err;
280 
281 	/* prepare command */
282 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
283 					  cmd_flags,
284 					  token);
285 
286 	/* send command to mc*/
287 	err = mc_send_command(mc_io, &cmd);
288 	if (err)
289 		return err;
290 
291 	/* retrieve response parameters */
292 	rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
293 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
294 
295 	return 0;
296 }
297 
298 /**
299  * dpni_reset() - Reset the DPNI, returns the object to initial state.
300  * @mc_io:	Pointer to MC portal's I/O object
301  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
302  * @token:	Token of DPNI object
303  *
304  * Return:	'0' on Success; Error code otherwise.
305  */
306 int dpni_reset(struct fsl_mc_io *mc_io,
307 	       uint32_t cmd_flags,
308 	       uint16_t token)
309 {
310 	struct mc_command cmd = { 0 };
311 
312 	/* prepare command */
313 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
314 					  cmd_flags,
315 					  token);
316 
317 	/* send command to mc*/
318 	return mc_send_command(mc_io, &cmd);
319 }
320 
321 /**
322  * dpni_set_irq_enable() - Set overall interrupt state.
323  * @mc_io:	Pointer to MC portal's I/O object
324  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
325  * @token:	Token of DPNI object
326  * @irq_index:	The interrupt index to configure
327  * @en:		Interrupt state: - enable = 1, disable = 0
328  *
329  * Allows GPP software to control when interrupts are generated.
330  * Each interrupt can have up to 32 causes.  The enable/disable control's the
331  * overall interrupt state. if the interrupt is disabled no causes will cause
332  * an interrupt.
333  *
334  * Return:	'0' on Success; Error code otherwise.
335  */
336 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
337 			uint32_t cmd_flags,
338 			uint16_t token,
339 			uint8_t irq_index,
340 			uint8_t en)
341 {
342 	struct mc_command cmd = { 0 };
343 	struct dpni_cmd_set_irq_enable *cmd_params;
344 
345 	/* prepare command */
346 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
347 					  cmd_flags,
348 					  token);
349 	cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
350 	dpni_set_field(cmd_params->enable, ENABLE, en);
351 	cmd_params->irq_index = irq_index;
352 
353 	/* send command to mc*/
354 	return mc_send_command(mc_io, &cmd);
355 }
356 
357 /**
358  * dpni_get_irq_enable() - Get overall interrupt state
359  * @mc_io:	Pointer to MC portal's I/O object
360  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
361  * @token:	Token of DPNI object
362  * @irq_index:	The interrupt index to configure
363  * @en:		Returned interrupt state - enable = 1, disable = 0
364  *
365  * Return:	'0' on Success; Error code otherwise.
366  */
367 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
368 			uint32_t cmd_flags,
369 			uint16_t token,
370 			uint8_t irq_index,
371 			uint8_t *en)
372 {
373 	struct mc_command cmd = { 0 };
374 	struct dpni_cmd_get_irq_enable *cmd_params;
375 	struct dpni_rsp_get_irq_enable *rsp_params;
376 
377 	int err;
378 
379 	/* prepare command */
380 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
381 					  cmd_flags,
382 					  token);
383 	cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
384 	cmd_params->irq_index = irq_index;
385 
386 	/* send command to mc*/
387 	err = mc_send_command(mc_io, &cmd);
388 	if (err)
389 		return err;
390 
391 	/* retrieve response parameters */
392 	rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
393 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
394 
395 	return 0;
396 }
397 
398 /**
399  * dpni_set_irq_mask() - Set interrupt mask.
400  * @mc_io:	Pointer to MC portal's I/O object
401  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
402  * @token:	Token of DPNI object
403  * @irq_index:	The interrupt index to configure
404  * @mask:	Event mask to trigger interrupt;
405  *		each bit:
406  *			0 = ignore event
407  *			1 = consider event for asserting IRQ
408  *
409  * Every interrupt can have up to 32 causes and the interrupt model supports
410  * masking/unmasking each cause independently
411  *
412  * Return:	'0' on Success; Error code otherwise.
413  */
414 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
415 		      uint32_t cmd_flags,
416 		      uint16_t token,
417 		      uint8_t irq_index,
418 		      uint32_t mask)
419 {
420 	struct mc_command cmd = { 0 };
421 	struct dpni_cmd_set_irq_mask *cmd_params;
422 
423 	/* prepare command */
424 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
425 					  cmd_flags,
426 					  token);
427 	cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
428 	cmd_params->mask = cpu_to_le32(mask);
429 	cmd_params->irq_index = irq_index;
430 
431 	/* send command to mc*/
432 	return mc_send_command(mc_io, &cmd);
433 }
434 
435 /**
436  * dpni_get_irq_mask() - Get interrupt mask.
437  * @mc_io:	Pointer to MC portal's I/O object
438  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
439  * @token:	Token of DPNI object
440  * @irq_index:	The interrupt index to configure
441  * @mask:	Returned event mask to trigger interrupt
442  *
443  * Every interrupt can have up to 32 causes and the interrupt model supports
444  * masking/unmasking each cause independently
445  *
446  * Return:	'0' on Success; Error code otherwise.
447  */
448 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
449 		      uint32_t cmd_flags,
450 		      uint16_t token,
451 		      uint8_t irq_index,
452 		      uint32_t *mask)
453 {
454 	struct mc_command cmd = { 0 };
455 	struct dpni_cmd_get_irq_mask *cmd_params;
456 	struct dpni_rsp_get_irq_mask *rsp_params;
457 	int err;
458 
459 	/* prepare command */
460 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
461 					  cmd_flags,
462 					  token);
463 	cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
464 	cmd_params->irq_index = irq_index;
465 
466 	/* send command to mc*/
467 	err = mc_send_command(mc_io, &cmd);
468 	if (err)
469 		return err;
470 
471 	/* retrieve response parameters */
472 	rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
473 	*mask = le32_to_cpu(rsp_params->mask);
474 
475 	return 0;
476 }
477 
478 /**
479  * dpni_get_irq_status() - Get the current status of any pending interrupts.
480  * @mc_io:	Pointer to MC portal's I/O object
481  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
482  * @token:	Token of DPNI object
483  * @irq_index:	The interrupt index to configure
484  * @status:	Returned interrupts status - one bit per cause:
485  *			0 = no interrupt pending
486  *			1 = interrupt pending
487  *
488  * Return:	'0' on Success; Error code otherwise.
489  */
490 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
491 			uint32_t cmd_flags,
492 			uint16_t token,
493 			uint8_t irq_index,
494 			uint32_t *status)
495 {
496 	struct mc_command cmd = { 0 };
497 	struct dpni_cmd_get_irq_status *cmd_params;
498 	struct dpni_rsp_get_irq_status *rsp_params;
499 	int err;
500 
501 	/* prepare command */
502 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
503 					  cmd_flags,
504 					  token);
505 	cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
506 	cmd_params->status = cpu_to_le32(*status);
507 	cmd_params->irq_index = irq_index;
508 
509 	/* send command to mc*/
510 	err = mc_send_command(mc_io, &cmd);
511 	if (err)
512 		return err;
513 
514 	/* retrieve response parameters */
515 	rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
516 	*status = le32_to_cpu(rsp_params->status);
517 
518 	return 0;
519 }
520 
521 /**
522  * dpni_clear_irq_status() - Clear a pending interrupt's status
523  * @mc_io:	Pointer to MC portal's I/O object
524  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
525  * @token:	Token of DPNI object
526  * @irq_index:	The interrupt index to configure
527  * @status:	bits to clear (W1C) - one bit per cause:
528  *			0 = don't change
529  *			1 = clear status bit
530  *
531  * Return:	'0' on Success; Error code otherwise.
532  */
533 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
534 			  uint32_t cmd_flags,
535 			  uint16_t token,
536 			  uint8_t irq_index,
537 			  uint32_t status)
538 {
539 	struct mc_command cmd = { 0 };
540 	struct dpni_cmd_clear_irq_status *cmd_params;
541 
542 	/* prepare command */
543 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
544 					  cmd_flags,
545 					  token);
546 	cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
547 	cmd_params->irq_index = irq_index;
548 	cmd_params->status = cpu_to_le32(status);
549 
550 	/* send command to mc*/
551 	return mc_send_command(mc_io, &cmd);
552 }
553 
554 /**
555  * dpni_get_attributes() - Retrieve DPNI attributes.
556  * @mc_io:	Pointer to MC portal's I/O object
557  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
558  * @token:	Token of DPNI object
559  * @attr:	Object's attributes
560  *
561  * Return:	'0' on Success; Error code otherwise.
562  */
563 int dpni_get_attributes(struct fsl_mc_io *mc_io,
564 			uint32_t cmd_flags,
565 			uint16_t token,
566 			struct dpni_attr *attr)
567 {
568 	struct mc_command cmd = { 0 };
569 	struct dpni_rsp_get_attr *rsp_params;
570 
571 	int err;
572 
573 	/* prepare command */
574 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
575 					  cmd_flags,
576 					  token);
577 
578 	/* send command to mc*/
579 	err = mc_send_command(mc_io, &cmd);
580 	if (err)
581 		return err;
582 
583 	/* retrieve response parameters */
584 	rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
585 	attr->options = le32_to_cpu(rsp_params->options);
586 	attr->num_queues = rsp_params->num_queues;
587 	attr->num_rx_tcs = rsp_params->num_rx_tcs;
588 	attr->num_tx_tcs = rsp_params->num_tx_tcs;
589 	attr->mac_filter_entries = rsp_params->mac_filter_entries;
590 	attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
591 	attr->qos_entries = rsp_params->qos_entries;
592 	attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
593 	attr->qos_key_size = rsp_params->qos_key_size;
594 	attr->fs_key_size = rsp_params->fs_key_size;
595 	attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
596 
597 	return 0;
598 }
599 
600 /**
601  * dpni_set_errors_behavior() - Set errors behavior
602  * @mc_io:	Pointer to MC portal's I/O object
603  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
604  * @token:	Token of DPNI object
605  * @cfg:	Errors configuration
606  *
607  * This function may be called numerous times with different
608  * error masks
609  *
610  * Return:	'0' on Success; Error code otherwise.
611  */
612 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
613 			     uint32_t cmd_flags,
614 			     uint16_t token,
615 			     struct dpni_error_cfg *cfg)
616 {
617 	struct mc_command cmd = { 0 };
618 	struct dpni_cmd_set_errors_behavior *cmd_params;
619 
620 	/* prepare command */
621 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
622 					  cmd_flags,
623 					  token);
624 	cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
625 	cmd_params->errors = cpu_to_le32(cfg->errors);
626 	dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
627 	dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
628 
629 	/* send command to mc*/
630 	return mc_send_command(mc_io, &cmd);
631 }
632 
633 /**
634  * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
635  * @mc_io:	Pointer to MC portal's I/O object
636  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
637  * @token:	Token of DPNI object
638  * @qtype:	Type of queue to retrieve configuration for
639  * @layout:	Returns buffer layout attributes
640  *
641  * Return:	'0' on Success; Error code otherwise.
642  */
643 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
644 			   uint32_t cmd_flags,
645 			   uint16_t token,
646 			   enum dpni_queue_type qtype,
647 			   struct dpni_buffer_layout *layout)
648 {
649 	struct mc_command cmd = { 0 };
650 	struct dpni_cmd_get_buffer_layout *cmd_params;
651 	struct dpni_rsp_get_buffer_layout *rsp_params;
652 	int err;
653 
654 	/* prepare command */
655 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
656 					  cmd_flags,
657 					  token);
658 	cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
659 	cmd_params->qtype = qtype;
660 
661 	/* send command to mc*/
662 	err = mc_send_command(mc_io, &cmd);
663 	if (err)
664 		return err;
665 
666 	/* retrieve response parameters */
667 	rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
668 	layout->pass_timestamp =
669 				(int)dpni_get_field(rsp_params->flags, PASS_TS);
670 	layout->pass_parser_result =
671 				(int)dpni_get_field(rsp_params->flags, PASS_PR);
672 	layout->pass_frame_status =
673 				(int)dpni_get_field(rsp_params->flags, PASS_FS);
674 	layout->pass_sw_opaque =
675 			(int)dpni_get_field(rsp_params->flags, PASS_SWO);
676 	layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
677 	layout->data_align = le16_to_cpu(rsp_params->data_align);
678 	layout->data_head_room = le16_to_cpu(rsp_params->head_room);
679 	layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
680 
681 	return 0;
682 }
683 
684 /**
685  * dpni_set_buffer_layout() - Set buffer layout configuration.
686  * @mc_io:	Pointer to MC portal's I/O object
687  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
688  * @token:	Token of DPNI object
689  * @qtype:	Type of queue this configuration applies to
690  * @layout:	Buffer layout configuration
691  *
692  * Return:	'0' on Success; Error code otherwise.
693  *
694  * @warning	Allowed only when DPNI is disabled
695  */
696 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
697 			   uint32_t cmd_flags,
698 			   uint16_t token,
699 			   enum dpni_queue_type qtype,
700 			   const struct dpni_buffer_layout *layout)
701 {
702 	struct mc_command cmd = { 0 };
703 	struct dpni_cmd_set_buffer_layout *cmd_params;
704 
705 	/* prepare command */
706 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
707 					  cmd_flags,
708 					  token);
709 	cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
710 	cmd_params->qtype = qtype;
711 	cmd_params->options = cpu_to_le16((uint16_t)layout->options);
712 	dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
713 	dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
714 	dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
715 	dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
716 	cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
717 	cmd_params->data_align = cpu_to_le16(layout->data_align);
718 	cmd_params->head_room = cpu_to_le16(layout->data_head_room);
719 	cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
720 
721 	/* send command to mc*/
722 	return mc_send_command(mc_io, &cmd);
723 }
724 
725 /**
726  * dpni_set_offload() - Set DPNI offload configuration.
727  * @mc_io:	Pointer to MC portal's I/O object
728  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
729  * @token:	Token of DPNI object
730  * @type:	Type of DPNI offload
731  * @config:	Offload configuration.
732  *		For checksum offloads, non-zero value enables the offload
733  *
734  * Return:     '0' on Success; Error code otherwise.
735  *
736  * @warning    Allowed only when DPNI is disabled
737  */
738 
739 int dpni_set_offload(struct fsl_mc_io *mc_io,
740 		     uint32_t cmd_flags,
741 		     uint16_t token,
742 		     enum dpni_offload type,
743 		     uint32_t config)
744 {
745 	struct mc_command cmd = { 0 };
746 	struct dpni_cmd_set_offload *cmd_params;
747 
748 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
749 					  cmd_flags,
750 					  token);
751 	cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
752 	cmd_params->dpni_offload = type;
753 	cmd_params->config = cpu_to_le32(config);
754 
755 	return mc_send_command(mc_io, &cmd);
756 }
757 
758 /**
759  * dpni_get_offload() - Get DPNI offload configuration.
760  * @mc_io:	Pointer to MC portal's I/O object
761  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
762  * @token:	Token of DPNI object
763  * @type:	Type of DPNI offload
764  * @config:	Offload configuration.
765  *			For checksum offloads, a value of 1 indicates that the
766  *			offload is enabled.
767  *
768  * Return:	'0' on Success; Error code otherwise.
769  *
770  * @warning	Allowed only when DPNI is disabled
771  */
772 int dpni_get_offload(struct fsl_mc_io *mc_io,
773 		     uint32_t cmd_flags,
774 		     uint16_t token,
775 		     enum dpni_offload type,
776 		     uint32_t *config)
777 {
778 	struct mc_command cmd = { 0 };
779 	struct dpni_cmd_get_offload *cmd_params;
780 	struct dpni_rsp_get_offload *rsp_params;
781 	int err;
782 
783 	/* prepare command */
784 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
785 					  cmd_flags,
786 					  token);
787 	cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
788 	cmd_params->dpni_offload = type;
789 
790 	/* send command to mc*/
791 	err = mc_send_command(mc_io, &cmd);
792 	if (err)
793 		return err;
794 
795 	/* retrieve response parameters */
796 	rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
797 	*config = le32_to_cpu(rsp_params->config);
798 
799 	return 0;
800 }
801 
802 /**
803  * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
804  *			for enqueue operations
805  * @mc_io:	Pointer to MC portal's I/O object
806  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
807  * @token:	Token of DPNI object
808  * @qtype:	Type of queue to receive QDID for
809  * @qdid:	Returned virtual QDID value that should be used as an argument
810  *			in all enqueue operations
811  *
812  * Return:	'0' on Success; Error code otherwise.
813  */
814 int dpni_get_qdid(struct fsl_mc_io *mc_io,
815 		  uint32_t cmd_flags,
816 		  uint16_t token,
817 		  enum dpni_queue_type qtype,
818 		  uint16_t *qdid)
819 {
820 	struct mc_command cmd = { 0 };
821 	struct dpni_cmd_get_qdid *cmd_params;
822 	struct dpni_rsp_get_qdid *rsp_params;
823 	int err;
824 
825 	/* prepare command */
826 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
827 					  cmd_flags,
828 					  token);
829 	cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
830 	cmd_params->qtype = qtype;
831 
832 	/* send command to mc*/
833 	err = mc_send_command(mc_io, &cmd);
834 	if (err)
835 		return err;
836 
837 	/* retrieve response parameters */
838 	rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
839 	*qdid = le16_to_cpu(rsp_params->qdid);
840 
841 	return 0;
842 }
843 
844 /**
845  * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
846  * @mc_io:	Pointer to MC portal's I/O object
847  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
848  * @token:	Token of DPNI object
849  * @data_offset: Tx data offset (from start of buffer)
850  *
851  * Return:	'0' on Success; Error code otherwise.
852  */
853 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
854 			    uint32_t cmd_flags,
855 			    uint16_t token,
856 			    uint16_t *data_offset)
857 {
858 	struct mc_command cmd = { 0 };
859 	struct dpni_rsp_get_tx_data_offset *rsp_params;
860 	int err;
861 
862 	/* prepare command */
863 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
864 					  cmd_flags,
865 					  token);
866 
867 	/* send command to mc*/
868 	err = mc_send_command(mc_io, &cmd);
869 	if (err)
870 		return err;
871 
872 	/* retrieve response parameters */
873 	rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
874 	*data_offset = le16_to_cpu(rsp_params->data_offset);
875 
876 	return 0;
877 }
878 
879 /**
880  * dpni_set_link_cfg() - set the link configuration.
881  * @mc_io:	Pointer to MC portal's I/O object
882  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
883  * @token:	Token of DPNI object
884  * @cfg:	Link configuration
885  *
886  * Return:	'0' on Success; Error code otherwise.
887  */
888 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
889 		      uint32_t cmd_flags,
890 		      uint16_t token,
891 		      const struct dpni_link_cfg *cfg)
892 {
893 	struct mc_command cmd = { 0 };
894 	struct dpni_cmd_set_link_cfg *cmd_params;
895 
896 	/* prepare command */
897 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
898 					  cmd_flags,
899 					  token);
900 	cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
901 	cmd_params->rate = cpu_to_le32(cfg->rate);
902 	cmd_params->options = cpu_to_le64(cfg->options);
903 	cmd_params->advertising = cpu_to_le64(cfg->advertising);
904 
905 	/* send command to mc*/
906 	return mc_send_command(mc_io, &cmd);
907 }
908 
909 /**
910  * dpni_get_link_state() - Return the link state (either up or down)
911  * @mc_io:	Pointer to MC portal's I/O object
912  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
913  * @token:	Token of DPNI object
914  * @state:	Returned link state;
915  *
916  * Return:	'0' on Success; Error code otherwise.
917  */
918 int dpni_get_link_state(struct fsl_mc_io *mc_io,
919 			uint32_t cmd_flags,
920 			uint16_t token,
921 			struct dpni_link_state *state)
922 {
923 	struct mc_command cmd = { 0 };
924 	struct dpni_rsp_get_link_state *rsp_params;
925 	int err;
926 
927 	/* prepare command */
928 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
929 					  cmd_flags,
930 					  token);
931 
932 	/* send command to mc*/
933 	err = mc_send_command(mc_io, &cmd);
934 	if (err)
935 		return err;
936 
937 	/* retrieve response parameters */
938 	rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
939 	state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
940 	state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
941 	state->rate = le32_to_cpu(rsp_params->rate);
942 	state->options = le64_to_cpu(rsp_params->options);
943 	state->supported = le64_to_cpu(rsp_params->supported);
944 	state->advertising = le64_to_cpu(rsp_params->advertising);
945 
946 	return 0;
947 }
948 
949 /**
950  * dpni_set_max_frame_length() - Set the maximum received frame length.
951  * @mc_io:		Pointer to MC portal's I/O object
952  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
953  * @token:		Token of DPNI object
954  * @max_frame_length:	Maximum received frame length (in bytes);
955  *			frame is discarded if its length exceeds this value
956  *
957  * Return:	'0' on Success; Error code otherwise.
958  */
959 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
960 			      uint32_t cmd_flags,
961 			      uint16_t token,
962 			      uint16_t max_frame_length)
963 {
964 	struct mc_command cmd = { 0 };
965 	struct dpni_cmd_set_max_frame_length *cmd_params;
966 
967 	/* prepare command */
968 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
969 					  cmd_flags,
970 					  token);
971 	cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
972 	cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
973 
974 	/* send command to mc*/
975 	return mc_send_command(mc_io, &cmd);
976 }
977 
978 /**
979  * dpni_get_max_frame_length() - Get the maximum received frame length.
980  * @mc_io:		Pointer to MC portal's I/O object
981  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
982  * @token:		Token of DPNI object
983  * @max_frame_length:	Maximum received frame length (in bytes);
984  *			frame is discarded if its length exceeds this value
985  *
986  * Return:	'0' on Success; Error code otherwise.
987  */
988 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
989 			      uint32_t cmd_flags,
990 			      uint16_t token,
991 			      uint16_t *max_frame_length)
992 {
993 	struct mc_command cmd = { 0 };
994 	struct dpni_rsp_get_max_frame_length *rsp_params;
995 	int err;
996 
997 	/* prepare command */
998 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
999 					  cmd_flags,
1000 					  token);
1001 
1002 	/* send command to mc*/
1003 	err = mc_send_command(mc_io, &cmd);
1004 	if (err)
1005 		return err;
1006 
1007 	/* retrieve response parameters */
1008 	rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1009 	*max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1010 
1011 	return 0;
1012 }
1013 
1014 /**
1015  * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1016  * @mc_io:	Pointer to MC portal's I/O object
1017  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1018  * @token:	Token of DPNI object
1019  * @en:		Set to '1' to enable; '0' to disable
1020  *
1021  * Return:	'0' on Success; Error code otherwise.
1022  */
1023 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1024 			       uint32_t cmd_flags,
1025 			       uint16_t token,
1026 			       int en)
1027 {
1028 	struct mc_command cmd = { 0 };
1029 	struct dpni_cmd_set_multicast_promisc *cmd_params;
1030 
1031 	/* prepare command */
1032 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1033 					  cmd_flags,
1034 					  token);
1035 	cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1036 	dpni_set_field(cmd_params->enable, ENABLE, en);
1037 
1038 	/* send command to mc*/
1039 	return mc_send_command(mc_io, &cmd);
1040 }
1041 
1042 /**
1043  * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1044  * @mc_io:	Pointer to MC portal's I/O object
1045  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1046  * @token:	Token of DPNI object
1047  * @en:		Returns '1' if enabled; '0' otherwise
1048  *
1049  * Return:	'0' on Success; Error code otherwise.
1050  */
1051 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1052 			       uint32_t cmd_flags,
1053 			       uint16_t token,
1054 			       int *en)
1055 {
1056 	struct mc_command cmd = { 0 };
1057 	struct dpni_rsp_get_multicast_promisc *rsp_params;
1058 	int err;
1059 
1060 	/* prepare command */
1061 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1062 					  cmd_flags,
1063 					  token);
1064 
1065 	/* send command to mc*/
1066 	err = mc_send_command(mc_io, &cmd);
1067 	if (err)
1068 		return err;
1069 
1070 	/* retrieve response parameters */
1071 	rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1072 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
1073 
1074 	return 0;
1075 }
1076 
1077 /**
1078  * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1079  * @mc_io:	Pointer to MC portal's I/O object
1080  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1081  * @token:	Token of DPNI object
1082  * @en:		Set to '1' to enable; '0' to disable
1083  *
1084  * Return:	'0' on Success; Error code otherwise.
1085  */
1086 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1087 			     uint32_t cmd_flags,
1088 			     uint16_t token,
1089 			     int en)
1090 {
1091 	struct mc_command cmd = { 0 };
1092 	struct dpni_cmd_set_unicast_promisc *cmd_params;
1093 
1094 	/* prepare command */
1095 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1096 					  cmd_flags,
1097 					  token);
1098 	cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1099 	dpni_set_field(cmd_params->enable, ENABLE, en);
1100 
1101 	/* send command to mc*/
1102 	return mc_send_command(mc_io, &cmd);
1103 }
1104 
1105 /**
1106  * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1107  * @mc_io:	Pointer to MC portal's I/O object
1108  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1109  * @token:	Token of DPNI object
1110  * @en:		Returns '1' if enabled; '0' otherwise
1111  *
1112  * Return:	'0' on Success; Error code otherwise.
1113  */
1114 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1115 			     uint32_t cmd_flags,
1116 			     uint16_t token,
1117 			     int *en)
1118 {
1119 	struct mc_command cmd = { 0 };
1120 	struct dpni_rsp_get_unicast_promisc *rsp_params;
1121 	int err;
1122 
1123 	/* prepare command */
1124 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1125 					  cmd_flags,
1126 					  token);
1127 
1128 	/* send command to mc*/
1129 	err = mc_send_command(mc_io, &cmd);
1130 	if (err)
1131 		return err;
1132 
1133 	/* retrieve response parameters */
1134 	rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1135 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
1136 
1137 	return 0;
1138 }
1139 
1140 /**
1141  * dpni_set_primary_mac_addr() - Set the primary MAC address
1142  * @mc_io:	Pointer to MC portal's I/O object
1143  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1144  * @token:	Token of DPNI object
1145  * @mac_addr:	MAC address to set as primary address
1146  *
1147  * Return:	'0' on Success; Error code otherwise.
1148  */
1149 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1150 			      uint32_t cmd_flags,
1151 			      uint16_t token,
1152 			      const uint8_t mac_addr[6])
1153 {
1154 	struct mc_command cmd = { 0 };
1155 	struct dpni_cmd_set_primary_mac_addr *cmd_params;
1156 	int i;
1157 
1158 	/* prepare command */
1159 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1160 					  cmd_flags,
1161 					  token);
1162 	cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1163 	for (i = 0; i < 6; i++)
1164 		cmd_params->mac_addr[i] = mac_addr[5 - i];
1165 
1166 	/* send command to mc*/
1167 	return mc_send_command(mc_io, &cmd);
1168 }
1169 
1170 /**
1171  * dpni_get_primary_mac_addr() - Get the primary MAC address
1172  * @mc_io:	Pointer to MC portal's I/O object
1173  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1174  * @token:	Token of DPNI object
1175  * @mac_addr:	Returned MAC address
1176  *
1177  * Return:	'0' on Success; Error code otherwise.
1178  */
1179 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1180 			      uint32_t cmd_flags,
1181 			      uint16_t token,
1182 			      uint8_t mac_addr[6])
1183 {
1184 	struct mc_command cmd = { 0 };
1185 	struct dpni_rsp_get_primary_mac_addr *rsp_params;
1186 	int i, err;
1187 
1188 	/* prepare command */
1189 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1190 					  cmd_flags,
1191 					  token);
1192 
1193 	/* send command to mc*/
1194 	err = mc_send_command(mc_io, &cmd);
1195 	if (err)
1196 		return err;
1197 
1198 	/* retrieve response parameters */
1199 	rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1200 	for (i = 0; i < 6; i++)
1201 		mac_addr[5 - i] = rsp_params->mac_addr[i];
1202 
1203 	return 0;
1204 }
1205 
1206 /**
1207  * dpni_add_mac_addr() - Add MAC address filter
1208  * @mc_io:	Pointer to MC portal's I/O object
1209  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1210  * @token:	Token of DPNI object
1211  * @mac_addr:	MAC address to add
1212  *
1213  * Return:	'0' on Success; Error code otherwise.
1214  */
1215 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1216 		      uint32_t cmd_flags,
1217 		      uint16_t token,
1218 		      const uint8_t mac_addr[6])
1219 {
1220 	struct mc_command cmd = { 0 };
1221 	struct dpni_cmd_add_mac_addr *cmd_params;
1222 	int i;
1223 
1224 	/* prepare command */
1225 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1226 					  cmd_flags,
1227 					  token);
1228 	cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1229 	for (i = 0; i < 6; i++)
1230 		cmd_params->mac_addr[i] = mac_addr[5 - i];
1231 
1232 	/* send command to mc*/
1233 	return mc_send_command(mc_io, &cmd);
1234 }
1235 
1236 /**
1237  * dpni_remove_mac_addr() - Remove MAC address filter
1238  * @mc_io:	Pointer to MC portal's I/O object
1239  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1240  * @token:	Token of DPNI object
1241  * @mac_addr:	MAC address to remove
1242  *
1243  * Return:	'0' on Success; Error code otherwise.
1244  */
1245 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1246 			 uint32_t cmd_flags,
1247 			 uint16_t token,
1248 			 const uint8_t mac_addr[6])
1249 {
1250 	struct mc_command cmd = { 0 };
1251 	struct dpni_cmd_remove_mac_addr *cmd_params;
1252 	int i;
1253 
1254 	/* prepare command */
1255 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1256 					  cmd_flags,
1257 					  token);
1258 	cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1259 	for (i = 0; i < 6; i++)
1260 		cmd_params->mac_addr[i] = mac_addr[5 - i];
1261 
1262 	/* send command to mc*/
1263 	return mc_send_command(mc_io, &cmd);
1264 }
1265 
1266 /**
1267  * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1268  * @mc_io:	Pointer to MC portal's I/O object
1269  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1270  * @token:	Token of DPNI object
1271  * @unicast:	Set to '1' to clear unicast addresses
1272  * @multicast:	Set to '1' to clear multicast addresses
1273  *
1274  * The primary MAC address is not cleared by this operation.
1275  *
1276  * Return:	'0' on Success; Error code otherwise.
1277  */
1278 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1279 			   uint32_t cmd_flags,
1280 			   uint16_t token,
1281 			   int unicast,
1282 			   int multicast)
1283 {
1284 	struct mc_command cmd = { 0 };
1285 	struct dpni_cmd_clear_mac_filters *cmd_params;
1286 
1287 	/* prepare command */
1288 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1289 					  cmd_flags,
1290 					  token);
1291 	cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1292 	dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1293 	dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1294 
1295 	/* send command to mc*/
1296 	return mc_send_command(mc_io, &cmd);
1297 }
1298 
1299 /**
1300  * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1301  *			port the DPNI is attached to
1302  * @mc_io:	Pointer to MC portal's I/O object
1303  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1304  * @token:	Token of DPNI object
1305  * @mac_addr:	MAC address of the physical port, if any, otherwise 0
1306  *
1307  * The primary MAC address is not cleared by this operation.
1308  *
1309  * Return:	'0' on Success; Error code otherwise.
1310  */
1311 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1312 			   uint32_t cmd_flags,
1313 			   uint16_t token,
1314 			   uint8_t mac_addr[6])
1315 {
1316 	struct mc_command cmd = { 0 };
1317 	struct dpni_rsp_get_port_mac_addr *rsp_params;
1318 	int i, err;
1319 
1320 	/* prepare command */
1321 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1322 					  cmd_flags,
1323 					  token);
1324 
1325 	/* send command to mc*/
1326 	err = mc_send_command(mc_io, &cmd);
1327 	if (err)
1328 		return err;
1329 
1330 	/* retrieve response parameters */
1331 	rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1332 	for (i = 0; i < 6; i++)
1333 		mac_addr[5 - i] = rsp_params->mac_addr[i];
1334 
1335 	return 0;
1336 }
1337 
1338 /**
1339  * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1340  * @mc_io:	Pointer to MC portal's I/O object
1341  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1342  * @token:	Token of DPNI object
1343  * @en:		Set to '1' to enable; '0' to disable
1344  *
1345  * Return:	'0' on Success; Error code otherwise.
1346  */
1347 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1348 			    uint32_t cmd_flags,
1349 			    uint16_t token,
1350 			    int en)
1351 {
1352 	struct dpni_cmd_enable_vlan_filter *cmd_params;
1353 	struct mc_command cmd = { 0 };
1354 
1355 	/* prepare command */
1356 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1357 					  cmd_flags,
1358 					  token);
1359 	cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1360 	dpni_set_field(cmd_params->en, ENABLE, en);
1361 
1362 	/* send command to mc*/
1363 	return mc_send_command(mc_io, &cmd);
1364 }
1365 
1366 /**
1367  * dpni_add_vlan_id() - Add VLAN ID filter
1368  * @mc_io:	Pointer to MC portal's I/O object
1369  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1370  * @token:	Token of DPNI object
1371  * @vlan_id:	VLAN ID to add
1372  *
1373  * Return:	'0' on Success; Error code otherwise.
1374  */
1375 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1376 		     uint32_t cmd_flags,
1377 		     uint16_t token,
1378 		     uint16_t vlan_id)
1379 {
1380 	struct dpni_cmd_vlan_id *cmd_params;
1381 	struct mc_command cmd = { 0 };
1382 
1383 	/* prepare command */
1384 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1385 					  cmd_flags,
1386 					  token);
1387 	cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1388 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
1389 
1390 	/* send command to mc*/
1391 	return mc_send_command(mc_io, &cmd);
1392 }
1393 
1394 /**
1395  * dpni_remove_vlan_id() - Remove VLAN ID filter
1396  * @mc_io:	Pointer to MC portal's I/O object
1397  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1398  * @token:	Token of DPNI object
1399  * @vlan_id:	VLAN ID to remove
1400  *
1401  * Return:	'0' on Success; Error code otherwise.
1402  */
1403 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1404 			uint32_t cmd_flags,
1405 			uint16_t token,
1406 			uint16_t vlan_id)
1407 {
1408 	struct dpni_cmd_vlan_id *cmd_params;
1409 	struct mc_command cmd = { 0 };
1410 
1411 	/* prepare command */
1412 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1413 					  cmd_flags,
1414 					  token);
1415 	cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1416 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
1417 
1418 	/* send command to mc*/
1419 	return mc_send_command(mc_io, &cmd);
1420 }
1421 
1422 /**
1423  * dpni_clear_vlan_filters() - Clear all VLAN filters
1424  * @mc_io:	Pointer to MC portal's I/O object
1425  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1426  * @token:	Token of DPNI object
1427  *
1428  * Return:	'0' on Success; Error code otherwise.
1429  */
1430 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1431 			    uint32_t cmd_flags,
1432 			    uint16_t token)
1433 {
1434 	struct mc_command cmd = { 0 };
1435 
1436 	/* prepare command */
1437 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1438 					  cmd_flags,
1439 					  token);
1440 
1441 	/* send command to mc*/
1442 	return mc_send_command(mc_io, &cmd);
1443 }
1444 
1445 /**
1446  * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1447  * @mc_io:	Pointer to MC portal's I/O object
1448  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1449  * @token:	Token of DPNI object
1450  * @tc_id:	Traffic class selection (0-7)
1451  * @cfg:	Traffic class distribution configuration
1452  *
1453  * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1454  *			first to prepare the key_cfg_iova parameter
1455  *
1456  * Return:	'0' on Success; error code otherwise.
1457  */
1458 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1459 			uint32_t cmd_flags,
1460 			uint16_t token,
1461 			uint8_t tc_id,
1462 			const struct dpni_rx_tc_dist_cfg *cfg)
1463 {
1464 	struct mc_command cmd = { 0 };
1465 	struct dpni_cmd_set_rx_tc_dist *cmd_params;
1466 
1467 	/* prepare command */
1468 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1469 					  cmd_flags,
1470 					  token);
1471 	cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1472 	cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1473 	cmd_params->tc_id = tc_id;
1474 	cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1475 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1476 	dpni_set_field(cmd_params->flags,
1477 		       DIST_MODE,
1478 		       cfg->dist_mode);
1479 	dpni_set_field(cmd_params->flags,
1480 		       MISS_ACTION,
1481 		       cfg->fs_cfg.miss_action);
1482 	dpni_set_field(cmd_params->keep_hash_key,
1483 		       KEEP_HASH_KEY,
1484 		       cfg->fs_cfg.keep_hash_key);
1485 	dpni_set_field(cmd_params->keep_hash_key,
1486 		       KEEP_ENTRIES,
1487 		       cfg->fs_cfg.keep_entries);
1488 
1489 	/* send command to mc*/
1490 	return mc_send_command(mc_io, &cmd);
1491 }
1492 
1493 /**
1494  * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1495  * @mc_io:	Pointer to MC portal's I/O object
1496  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1497  * @token:	Token of DPNI object
1498  * @mode:	Tx confirmation mode
1499  *
1500  * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1501  * selected at DPNI creation.
1502  * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1503  * transmit confirmation (including the private confirmation queues), regardless
1504  * of previous settings; Note that in this case, Tx error frames are still
1505  * enqueued to the general transmit errors queue.
1506  * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1507  * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1508  * command will be ignored.
1509  *
1510  * Return:	'0' on Success; Error code otherwise.
1511  */
1512 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1513 				  uint32_t cmd_flags,
1514 				  uint16_t token,
1515 				  enum dpni_confirmation_mode mode)
1516 {
1517 	struct dpni_tx_confirmation_mode *cmd_params;
1518 	struct mc_command cmd = { 0 };
1519 
1520 	/* prepare command */
1521 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1522 					  cmd_flags,
1523 					  token);
1524 	cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1525 	cmd_params->confirmation_mode = mode;
1526 
1527 	/* send command to mc*/
1528 	return mc_send_command(mc_io, &cmd);
1529 }
1530 
1531 /**
1532  * dpni_set_qos_table() - Set QoS mapping table
1533  * @mc_io:	Pointer to MC portal's I/O object
1534  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1535  * @token:	Token of DPNI object
1536  * @cfg:	QoS table configuration
1537  *
1538  * This function and all QoS-related functions require that
1539  *'max_tcs > 1' was set at DPNI creation.
1540  *
1541  * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1542  *			prepare the key_cfg_iova parameter
1543  *
1544  * Return:	'0' on Success; Error code otherwise.
1545  */
1546 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1547 		       uint32_t cmd_flags,
1548 		       uint16_t token,
1549 		       const struct dpni_qos_tbl_cfg *cfg)
1550 {
1551 	struct dpni_cmd_set_qos_table *cmd_params;
1552 	struct mc_command cmd = { 0 };
1553 
1554 	/* prepare command */
1555 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1556 					  cmd_flags,
1557 					  token);
1558 	cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1559 	cmd_params->default_tc = cfg->default_tc;
1560 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1561 	dpni_set_field(cmd_params->discard_on_miss,
1562 		       ENABLE,
1563 		       cfg->discard_on_miss);
1564 	dpni_set_field(cmd_params->discard_on_miss,
1565 					KEEP_QOS_ENTRIES,
1566 			       cfg->keep_entries);
1567 
1568 	/* send command to mc*/
1569 	return mc_send_command(mc_io, &cmd);
1570 }
1571 
1572 /**
1573  * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1574  * @mc_io:	Pointer to MC portal's I/O object
1575  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1576  * @token:	Token of DPNI object
1577  * @cfg:	QoS rule to add
1578  * @tc_id:	Traffic class selection (0-7)
1579  * @index:	Location in the QoS table where to insert the entry.
1580  *		Only relevant if MASKING is enabled for QoS classification on
1581  *		this DPNI, it is ignored for exact match.
1582  *
1583  * Return:	'0' on Success; Error code otherwise.
1584  */
1585 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1586 		       uint32_t cmd_flags,
1587 		       uint16_t token,
1588 		       const struct dpni_rule_cfg *cfg,
1589 		       uint8_t tc_id,
1590 		       uint16_t index)
1591 {
1592 	struct dpni_cmd_add_qos_entry *cmd_params;
1593 	struct mc_command cmd = { 0 };
1594 
1595 	/* prepare command */
1596 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1597 					  cmd_flags,
1598 					  token);
1599 	cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1600 	cmd_params->tc_id = tc_id;
1601 	cmd_params->key_size = cfg->key_size;
1602 	cmd_params->index = cpu_to_le16(index);
1603 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1604 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1605 
1606 	/* send command to mc*/
1607 	return mc_send_command(mc_io, &cmd);
1608 }
1609 
1610 /**
1611  * dpni_remove_qos_entry() - Remove QoS mapping entry
1612  * @mc_io:	Pointer to MC portal's I/O object
1613  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1614  * @token:	Token of DPNI object
1615  * @cfg:	QoS rule to remove
1616  *
1617  * Return:	'0' on Success; Error code otherwise.
1618  */
1619 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1620 			  uint32_t cmd_flags,
1621 			  uint16_t token,
1622 			  const struct dpni_rule_cfg *cfg)
1623 {
1624 	struct dpni_cmd_remove_qos_entry *cmd_params;
1625 	struct mc_command cmd = { 0 };
1626 
1627 	/* prepare command */
1628 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1629 					  cmd_flags,
1630 					  token);
1631 	cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1632 	cmd_params->key_size = cfg->key_size;
1633 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1634 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1635 
1636 	/* send command to mc*/
1637 	return mc_send_command(mc_io, &cmd);
1638 }
1639 
1640 /**
1641  * dpni_clear_qos_table() - Clear all QoS mapping entries
1642  * @mc_io:	Pointer to MC portal's I/O object
1643  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1644  * @token:	Token of DPNI object
1645  *
1646  * Following this function call, all frames are directed to
1647  * the default traffic class (0)
1648  *
1649  * Return:	'0' on Success; Error code otherwise.
1650  */
1651 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1652 			 uint32_t cmd_flags,
1653 			 uint16_t token)
1654 {
1655 	struct mc_command cmd = { 0 };
1656 
1657 	/* prepare command */
1658 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1659 					  cmd_flags,
1660 					  token);
1661 
1662 	/* send command to mc*/
1663 	return mc_send_command(mc_io, &cmd);
1664 }
1665 
1666 /**
1667  * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1668  *			(to select a flow ID)
1669  * @mc_io:	Pointer to MC portal's I/O object
1670  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1671  * @token:	Token of DPNI object
1672  * @tc_id:	Traffic class selection (0-7)
1673  * @index:	Location in the QoS table where to insert the entry.
1674  *		Only relevant if MASKING is enabled for QoS classification
1675  *		on this DPNI, it is ignored for exact match.
1676  * @cfg:	Flow steering rule to add
1677  * @action:	Action to be taken as result of a classification hit
1678  *
1679  * Return:	'0' on Success; Error code otherwise.
1680  */
1681 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1682 		      uint32_t cmd_flags,
1683 		      uint16_t token,
1684 		      uint8_t tc_id,
1685 		      uint16_t index,
1686 		      const struct dpni_rule_cfg *cfg,
1687 		      const struct dpni_fs_action_cfg *action)
1688 {
1689 	struct dpni_cmd_add_fs_entry *cmd_params;
1690 	struct mc_command cmd = { 0 };
1691 
1692 	/* prepare command */
1693 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1694 					  cmd_flags,
1695 					  token);
1696 	cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1697 	cmd_params->tc_id = tc_id;
1698 	cmd_params->key_size = cfg->key_size;
1699 	cmd_params->index = cpu_to_le16(index);
1700 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1701 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1702 	cmd_params->options = cpu_to_le16(action->options);
1703 	cmd_params->flow_id = cpu_to_le16(action->flow_id);
1704 	cmd_params->flc = cpu_to_le64(action->flc);
1705 
1706 	/* send command to mc*/
1707 	return mc_send_command(mc_io, &cmd);
1708 }
1709 
1710 /**
1711  * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1712  *			traffic class
1713  * @mc_io:	Pointer to MC portal's I/O object
1714  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1715  * @token:	Token of DPNI object
1716  * @tc_id:	Traffic class selection (0-7)
1717  * @cfg:	Flow steering rule to remove
1718  *
1719  * Return:	'0' on Success; Error code otherwise.
1720  */
1721 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1722 			 uint32_t cmd_flags,
1723 			 uint16_t token,
1724 			 uint8_t tc_id,
1725 			 const struct dpni_rule_cfg *cfg)
1726 {
1727 	struct dpni_cmd_remove_fs_entry *cmd_params;
1728 	struct mc_command cmd = { 0 };
1729 
1730 	/* prepare command */
1731 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1732 					  cmd_flags,
1733 					  token);
1734 	cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1735 	cmd_params->tc_id = tc_id;
1736 	cmd_params->key_size = cfg->key_size;
1737 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1738 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1739 
1740 	/* send command to mc*/
1741 	return mc_send_command(mc_io, &cmd);
1742 }
1743 
1744 /**
1745  * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1746  *			traffic class
1747  * @mc_io:	Pointer to MC portal's I/O object
1748  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1749  * @token:	Token of DPNI object
1750  * @tc_id:	Traffic class selection (0-7)
1751  *
1752  * Return:	'0' on Success; Error code otherwise.
1753  */
1754 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1755 			  uint32_t cmd_flags,
1756 			  uint16_t token,
1757 			  uint8_t tc_id)
1758 {
1759 	struct dpni_cmd_clear_fs_entries *cmd_params;
1760 	struct mc_command cmd = { 0 };
1761 
1762 	/* prepare command */
1763 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1764 					  cmd_flags,
1765 					  token);
1766 	cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1767 	cmd_params->tc_id = tc_id;
1768 
1769 	/* send command to mc*/
1770 	return mc_send_command(mc_io, &cmd);
1771 }
1772 
1773 /**
1774  * dpni_set_congestion_notification() - Set traffic class congestion
1775  *	notification configuration
1776  * @mc_io:	Pointer to MC portal's I/O object
1777  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1778  * @token:	Token of DPNI object
1779  * @qtype:	Type of queue - Rx, Tx and Tx confirm types are supported
1780  * @tc_id:	Traffic class selection (0-7)
1781  * @cfg:	congestion notification configuration
1782  *
1783  * Return:	'0' on Success; error code otherwise.
1784  */
1785 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1786 				     uint32_t cmd_flags,
1787 				     uint16_t token,
1788 				     enum dpni_queue_type qtype,
1789 				     uint8_t tc_id,
1790 			const struct dpni_congestion_notification_cfg *cfg)
1791 {
1792 	struct dpni_cmd_set_congestion_notification *cmd_params;
1793 	struct mc_command cmd = { 0 };
1794 
1795 	/* prepare command */
1796 	cmd.header = mc_encode_cmd_header(
1797 					DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1798 					cmd_flags,
1799 					token);
1800 	cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1801 	cmd_params->qtype = qtype;
1802 	cmd_params->tc = tc_id;
1803 	cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1804 	cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1805 	cmd_params->dest_priority = cfg->dest_cfg.priority;
1806 	cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1807 	cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1808 	cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1809 	cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1810 	dpni_set_field(cmd_params->type_units,
1811 		       DEST_TYPE,
1812 		       cfg->dest_cfg.dest_type);
1813 	dpni_set_field(cmd_params->type_units,
1814 		       CONG_UNITS,
1815 		       cfg->units);
1816 
1817 	/* send command to mc*/
1818 	return mc_send_command(mc_io, &cmd);
1819 }
1820 
1821 /**
1822  * dpni_get_congestion_notification() - Get traffic class congestion
1823  *	notification configuration
1824  * @mc_io:	Pointer to MC portal's I/O object
1825  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1826  * @token:	Token of DPNI object
1827  * @qtype:	Type of queue - Rx, Tx and Tx confirm types are supported
1828  * @tc_id:	Traffic class selection (0-7)
1829  * @cfg:	congestion notification configuration
1830  *
1831  * Return:	'0' on Success; error code otherwise.
1832  */
1833 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1834 				     uint32_t cmd_flags,
1835 				     uint16_t token,
1836 				     enum dpni_queue_type qtype,
1837 				     uint8_t tc_id,
1838 				struct dpni_congestion_notification_cfg *cfg)
1839 {
1840 	struct dpni_rsp_get_congestion_notification *rsp_params;
1841 	struct dpni_cmd_get_congestion_notification *cmd_params;
1842 	struct mc_command cmd = { 0 };
1843 	int err;
1844 
1845 	/* prepare command */
1846 	cmd.header = mc_encode_cmd_header(
1847 					DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
1848 					cmd_flags,
1849 					token);
1850 	cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
1851 	cmd_params->qtype = qtype;
1852 	cmd_params->tc = tc_id;
1853 
1854 	/* send command to mc*/
1855 	err = mc_send_command(mc_io, &cmd);
1856 	if (err)
1857 		return err;
1858 
1859 	rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
1860 	cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
1861 	cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
1862 	cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
1863 	cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
1864 	cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
1865 	cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
1866 	cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
1867 	cfg->dest_cfg.priority = rsp_params->dest_priority;
1868 	cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
1869 						 DEST_TYPE);
1870 
1871 	return 0;
1872 }
1873 
1874 /**
1875  * dpni_get_api_version() - Get Data Path Network Interface API version
1876  * @mc_io:  Pointer to MC portal's I/O object
1877  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1878  * @major_ver:	Major version of data path network interface API
1879  * @minor_ver:	Minor version of data path network interface API
1880  *
1881  * Return:  '0' on Success; Error code otherwise.
1882  */
1883 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1884 			 uint32_t cmd_flags,
1885 			 uint16_t *major_ver,
1886 			 uint16_t *minor_ver)
1887 {
1888 	struct dpni_rsp_get_api_version *rsp_params;
1889 	struct mc_command cmd = { 0 };
1890 	int err;
1891 
1892 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1893 					cmd_flags,
1894 					0);
1895 
1896 	err = mc_send_command(mc_io, &cmd);
1897 	if (err)
1898 		return err;
1899 
1900 	rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1901 	*major_ver = le16_to_cpu(rsp_params->major);
1902 	*minor_ver = le16_to_cpu(rsp_params->minor);
1903 
1904 	return 0;
1905 }
1906 
1907 /**
1908  * dpni_set_queue() - Set queue parameters
1909  * @mc_io:	Pointer to MC portal's I/O object
1910  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1911  * @token:	Token of DPNI object
1912  * @qtype:	Type of queue - all queue types are supported, although
1913  *		the command is ignored for Tx
1914  * @tc:		Traffic class, in range 0 to NUM_TCS - 1
1915  * @index:	Selects the specific queue out of the set allocated for the
1916  *		same TC. Value must be in range 0 to NUM_QUEUES - 1
1917  * @options:	A combination of DPNI_QUEUE_OPT_ values that control what
1918  *		configuration options are set on the queue
1919  * @queue:	Queue structure
1920  *
1921  * Return:	'0' on Success; Error code otherwise.
1922  */
1923 int dpni_set_queue(struct fsl_mc_io *mc_io,
1924 		   uint32_t cmd_flags,
1925 		   uint16_t token,
1926 		   enum dpni_queue_type qtype,
1927 		   uint8_t tc,
1928 		   uint8_t index,
1929 		   uint8_t options,
1930 		   const struct dpni_queue *queue)
1931 {
1932 	struct mc_command cmd = { 0 };
1933 	struct dpni_cmd_set_queue *cmd_params;
1934 
1935 	/* prepare command */
1936 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1937 					  cmd_flags,
1938 					  token);
1939 	cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1940 	cmd_params->qtype = qtype;
1941 	cmd_params->tc = tc;
1942 	cmd_params->index = index;
1943 	cmd_params->options = options;
1944 	cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1945 	cmd_params->dest_prio = queue->destination.priority;
1946 	dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1947 	dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1948 	dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1949 		       queue->destination.hold_active);
1950 	cmd_params->flc = cpu_to_le64(queue->flc.value);
1951 	cmd_params->user_context = cpu_to_le64(queue->user_context);
1952 
1953 	/* send command to mc */
1954 	return mc_send_command(mc_io, &cmd);
1955 }
1956 
1957 /**
1958  * dpni_get_queue() - Get queue parameters
1959  * @mc_io:	Pointer to MC portal's I/O object
1960  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1961  * @token:	Token of DPNI object
1962  * @qtype:	Type of queue - all queue types are supported
1963  * @tc:		Traffic class, in range 0 to NUM_TCS - 1
1964  * @index:	Selects the specific queue out of the set allocated for the
1965  *		same TC. Value must be in range 0 to NUM_QUEUES - 1
1966  * @queue:	Queue configuration structure
1967  * @qid:	Queue identification
1968  *
1969  * Return:	'0' on Success; Error code otherwise.
1970  */
1971 int dpni_get_queue(struct fsl_mc_io *mc_io,
1972 		   uint32_t cmd_flags,
1973 		   uint16_t token,
1974 		   enum dpni_queue_type qtype,
1975 		   uint8_t tc,
1976 		   uint8_t index,
1977 		   struct dpni_queue *queue,
1978 		   struct dpni_queue_id *qid)
1979 {
1980 	struct mc_command cmd = { 0 };
1981 	struct dpni_cmd_get_queue *cmd_params;
1982 	struct dpni_rsp_get_queue *rsp_params;
1983 	int err;
1984 
1985 	/* prepare command */
1986 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1987 					  cmd_flags,
1988 					  token);
1989 	cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1990 	cmd_params->qtype = qtype;
1991 	cmd_params->tc = tc;
1992 	cmd_params->index = index;
1993 
1994 	/* send command to mc */
1995 	err = mc_send_command(mc_io, &cmd);
1996 	if (err)
1997 		return err;
1998 
1999 	/* retrieve response parameters */
2000 	rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2001 	queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2002 	queue->destination.priority = rsp_params->dest_prio;
2003 	queue->destination.type = dpni_get_field(rsp_params->flags,
2004 						     DEST_TYPE);
2005 	queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2006 						  STASH_CTRL);
2007 	queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2008 							HOLD_ACTIVE);
2009 	queue->flc.value = le64_to_cpu(rsp_params->flc);
2010 	queue->user_context = le64_to_cpu(rsp_params->user_context);
2011 	qid->fqid = le32_to_cpu(rsp_params->fqid);
2012 	qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2013 
2014 	return 0;
2015 }
2016 
2017 /**
2018  * dpni_get_statistics() - Get DPNI statistics
2019  * @mc_io:	Pointer to MC portal's I/O object
2020  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2021  * @token:	Token of DPNI object
2022  * @page:	Selects the statistics page to retrieve, see
2023  *		DPNI_GET_STATISTICS output. Pages are numbered 0 to 3.
2024  * @param:	Custom parameter for some pages used to select
2025  *		a certain statistic source, for example the TC.
2026  * @stat:	Structure containing the statistics
2027  *
2028  * Return:	'0' on Success; Error code otherwise.
2029  */
2030 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2031 			uint32_t cmd_flags,
2032 			uint16_t token,
2033 			uint8_t page,
2034 			uint8_t param,
2035 			union dpni_statistics *stat)
2036 {
2037 	struct mc_command cmd = { 0 };
2038 	struct dpni_cmd_get_statistics *cmd_params;
2039 	struct dpni_rsp_get_statistics *rsp_params;
2040 	int i, err;
2041 
2042 	/* prepare command */
2043 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2044 					  cmd_flags,
2045 					  token);
2046 	cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2047 	cmd_params->page_number = page;
2048 	cmd_params->param = param;
2049 
2050 	/* send command to mc */
2051 	err = mc_send_command(mc_io, &cmd);
2052 	if (err)
2053 		return err;
2054 
2055 	/* retrieve response parameters */
2056 	rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2057 	for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2058 		stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2059 
2060 	return 0;
2061 }
2062 
2063 /**
2064  * dpni_reset_statistics() - Clears DPNI statistics
2065  * @mc_io:		Pointer to MC portal's I/O object
2066  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
2067  * @token:		Token of DPNI object
2068  *
2069  * Return:  '0' on Success; Error code otherwise.
2070  */
2071 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2072 			  uint32_t cmd_flags,
2073 		     uint16_t token)
2074 {
2075 	struct mc_command cmd = { 0 };
2076 
2077 	/* prepare command */
2078 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2079 					  cmd_flags,
2080 					  token);
2081 
2082 	/* send command to mc*/
2083 	return mc_send_command(mc_io, &cmd);
2084 }
2085 
2086 /**
2087  * dpni_set_taildrop() - Set taildrop per queue or TC
2088  *
2089  * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2090  * congestion notification or early drop (WRED) configuration previously applied
2091  * to the same TC.
2092  *
2093  * @mc_io:	Pointer to MC portal's I/O object
2094  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2095  * @token:	Token of DPNI object
2096  * @cg_point:	Congestion point, DPNI_CP_QUEUE is only supported in
2097  *		combination with DPNI_QUEUE_RX.
2098  * @q_type:	Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2099  * @tc:		Traffic class to apply this taildrop to
2100  * @q_index:	Index of the queue if the DPNI supports multiple queues for
2101  *		traffic distribution.
2102  *		Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
2103  * @taildrop:	Taildrop structure
2104  *
2105  * Return:	'0' on Success; Error code otherwise.
2106  */
2107 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2108 		      uint32_t cmd_flags,
2109 		      uint16_t token,
2110 		      enum dpni_congestion_point cg_point,
2111 		      enum dpni_queue_type qtype,
2112 		      uint8_t tc,
2113 		      uint8_t index,
2114 		      struct dpni_taildrop *taildrop)
2115 {
2116 	struct mc_command cmd = { 0 };
2117 	struct dpni_cmd_set_taildrop *cmd_params;
2118 
2119 	/* prepare command */
2120 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2121 					  cmd_flags,
2122 					  token);
2123 	cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2124 	cmd_params->congestion_point = cg_point;
2125 	cmd_params->qtype = qtype;
2126 	cmd_params->tc = tc;
2127 	cmd_params->index = index;
2128 	cmd_params->units = taildrop->units;
2129 	cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2130 	dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2131 	dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2132 	dpni_set_field(cmd_params->oal_hi,
2133 		       OAL_HI,
2134 		       taildrop->oal >> DPNI_OAL_LO_SIZE);
2135 
2136 	/* send command to mc */
2137 	return mc_send_command(mc_io, &cmd);
2138 }
2139 
2140 /**
2141  * dpni_get_taildrop() - Get taildrop information
2142  * @mc_io:	Pointer to MC portal's I/O object
2143  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2144  * @token:	Token of DPNI object
2145  * @cg_point:	Congestion point
2146  * @q_type:	Queue type on which the taildrop is configured.
2147  *		Only Rx queues are supported for now
2148  * @tc:		Traffic class to apply this taildrop to
2149  * @q_index:	Index of the queue if the DPNI supports multiple queues for
2150  *		traffic distribution. Ignored if CONGESTION_POINT is not 0.
2151  * @taildrop:	Taildrop structure
2152  *
2153  * Return:	'0' on Success; Error code otherwise.
2154  */
2155 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2156 		      uint32_t cmd_flags,
2157 		      uint16_t token,
2158 		      enum dpni_congestion_point cg_point,
2159 		      enum dpni_queue_type qtype,
2160 		      uint8_t tc,
2161 		      uint8_t index,
2162 		      struct dpni_taildrop *taildrop)
2163 {
2164 	struct mc_command cmd = { 0 };
2165 	struct dpni_cmd_get_taildrop *cmd_params;
2166 	struct dpni_rsp_get_taildrop *rsp_params;
2167 	uint8_t oal_lo, oal_hi;
2168 	int err;
2169 
2170 	/* prepare command */
2171 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2172 					  cmd_flags,
2173 					  token);
2174 	cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2175 	cmd_params->congestion_point = cg_point;
2176 	cmd_params->qtype = qtype;
2177 	cmd_params->tc = tc;
2178 	cmd_params->index = index;
2179 
2180 	/* send command to mc */
2181 	err = mc_send_command(mc_io, &cmd);
2182 	if (err)
2183 		return err;
2184 
2185 	/* retrieve response parameters */
2186 	rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2187 	taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2188 	taildrop->units = rsp_params->units;
2189 	taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2190 	oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2191 	oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2192 	taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2193 
2194 	/* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2195 	if (taildrop->oal >= 0x0800)
2196 		taildrop->oal |= 0xF000;
2197 
2198 	return 0;
2199 }
2200 
2201 /**
2202  * dpni_set_opr() - Set Order Restoration configuration.
2203  * @mc_io:	Pointer to MC portal's I/O object
2204  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2205  * @token:	Token of DPNI object
2206  * @tc:		Traffic class, in range 0 to NUM_TCS - 1
2207  * @index:	Selects the specific queue out of the set allocated
2208  *			for the same TC. Value must be in range 0 to
2209  *			NUM_QUEUES - 1
2210  * @options:	Configuration mode options
2211  *			can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2212  * @cfg:	Configuration options for the OPR
2213  *
2214  * Return:	'0' on Success; Error code otherwise.
2215  */
2216 int dpni_set_opr(struct fsl_mc_io *mc_io,
2217 		 uint32_t cmd_flags,
2218 		 uint16_t token,
2219 		 uint8_t tc,
2220 		 uint8_t index,
2221 		 uint8_t options,
2222 		 struct opr_cfg *cfg)
2223 {
2224 	struct dpni_cmd_set_opr *cmd_params;
2225 	struct mc_command cmd = { 0 };
2226 
2227 	/* prepare command */
2228 	cmd.header = mc_encode_cmd_header(
2229 			DPNI_CMDID_SET_OPR,
2230 			cmd_flags,
2231 			token);
2232 	cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2233 	cmd_params->tc_id = tc;
2234 	cmd_params->index = index;
2235 	cmd_params->options = options;
2236 	cmd_params->oloe = cfg->oloe;
2237 	cmd_params->oeane = cfg->oeane;
2238 	cmd_params->olws = cfg->olws;
2239 	cmd_params->oa = cfg->oa;
2240 	cmd_params->oprrws = cfg->oprrws;
2241 
2242 	/* send command to mc*/
2243 	return mc_send_command(mc_io, &cmd);
2244 }
2245 
2246 /**
2247  * dpni_get_opr() - Retrieve Order Restoration config and query.
2248  * @mc_io:	Pointer to MC portal's I/O object
2249  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2250  * @token:	Token of DPNI object
2251  * @tc:		Traffic class, in range 0 to NUM_TCS - 1
2252  * @index:	Selects the specific queue out of the set allocated
2253  *			for the same TC. Value must be in range 0 to
2254  *			NUM_QUEUES - 1
2255  * @cfg:	Returned OPR configuration
2256  * @qry:	Returned OPR query
2257  *
2258  * Return:	'0' on Success; Error code otherwise.
2259  */
2260 int dpni_get_opr(struct fsl_mc_io *mc_io,
2261 		 uint32_t cmd_flags,
2262 		 uint16_t token,
2263 		 uint8_t tc,
2264 		 uint8_t index,
2265 		 struct opr_cfg *cfg,
2266 		 struct opr_qry *qry)
2267 {
2268 	struct dpni_rsp_get_opr *rsp_params;
2269 	struct dpni_cmd_get_opr *cmd_params;
2270 	struct mc_command cmd = { 0 };
2271 	int err;
2272 
2273 	/* prepare command */
2274 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2275 					  cmd_flags,
2276 					  token);
2277 	cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2278 	cmd_params->index = index;
2279 	cmd_params->tc_id = tc;
2280 
2281 	/* send command to mc*/
2282 	err = mc_send_command(mc_io, &cmd);
2283 	if (err)
2284 		return err;
2285 
2286 	/* retrieve response parameters */
2287 	rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2288 	cfg->oloe = rsp_params->oloe;
2289 	cfg->oeane = rsp_params->oeane;
2290 	cfg->olws = rsp_params->olws;
2291 	cfg->oa = rsp_params->oa;
2292 	cfg->oprrws = rsp_params->oprrws;
2293 	qry->rip = dpni_get_field(rsp_params->flags, RIP);
2294 	qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2295 	qry->nesn = le16_to_cpu(rsp_params->nesn);
2296 	qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2297 	qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2298 	qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2299 	qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2300 	qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2301 	qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2302 	qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2303 	qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2304 	qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2305 
2306 	return 0;
2307 }
2308 
2309 /**
2310  * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2311  * @mc_io:	Pointer to MC portal's I/O object
2312  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2313  * @token:	Token of DPNI object
2314  * @cfg: Distribution configuration
2315  * If the FS is already enabled with a previous call the classification
2316  *		key will be changed but all the table rules are kept. If the
2317  *		existing rules do not match the key the results will not be
2318  *		predictable. It is the user responsibility to keep key integrity
2319  * If cfg.enable is set to 1 the command will create a flow steering table
2320  *		and will classify packets according to this table. The packets
2321  *		that miss all the table rules will be classified according to
2322  *		settings made in dpni_set_rx_hash_dist()
2323  * If cfg.enable is set to 0 the command will clear flow steering table. The
2324  *		packets will be classified according to settings made in
2325  *		dpni_set_rx_hash_dist()
2326  */
2327 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2328 		uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2329 {
2330 	struct dpni_cmd_set_rx_fs_dist *cmd_params;
2331 	struct mc_command cmd = { 0 };
2332 
2333 	/* prepare command */
2334 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2335 					  cmd_flags,
2336 					  token);
2337 	cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2338 	cmd_params->dist_size	= cpu_to_le16(cfg->dist_size);
2339 	dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2340 	cmd_params->tc = cfg->tc;
2341 	cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2342 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2343 
2344 	/* send command to mc*/
2345 	return mc_send_command(mc_io, &cmd);
2346 }
2347 
2348 /**
2349  * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2350  * @mc_io:	Pointer to MC portal's I/O object
2351  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2352  * @token:	Token of DPNI object
2353  * @cfg: Distribution configuration
2354  * If cfg.enable is set to 1 the packets will be classified using a hash
2355  *		function based on the key received in cfg.key_cfg_iova parameter
2356  * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2357  *		dpni_set_rx_dist_default_queue() call
2358  */
2359 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2360 		uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2361 {
2362 	struct dpni_cmd_set_rx_hash_dist *cmd_params;
2363 	struct mc_command cmd = { 0 };
2364 
2365 	/* prepare command */
2366 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2367 					  cmd_flags,
2368 					  token);
2369 	cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2370 	cmd_params->dist_size	= cpu_to_le16(cfg->dist_size);
2371 	dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2372 	cmd_params->tc_id		= cfg->tc;
2373 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2374 
2375 	/* send command to mc*/
2376 	return mc_send_command(mc_io, &cmd);
2377 }
2378 
2379 /**
2380  * dpni_add_custom_tpid() - Configures a distinct Ethertype value
2381  *		(or TPID value) to indicate VLAN tag in addition to the common
2382  *		TPID values 0x8100 and 0x88A8
2383  * @mc_io:	Pointer to MC portal's I/O object
2384  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2385  * @token:	Token of DPNI object
2386  * @tpid:	New value for TPID
2387  *
2388  * Only two custom values are accepted. If the function is called for the third
2389  * time it will return error.
2390  * To replace an existing value use dpni_remove_custom_tpid() to remove
2391  * a previous TPID and after that use again the function.
2392  *
2393  * Return:	'0' on Success; Error code otherwise.
2394  */
2395 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2396 		uint16_t token, uint16_t tpid)
2397 {
2398 	struct dpni_cmd_add_custom_tpid *cmd_params;
2399 	struct mc_command cmd = { 0 };
2400 
2401 	/* prepare command */
2402 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
2403 					  cmd_flags,
2404 					  token);
2405 	cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
2406 	cmd_params->tpid = cpu_to_le16(tpid);
2407 
2408 	/* send command to mc*/
2409 	return mc_send_command(mc_io, &cmd);
2410 }
2411 
2412 /**
2413  * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
2414  *		previously with dpni_add_custom_tpid()
2415  * @mc_io:	Pointer to MC portal's I/O object
2416  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2417  * @token:	Token of DPNI object
2418  * @tpid:	New value for TPID
2419  *
2420  * Use this function when a TPID value added with dpni_add_custom_tpid() needs
2421  * to be replaced.
2422  *
2423  * Return:	'0' on Success; Error code otherwise.
2424  */
2425 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2426 		uint16_t token, uint16_t tpid)
2427 {
2428 	struct dpni_cmd_remove_custom_tpid *cmd_params;
2429 	struct mc_command cmd = { 0 };
2430 
2431 	/* prepare command */
2432 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
2433 					  cmd_flags,
2434 					  token);
2435 	cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
2436 	cmd_params->tpid = cpu_to_le16(tpid);
2437 
2438 	/* send command to mc*/
2439 	return mc_send_command(mc_io, &cmd);
2440 }
2441 
2442 /**
2443  * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured
2444  *				to detect 802.1q frames
2445  * @mc_io:	Pointer to MC portal's I/O object
2446  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2447  * @token:	Token of DPNI object
2448  * @tpid:	TPID values. Only nonzero members of the structure are valid.
2449  *
2450  * Return:	'0' on Success; Error code otherwise.
2451  */
2452 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2453 		uint16_t token, struct dpni_custom_tpid_cfg *tpid)
2454 {
2455 	struct dpni_rsp_get_custom_tpid *rsp_params;
2456 	struct mc_command cmd = { 0 };
2457 	int err;
2458 
2459 	/* prepare command */
2460 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
2461 					  cmd_flags,
2462 					  token);
2463 
2464 	/* send command to mc*/
2465 	err = mc_send_command(mc_io, &cmd);
2466 	if (err)
2467 		return err;
2468 
2469 	/* read command response */
2470 	rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
2471 	tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
2472 	tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
2473 
2474 	return err;
2475 }
2476