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