1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2013-2016 Freescale Semiconductor Inc.
3  * Copyright 2016 NXP
4  */
5 #include <linux/kernel.h>
6 #include <linux/errno.h>
7 #include <linux/fsl/mc.h>
8 #include "dpni.h"
9 #include "dpni-cmd.h"
10 
11 /**
12  * dpni_prepare_key_cfg() - function prepare extract parameters
13  * @cfg: defining a full Key Generation profile (rule)
14  * @key_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
15  *
16  * This function has to be called before the following functions:
17  *	- dpni_set_rx_tc_dist()
18  *	- dpni_set_qos_table()
19  */
20 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg, u8 *key_cfg_buf)
21 {
22 	int i, j;
23 	struct dpni_ext_set_rx_tc_dist *dpni_ext;
24 	struct dpni_dist_extract *extr;
25 
26 	if (cfg->num_extracts > DPKG_MAX_NUM_OF_EXTRACTS)
27 		return -EINVAL;
28 
29 	dpni_ext = (struct dpni_ext_set_rx_tc_dist *)key_cfg_buf;
30 	dpni_ext->num_extracts = cfg->num_extracts;
31 
32 	for (i = 0; i < cfg->num_extracts; i++) {
33 		extr = &dpni_ext->extracts[i];
34 
35 		switch (cfg->extracts[i].type) {
36 		case DPKG_EXTRACT_FROM_HDR:
37 			extr->prot = cfg->extracts[i].extract.from_hdr.prot;
38 			dpni_set_field(extr->efh_type, EFH_TYPE,
39 				       cfg->extracts[i].extract.from_hdr.type);
40 			extr->size = cfg->extracts[i].extract.from_hdr.size;
41 			extr->offset = cfg->extracts[i].extract.from_hdr.offset;
42 			extr->field = cpu_to_le32(
43 				cfg->extracts[i].extract.from_hdr.field);
44 			extr->hdr_index =
45 				cfg->extracts[i].extract.from_hdr.hdr_index;
46 			break;
47 		case DPKG_EXTRACT_FROM_DATA:
48 			extr->size = cfg->extracts[i].extract.from_data.size;
49 			extr->offset =
50 				cfg->extracts[i].extract.from_data.offset;
51 			break;
52 		case DPKG_EXTRACT_FROM_PARSE:
53 			extr->size = cfg->extracts[i].extract.from_parse.size;
54 			extr->offset =
55 				cfg->extracts[i].extract.from_parse.offset;
56 			break;
57 		default:
58 			return -EINVAL;
59 		}
60 
61 		extr->num_of_byte_masks = cfg->extracts[i].num_of_byte_masks;
62 		dpni_set_field(extr->extract_type, EXTRACT_TYPE,
63 			       cfg->extracts[i].type);
64 
65 		for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
66 			extr->masks[j].mask = cfg->extracts[i].masks[j].mask;
67 			extr->masks[j].offset =
68 				cfg->extracts[i].masks[j].offset;
69 		}
70 	}
71 
72 	return 0;
73 }
74 
75 /**
76  * dpni_open() - Open a control session for the specified object
77  * @mc_io:	Pointer to MC portal's I/O object
78  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
79  * @dpni_id:	DPNI unique ID
80  * @token:	Returned token; use in subsequent API calls
81  *
82  * This function can be used to open a control session for an
83  * already created object; an object may have been declared in
84  * the DPL or by calling the dpni_create() function.
85  * This function returns a unique authentication token,
86  * associated with the specific object ID and the specific MC
87  * portal; this token must be used in all subsequent commands for
88  * this specific object.
89  *
90  * Return:	'0' on Success; Error code otherwise.
91  */
92 int dpni_open(struct fsl_mc_io *mc_io,
93 	      u32 cmd_flags,
94 	      int dpni_id,
95 	      u16 *token)
96 {
97 	struct fsl_mc_command cmd = { 0 };
98 	struct dpni_cmd_open *cmd_params;
99 
100 	int err;
101 
102 	/* prepare command */
103 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
104 					  cmd_flags,
105 					  0);
106 	cmd_params = (struct dpni_cmd_open *)cmd.params;
107 	cmd_params->dpni_id = cpu_to_le32(dpni_id);
108 
109 	/* send command to mc*/
110 	err = mc_send_command(mc_io, &cmd);
111 	if (err)
112 		return err;
113 
114 	/* retrieve response parameters */
115 	*token = mc_cmd_hdr_read_token(&cmd);
116 
117 	return 0;
118 }
119 
120 /**
121  * dpni_close() - Close the control session of the object
122  * @mc_io:	Pointer to MC portal's I/O object
123  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
124  * @token:	Token of DPNI object
125  *
126  * After this function is called, no further operations are
127  * allowed on the object without opening a new control session.
128  *
129  * Return:	'0' on Success; Error code otherwise.
130  */
131 int dpni_close(struct fsl_mc_io *mc_io,
132 	       u32 cmd_flags,
133 	       u16 token)
134 {
135 	struct fsl_mc_command cmd = { 0 };
136 
137 	/* prepare command */
138 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
139 					  cmd_flags,
140 					  token);
141 
142 	/* send command to mc*/
143 	return mc_send_command(mc_io, &cmd);
144 }
145 
146 /**
147  * dpni_set_pools() - Set buffer pools configuration
148  * @mc_io:	Pointer to MC portal's I/O object
149  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
150  * @token:	Token of DPNI object
151  * @cfg:	Buffer pools configuration
152  *
153  * mandatory for DPNI operation
154  * warning:Allowed only when DPNI is disabled
155  *
156  * Return:	'0' on Success; Error code otherwise.
157  */
158 int dpni_set_pools(struct fsl_mc_io *mc_io,
159 		   u32 cmd_flags,
160 		   u16 token,
161 		   const struct dpni_pools_cfg *cfg)
162 {
163 	struct fsl_mc_command cmd = { 0 };
164 	struct dpni_cmd_set_pools *cmd_params;
165 	int i;
166 
167 	/* prepare command */
168 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
169 					  cmd_flags,
170 					  token);
171 	cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
172 	cmd_params->num_dpbp = cfg->num_dpbp;
173 	for (i = 0; i < DPNI_MAX_DPBP; i++) {
174 		cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
175 		cmd_params->buffer_size[i] =
176 			cpu_to_le16(cfg->pools[i].buffer_size);
177 		cmd_params->backup_pool_mask |=
178 			DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
179 	}
180 
181 	/* send command to mc*/
182 	return mc_send_command(mc_io, &cmd);
183 }
184 
185 /**
186  * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
187  * @mc_io:	Pointer to MC portal's I/O object
188  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
189  * @token:		Token of DPNI object
190  *
191  * Return:	'0' on Success; Error code otherwise.
192  */
193 int dpni_enable(struct fsl_mc_io *mc_io,
194 		u32 cmd_flags,
195 		u16 token)
196 {
197 	struct fsl_mc_command cmd = { 0 };
198 
199 	/* prepare command */
200 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
201 					  cmd_flags,
202 					  token);
203 
204 	/* send command to mc*/
205 	return mc_send_command(mc_io, &cmd);
206 }
207 
208 /**
209  * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
210  * @mc_io:	Pointer to MC portal's I/O object
211  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
212  * @token:	Token of DPNI object
213  *
214  * Return:	'0' on Success; Error code otherwise.
215  */
216 int dpni_disable(struct fsl_mc_io *mc_io,
217 		 u32 cmd_flags,
218 		 u16 token)
219 {
220 	struct fsl_mc_command cmd = { 0 };
221 
222 	/* prepare command */
223 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
224 					  cmd_flags,
225 					  token);
226 
227 	/* send command to mc*/
228 	return mc_send_command(mc_io, &cmd);
229 }
230 
231 /**
232  * dpni_is_enabled() - Check if the DPNI is enabled.
233  * @mc_io:	Pointer to MC portal's I/O object
234  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
235  * @token:	Token of DPNI object
236  * @en:		Returns '1' if object is enabled; '0' otherwise
237  *
238  * Return:	'0' on Success; Error code otherwise.
239  */
240 int dpni_is_enabled(struct fsl_mc_io *mc_io,
241 		    u32 cmd_flags,
242 		    u16 token,
243 		    int *en)
244 {
245 	struct fsl_mc_command cmd = { 0 };
246 	struct dpni_rsp_is_enabled *rsp_params;
247 	int err;
248 
249 	/* prepare command */
250 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
251 					  cmd_flags,
252 					  token);
253 
254 	/* send command to mc*/
255 	err = mc_send_command(mc_io, &cmd);
256 	if (err)
257 		return err;
258 
259 	/* retrieve response parameters */
260 	rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
261 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
262 
263 	return 0;
264 }
265 
266 /**
267  * dpni_reset() - Reset the DPNI, returns the object to initial state.
268  * @mc_io:	Pointer to MC portal's I/O object
269  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
270  * @token:	Token of DPNI object
271  *
272  * Return:	'0' on Success; Error code otherwise.
273  */
274 int dpni_reset(struct fsl_mc_io *mc_io,
275 	       u32 cmd_flags,
276 	       u16 token)
277 {
278 	struct fsl_mc_command cmd = { 0 };
279 
280 	/* prepare command */
281 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
282 					  cmd_flags,
283 					  token);
284 
285 	/* send command to mc*/
286 	return mc_send_command(mc_io, &cmd);
287 }
288 
289 /**
290  * dpni_set_irq_enable() - Set overall interrupt state.
291  * @mc_io:	Pointer to MC portal's I/O object
292  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
293  * @token:	Token of DPNI object
294  * @irq_index:	The interrupt index to configure
295  * @en:		Interrupt state: - enable = 1, disable = 0
296  *
297  * Allows GPP software to control when interrupts are generated.
298  * Each interrupt can have up to 32 causes.  The enable/disable control's the
299  * overall interrupt state. if the interrupt is disabled no causes will cause
300  * an interrupt.
301  *
302  * Return:	'0' on Success; Error code otherwise.
303  */
304 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
305 			u32 cmd_flags,
306 			u16 token,
307 			u8 irq_index,
308 			u8 en)
309 {
310 	struct fsl_mc_command cmd = { 0 };
311 	struct dpni_cmd_set_irq_enable *cmd_params;
312 
313 	/* prepare command */
314 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
315 					  cmd_flags,
316 					  token);
317 	cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
318 	dpni_set_field(cmd_params->enable, ENABLE, en);
319 	cmd_params->irq_index = irq_index;
320 
321 	/* send command to mc*/
322 	return mc_send_command(mc_io, &cmd);
323 }
324 
325 /**
326  * dpni_get_irq_enable() - Get overall interrupt state
327  * @mc_io:	Pointer to MC portal's I/O object
328  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
329  * @token:	Token of DPNI object
330  * @irq_index:	The interrupt index to configure
331  * @en:		Returned interrupt state - enable = 1, disable = 0
332  *
333  * Return:	'0' on Success; Error code otherwise.
334  */
335 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
336 			u32 cmd_flags,
337 			u16 token,
338 			u8 irq_index,
339 			u8 *en)
340 {
341 	struct fsl_mc_command cmd = { 0 };
342 	struct dpni_cmd_get_irq_enable *cmd_params;
343 	struct dpni_rsp_get_irq_enable *rsp_params;
344 
345 	int err;
346 
347 	/* prepare command */
348 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
349 					  cmd_flags,
350 					  token);
351 	cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
352 	cmd_params->irq_index = irq_index;
353 
354 	/* send command to mc*/
355 	err = mc_send_command(mc_io, &cmd);
356 	if (err)
357 		return err;
358 
359 	/* retrieve response parameters */
360 	rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
361 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
362 
363 	return 0;
364 }
365 
366 /**
367  * dpni_set_irq_mask() - Set interrupt mask.
368  * @mc_io:	Pointer to MC portal's I/O object
369  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
370  * @token:	Token of DPNI object
371  * @irq_index:	The interrupt index to configure
372  * @mask:	event mask to trigger interrupt;
373  *			each bit:
374  *				0 = ignore event
375  *				1 = consider event for asserting IRQ
376  *
377  * Every interrupt can have up to 32 causes and the interrupt model supports
378  * masking/unmasking each cause independently
379  *
380  * Return:	'0' on Success; Error code otherwise.
381  */
382 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
383 		      u32 cmd_flags,
384 		      u16 token,
385 		      u8 irq_index,
386 		      u32 mask)
387 {
388 	struct fsl_mc_command cmd = { 0 };
389 	struct dpni_cmd_set_irq_mask *cmd_params;
390 
391 	/* prepare command */
392 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
393 					  cmd_flags,
394 					  token);
395 	cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
396 	cmd_params->mask = cpu_to_le32(mask);
397 	cmd_params->irq_index = irq_index;
398 
399 	/* send command to mc*/
400 	return mc_send_command(mc_io, &cmd);
401 }
402 
403 /**
404  * dpni_get_irq_mask() - Get interrupt mask.
405  * @mc_io:	Pointer to MC portal's I/O object
406  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
407  * @token:	Token of DPNI object
408  * @irq_index:	The interrupt index to configure
409  * @mask:	Returned event mask to trigger interrupt
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_get_irq_mask(struct fsl_mc_io *mc_io,
417 		      u32 cmd_flags,
418 		      u16 token,
419 		      u8 irq_index,
420 		      u32 *mask)
421 {
422 	struct fsl_mc_command cmd = { 0 };
423 	struct dpni_cmd_get_irq_mask *cmd_params;
424 	struct dpni_rsp_get_irq_mask *rsp_params;
425 	int err;
426 
427 	/* prepare command */
428 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
429 					  cmd_flags,
430 					  token);
431 	cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
432 	cmd_params->irq_index = irq_index;
433 
434 	/* send command to mc*/
435 	err = mc_send_command(mc_io, &cmd);
436 	if (err)
437 		return err;
438 
439 	/* retrieve response parameters */
440 	rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
441 	*mask = le32_to_cpu(rsp_params->mask);
442 
443 	return 0;
444 }
445 
446 /**
447  * dpni_get_irq_status() - Get the current status of any pending interrupts.
448  * @mc_io:	Pointer to MC portal's I/O object
449  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
450  * @token:	Token of DPNI object
451  * @irq_index:	The interrupt index to configure
452  * @status:	Returned interrupts status - one bit per cause:
453  *			0 = no interrupt pending
454  *			1 = interrupt pending
455  *
456  * Return:	'0' on Success; Error code otherwise.
457  */
458 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
459 			u32 cmd_flags,
460 			u16 token,
461 			u8 irq_index,
462 			u32 *status)
463 {
464 	struct fsl_mc_command cmd = { 0 };
465 	struct dpni_cmd_get_irq_status *cmd_params;
466 	struct dpni_rsp_get_irq_status *rsp_params;
467 	int err;
468 
469 	/* prepare command */
470 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
471 					  cmd_flags,
472 					  token);
473 	cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
474 	cmd_params->status = cpu_to_le32(*status);
475 	cmd_params->irq_index = irq_index;
476 
477 	/* send command to mc*/
478 	err = mc_send_command(mc_io, &cmd);
479 	if (err)
480 		return err;
481 
482 	/* retrieve response parameters */
483 	rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
484 	*status = le32_to_cpu(rsp_params->status);
485 
486 	return 0;
487 }
488 
489 /**
490  * dpni_clear_irq_status() - Clear a pending interrupt's status
491  * @mc_io:	Pointer to MC portal's I/O object
492  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
493  * @token:	Token of DPNI object
494  * @irq_index:	The interrupt index to configure
495  * @status:	bits to clear (W1C) - one bit per cause:
496  *			0 = don't change
497  *			1 = clear status bit
498  *
499  * Return:	'0' on Success; Error code otherwise.
500  */
501 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
502 			  u32 cmd_flags,
503 			  u16 token,
504 			  u8 irq_index,
505 			  u32 status)
506 {
507 	struct fsl_mc_command cmd = { 0 };
508 	struct dpni_cmd_clear_irq_status *cmd_params;
509 
510 	/* prepare command */
511 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
512 					  cmd_flags,
513 					  token);
514 	cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
515 	cmd_params->irq_index = irq_index;
516 	cmd_params->status = cpu_to_le32(status);
517 
518 	/* send command to mc*/
519 	return mc_send_command(mc_io, &cmd);
520 }
521 
522 /**
523  * dpni_get_attributes() - Retrieve DPNI attributes.
524  * @mc_io:	Pointer to MC portal's I/O object
525  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
526  * @token:	Token of DPNI object
527  * @attr:	Object's attributes
528  *
529  * Return:	'0' on Success; Error code otherwise.
530  */
531 int dpni_get_attributes(struct fsl_mc_io *mc_io,
532 			u32 cmd_flags,
533 			u16 token,
534 			struct dpni_attr *attr)
535 {
536 	struct fsl_mc_command cmd = { 0 };
537 	struct dpni_rsp_get_attr *rsp_params;
538 
539 	int err;
540 
541 	/* prepare command */
542 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
543 					  cmd_flags,
544 					  token);
545 
546 	/* send command to mc*/
547 	err = mc_send_command(mc_io, &cmd);
548 	if (err)
549 		return err;
550 
551 	/* retrieve response parameters */
552 	rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
553 	attr->options = le32_to_cpu(rsp_params->options);
554 	attr->num_queues = rsp_params->num_queues;
555 	attr->num_tcs = rsp_params->num_tcs;
556 	attr->mac_filter_entries = rsp_params->mac_filter_entries;
557 	attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
558 	attr->qos_entries = rsp_params->qos_entries;
559 	attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
560 	attr->qos_key_size = rsp_params->qos_key_size;
561 	attr->fs_key_size = rsp_params->fs_key_size;
562 	attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
563 
564 	return 0;
565 }
566 
567 /**
568  * dpni_set_errors_behavior() - Set errors behavior
569  * @mc_io:	Pointer to MC portal's I/O object
570  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
571  * @token:	Token of DPNI object
572  * @cfg:	Errors configuration
573  *
574  * this function may be called numerous times with different
575  * error masks
576  *
577  * Return:	'0' on Success; Error code otherwise.
578  */
579 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
580 			     u32 cmd_flags,
581 			     u16 token,
582 			     struct dpni_error_cfg *cfg)
583 {
584 	struct fsl_mc_command cmd = { 0 };
585 	struct dpni_cmd_set_errors_behavior *cmd_params;
586 
587 	/* prepare command */
588 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
589 					  cmd_flags,
590 					  token);
591 	cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
592 	cmd_params->errors = cpu_to_le32(cfg->errors);
593 	dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
594 	dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
595 
596 	/* send command to mc*/
597 	return mc_send_command(mc_io, &cmd);
598 }
599 
600 /**
601  * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
602  * @mc_io:	Pointer to MC portal's I/O object
603  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
604  * @token:	Token of DPNI object
605  * @qtype:	Type of queue to retrieve configuration for
606  * @layout:	Returns buffer layout attributes
607  *
608  * Return:	'0' on Success; Error code otherwise.
609  */
610 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
611 			   u32 cmd_flags,
612 			   u16 token,
613 			   enum dpni_queue_type qtype,
614 			   struct dpni_buffer_layout *layout)
615 {
616 	struct fsl_mc_command cmd = { 0 };
617 	struct dpni_cmd_get_buffer_layout *cmd_params;
618 	struct dpni_rsp_get_buffer_layout *rsp_params;
619 	int err;
620 
621 	/* prepare command */
622 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
623 					  cmd_flags,
624 					  token);
625 	cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
626 	cmd_params->qtype = qtype;
627 
628 	/* send command to mc*/
629 	err = mc_send_command(mc_io, &cmd);
630 	if (err)
631 		return err;
632 
633 	/* retrieve response parameters */
634 	rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
635 	layout->pass_timestamp = dpni_get_field(rsp_params->flags, PASS_TS);
636 	layout->pass_parser_result = dpni_get_field(rsp_params->flags, PASS_PR);
637 	layout->pass_frame_status = dpni_get_field(rsp_params->flags, PASS_FS);
638 	layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
639 	layout->data_align = le16_to_cpu(rsp_params->data_align);
640 	layout->data_head_room = le16_to_cpu(rsp_params->head_room);
641 	layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
642 
643 	return 0;
644 }
645 
646 /**
647  * dpni_set_buffer_layout() - Set buffer layout configuration.
648  * @mc_io:	Pointer to MC portal's I/O object
649  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
650  * @token:	Token of DPNI object
651  * @qtype:	Type of queue this configuration applies to
652  * @layout:	Buffer layout configuration
653  *
654  * Return:	'0' on Success; Error code otherwise.
655  *
656  * @warning	Allowed only when DPNI is disabled
657  */
658 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
659 			   u32 cmd_flags,
660 			   u16 token,
661 			   enum dpni_queue_type qtype,
662 			   const struct dpni_buffer_layout *layout)
663 {
664 	struct fsl_mc_command cmd = { 0 };
665 	struct dpni_cmd_set_buffer_layout *cmd_params;
666 
667 	/* prepare command */
668 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
669 					  cmd_flags,
670 					  token);
671 	cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
672 	cmd_params->qtype = qtype;
673 	cmd_params->options = cpu_to_le16(layout->options);
674 	dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
675 	dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
676 	dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
677 	cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
678 	cmd_params->data_align = cpu_to_le16(layout->data_align);
679 	cmd_params->head_room = cpu_to_le16(layout->data_head_room);
680 	cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
681 
682 	/* send command to mc*/
683 	return mc_send_command(mc_io, &cmd);
684 }
685 
686 /**
687  * dpni_set_offload() - Set DPNI offload configuration.
688  * @mc_io:	Pointer to MC portal's I/O object
689  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
690  * @token:	Token of DPNI object
691  * @type:	Type of DPNI offload
692  * @config:	Offload configuration.
693  *		For checksum offloads, non-zero value enables the offload
694  *
695  * Return:     '0' on Success; Error code otherwise.
696  *
697  * @warning    Allowed only when DPNI is disabled
698  */
699 
700 int dpni_set_offload(struct fsl_mc_io *mc_io,
701 		     u32 cmd_flags,
702 		     u16 token,
703 		     enum dpni_offload type,
704 		     u32 config)
705 {
706 	struct fsl_mc_command cmd = { 0 };
707 	struct dpni_cmd_set_offload *cmd_params;
708 
709 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
710 					  cmd_flags,
711 					  token);
712 	cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
713 	cmd_params->dpni_offload = type;
714 	cmd_params->config = cpu_to_le32(config);
715 
716 	return mc_send_command(mc_io, &cmd);
717 }
718 
719 int dpni_get_offload(struct fsl_mc_io *mc_io,
720 		     u32 cmd_flags,
721 		     u16 token,
722 		     enum dpni_offload type,
723 		     u32 *config)
724 {
725 	struct fsl_mc_command cmd = { 0 };
726 	struct dpni_cmd_get_offload *cmd_params;
727 	struct dpni_rsp_get_offload *rsp_params;
728 	int err;
729 
730 	/* prepare command */
731 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
732 					  cmd_flags,
733 					  token);
734 	cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
735 	cmd_params->dpni_offload = type;
736 
737 	/* send command to mc*/
738 	err = mc_send_command(mc_io, &cmd);
739 	if (err)
740 		return err;
741 
742 	/* retrieve response parameters */
743 	rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
744 	*config = le32_to_cpu(rsp_params->config);
745 
746 	return 0;
747 }
748 
749 /**
750  * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
751  *			for enqueue operations
752  * @mc_io:	Pointer to MC portal's I/O object
753  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
754  * @token:	Token of DPNI object
755  * @qtype:	Type of queue to receive QDID for
756  * @qdid:	Returned virtual QDID value that should be used as an argument
757  *			in all enqueue operations
758  *
759  * Return:	'0' on Success; Error code otherwise.
760  */
761 int dpni_get_qdid(struct fsl_mc_io *mc_io,
762 		  u32 cmd_flags,
763 		  u16 token,
764 		  enum dpni_queue_type qtype,
765 		  u16 *qdid)
766 {
767 	struct fsl_mc_command cmd = { 0 };
768 	struct dpni_cmd_get_qdid *cmd_params;
769 	struct dpni_rsp_get_qdid *rsp_params;
770 	int err;
771 
772 	/* prepare command */
773 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
774 					  cmd_flags,
775 					  token);
776 	cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
777 	cmd_params->qtype = qtype;
778 
779 	/* send command to mc*/
780 	err = mc_send_command(mc_io, &cmd);
781 	if (err)
782 		return err;
783 
784 	/* retrieve response parameters */
785 	rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
786 	*qdid = le16_to_cpu(rsp_params->qdid);
787 
788 	return 0;
789 }
790 
791 /**
792  * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
793  * @mc_io:	Pointer to MC portal's I/O object
794  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
795  * @token:	Token of DPNI object
796  * @data_offset: Tx data offset (from start of buffer)
797  *
798  * Return:	'0' on Success; Error code otherwise.
799  */
800 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
801 			    u32 cmd_flags,
802 			    u16 token,
803 			    u16 *data_offset)
804 {
805 	struct fsl_mc_command cmd = { 0 };
806 	struct dpni_rsp_get_tx_data_offset *rsp_params;
807 	int err;
808 
809 	/* prepare command */
810 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
811 					  cmd_flags,
812 					  token);
813 
814 	/* send command to mc*/
815 	err = mc_send_command(mc_io, &cmd);
816 	if (err)
817 		return err;
818 
819 	/* retrieve response parameters */
820 	rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
821 	*data_offset = le16_to_cpu(rsp_params->data_offset);
822 
823 	return 0;
824 }
825 
826 /**
827  * dpni_set_link_cfg() - set the link configuration.
828  * @mc_io:	Pointer to MC portal's I/O object
829  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
830  * @token:	Token of DPNI object
831  * @cfg:	Link configuration
832  *
833  * Return:	'0' on Success; Error code otherwise.
834  */
835 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
836 		      u32 cmd_flags,
837 		      u16 token,
838 		      const struct dpni_link_cfg *cfg)
839 {
840 	struct fsl_mc_command cmd = { 0 };
841 	struct dpni_cmd_link_cfg *cmd_params;
842 
843 	/* prepare command */
844 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
845 					  cmd_flags,
846 					  token);
847 	cmd_params = (struct dpni_cmd_link_cfg *)cmd.params;
848 	cmd_params->rate = cpu_to_le32(cfg->rate);
849 	cmd_params->options = cpu_to_le64(cfg->options);
850 
851 	/* send command to mc*/
852 	return mc_send_command(mc_io, &cmd);
853 }
854 
855 /**
856  * dpni_get_link_cfg() - return the link configuration
857  * @mc_io:	Pointer to MC portal's I/O object
858  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
859  * @token:	Token of DPNI object
860  * @cfg:	Link configuration from dpni object
861  *
862  * Return:	'0' on Success; Error code otherwise.
863  */
864 int dpni_get_link_cfg(struct fsl_mc_io *mc_io,
865 		      u32 cmd_flags,
866 		      u16 token,
867 		      struct dpni_link_cfg *cfg)
868 {
869 	struct fsl_mc_command cmd = { 0 };
870 	struct dpni_cmd_link_cfg *rsp_params;
871 	int err;
872 
873 	/* prepare command */
874 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG,
875 					  cmd_flags,
876 					  token);
877 
878 	/* send command to mc*/
879 	err = mc_send_command(mc_io, &cmd);
880 	if (err)
881 		return err;
882 
883 	/* retrieve response parameters */
884 	rsp_params = (struct dpni_cmd_link_cfg *)cmd.params;
885 	cfg->rate = le32_to_cpu(rsp_params->rate);
886 	cfg->options = le64_to_cpu(rsp_params->options);
887 
888 	return err;
889 }
890 
891 /**
892  * dpni_get_link_state() - Return the link state (either up or down)
893  * @mc_io:	Pointer to MC portal's I/O object
894  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
895  * @token:	Token of DPNI object
896  * @state:	Returned link state;
897  *
898  * Return:	'0' on Success; Error code otherwise.
899  */
900 int dpni_get_link_state(struct fsl_mc_io *mc_io,
901 			u32 cmd_flags,
902 			u16 token,
903 			struct dpni_link_state *state)
904 {
905 	struct fsl_mc_command cmd = { 0 };
906 	struct dpni_rsp_get_link_state *rsp_params;
907 	int err;
908 
909 	/* prepare command */
910 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
911 					  cmd_flags,
912 					  token);
913 
914 	/* send command to mc*/
915 	err = mc_send_command(mc_io, &cmd);
916 	if (err)
917 		return err;
918 
919 	/* retrieve response parameters */
920 	rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
921 	state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
922 	state->rate = le32_to_cpu(rsp_params->rate);
923 	state->options = le64_to_cpu(rsp_params->options);
924 
925 	return 0;
926 }
927 
928 /**
929  * dpni_set_max_frame_length() - Set the maximum received frame length.
930  * @mc_io:	Pointer to MC portal's I/O object
931  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
932  * @token:	Token of DPNI object
933  * @max_frame_length:	Maximum received frame length (in
934  *				bytes); frame is discarded if its
935  *				length exceeds this value
936  *
937  * Return:	'0' on Success; Error code otherwise.
938  */
939 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
940 			      u32 cmd_flags,
941 			      u16 token,
942 			      u16 max_frame_length)
943 {
944 	struct fsl_mc_command cmd = { 0 };
945 	struct dpni_cmd_set_max_frame_length *cmd_params;
946 
947 	/* prepare command */
948 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
949 					  cmd_flags,
950 					  token);
951 	cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
952 	cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
953 
954 	/* send command to mc*/
955 	return mc_send_command(mc_io, &cmd);
956 }
957 
958 /**
959  * dpni_get_max_frame_length() - Get the maximum received frame length.
960  * @mc_io:	Pointer to MC portal's I/O object
961  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
962  * @token:	Token of DPNI object
963  * @max_frame_length:	Maximum received frame length (in
964  *				bytes); frame is discarded if its
965  *				length exceeds this value
966  *
967  * Return:	'0' on Success; Error code otherwise.
968  */
969 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
970 			      u32 cmd_flags,
971 			      u16 token,
972 			      u16 *max_frame_length)
973 {
974 	struct fsl_mc_command cmd = { 0 };
975 	struct dpni_rsp_get_max_frame_length *rsp_params;
976 	int err;
977 
978 	/* prepare command */
979 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
980 					  cmd_flags,
981 					  token);
982 
983 	/* send command to mc*/
984 	err = mc_send_command(mc_io, &cmd);
985 	if (err)
986 		return err;
987 
988 	/* retrieve response parameters */
989 	rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
990 	*max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
991 
992 	return 0;
993 }
994 
995 /**
996  * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
997  * @mc_io:	Pointer to MC portal's I/O object
998  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
999  * @token:	Token of DPNI object
1000  * @en:		Set to '1' to enable; '0' to disable
1001  *
1002  * Return:	'0' on Success; Error code otherwise.
1003  */
1004 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1005 			       u32 cmd_flags,
1006 			       u16 token,
1007 			       int en)
1008 {
1009 	struct fsl_mc_command cmd = { 0 };
1010 	struct dpni_cmd_set_multicast_promisc *cmd_params;
1011 
1012 	/* prepare command */
1013 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1014 					  cmd_flags,
1015 					  token);
1016 	cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1017 	dpni_set_field(cmd_params->enable, ENABLE, en);
1018 
1019 	/* send command to mc*/
1020 	return mc_send_command(mc_io, &cmd);
1021 }
1022 
1023 /**
1024  * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1025  * @mc_io:	Pointer to MC portal's I/O object
1026  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1027  * @token:	Token of DPNI object
1028  * @en:		Returns '1' if enabled; '0' otherwise
1029  *
1030  * Return:	'0' on Success; Error code otherwise.
1031  */
1032 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1033 			       u32 cmd_flags,
1034 			       u16 token,
1035 			       int *en)
1036 {
1037 	struct fsl_mc_command cmd = { 0 };
1038 	struct dpni_rsp_get_multicast_promisc *rsp_params;
1039 	int err;
1040 
1041 	/* prepare command */
1042 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1043 					  cmd_flags,
1044 					  token);
1045 
1046 	/* send command to mc*/
1047 	err = mc_send_command(mc_io, &cmd);
1048 	if (err)
1049 		return err;
1050 
1051 	/* retrieve response parameters */
1052 	rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1053 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
1054 
1055 	return 0;
1056 }
1057 
1058 /**
1059  * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1060  * @mc_io:	Pointer to MC portal's I/O object
1061  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1062  * @token:	Token of DPNI object
1063  * @en:		Set to '1' to enable; '0' to disable
1064  *
1065  * Return:	'0' on Success; Error code otherwise.
1066  */
1067 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1068 			     u32 cmd_flags,
1069 			     u16 token,
1070 			     int en)
1071 {
1072 	struct fsl_mc_command cmd = { 0 };
1073 	struct dpni_cmd_set_unicast_promisc *cmd_params;
1074 
1075 	/* prepare command */
1076 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1077 					  cmd_flags,
1078 					  token);
1079 	cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1080 	dpni_set_field(cmd_params->enable, ENABLE, en);
1081 
1082 	/* send command to mc*/
1083 	return mc_send_command(mc_io, &cmd);
1084 }
1085 
1086 /**
1087  * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1088  * @mc_io:	Pointer to MC portal's I/O object
1089  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1090  * @token:	Token of DPNI object
1091  * @en:		Returns '1' if enabled; '0' otherwise
1092  *
1093  * Return:	'0' on Success; Error code otherwise.
1094  */
1095 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1096 			     u32 cmd_flags,
1097 			     u16 token,
1098 			     int *en)
1099 {
1100 	struct fsl_mc_command cmd = { 0 };
1101 	struct dpni_rsp_get_unicast_promisc *rsp_params;
1102 	int err;
1103 
1104 	/* prepare command */
1105 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1106 					  cmd_flags,
1107 					  token);
1108 
1109 	/* send command to mc*/
1110 	err = mc_send_command(mc_io, &cmd);
1111 	if (err)
1112 		return err;
1113 
1114 	/* retrieve response parameters */
1115 	rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1116 	*en = dpni_get_field(rsp_params->enabled, ENABLE);
1117 
1118 	return 0;
1119 }
1120 
1121 /**
1122  * dpni_set_primary_mac_addr() - Set the primary MAC address
1123  * @mc_io:	Pointer to MC portal's I/O object
1124  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1125  * @token:	Token of DPNI object
1126  * @mac_addr:	MAC address to set as primary address
1127  *
1128  * Return:	'0' on Success; Error code otherwise.
1129  */
1130 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1131 			      u32 cmd_flags,
1132 			      u16 token,
1133 			      const u8 mac_addr[6])
1134 {
1135 	struct fsl_mc_command cmd = { 0 };
1136 	struct dpni_cmd_set_primary_mac_addr *cmd_params;
1137 	int i;
1138 
1139 	/* prepare command */
1140 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1141 					  cmd_flags,
1142 					  token);
1143 	cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1144 	for (i = 0; i < 6; i++)
1145 		cmd_params->mac_addr[i] = mac_addr[5 - i];
1146 
1147 	/* send command to mc*/
1148 	return mc_send_command(mc_io, &cmd);
1149 }
1150 
1151 /**
1152  * dpni_get_primary_mac_addr() - Get the primary MAC address
1153  * @mc_io:	Pointer to MC portal's I/O object
1154  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1155  * @token:	Token of DPNI object
1156  * @mac_addr:	Returned MAC address
1157  *
1158  * Return:	'0' on Success; Error code otherwise.
1159  */
1160 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1161 			      u32 cmd_flags,
1162 			      u16 token,
1163 			      u8 mac_addr[6])
1164 {
1165 	struct fsl_mc_command cmd = { 0 };
1166 	struct dpni_rsp_get_primary_mac_addr *rsp_params;
1167 	int i, err;
1168 
1169 	/* prepare command */
1170 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1171 					  cmd_flags,
1172 					  token);
1173 
1174 	/* send command to mc*/
1175 	err = mc_send_command(mc_io, &cmd);
1176 	if (err)
1177 		return err;
1178 
1179 	/* retrieve response parameters */
1180 	rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1181 	for (i = 0; i < 6; i++)
1182 		mac_addr[5 - i] = rsp_params->mac_addr[i];
1183 
1184 	return 0;
1185 }
1186 
1187 /**
1188  * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1189  *			port the DPNI is attached to
1190  * @mc_io:	Pointer to MC portal's I/O object
1191  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1192  * @token:	Token of DPNI object
1193  * @mac_addr:	MAC address of the physical port, if any, otherwise 0
1194  *
1195  * The primary MAC address is not cleared by this operation.
1196  *
1197  * Return:	'0' on Success; Error code otherwise.
1198  */
1199 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1200 			   u32 cmd_flags,
1201 			   u16 token,
1202 			   u8 mac_addr[6])
1203 {
1204 	struct fsl_mc_command cmd = { 0 };
1205 	struct dpni_rsp_get_port_mac_addr *rsp_params;
1206 	int i, err;
1207 
1208 	/* prepare command */
1209 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1210 					  cmd_flags,
1211 					  token);
1212 
1213 	/* send command to mc*/
1214 	err = mc_send_command(mc_io, &cmd);
1215 	if (err)
1216 		return err;
1217 
1218 	/* retrieve response parameters */
1219 	rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1220 	for (i = 0; i < 6; i++)
1221 		mac_addr[5 - i] = rsp_params->mac_addr[i];
1222 
1223 	return 0;
1224 }
1225 
1226 /**
1227  * dpni_add_mac_addr() - Add MAC address filter
1228  * @mc_io:	Pointer to MC portal's I/O object
1229  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1230  * @token:	Token of DPNI object
1231  * @mac_addr:	MAC address to add
1232  *
1233  * Return:	'0' on Success; Error code otherwise.
1234  */
1235 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1236 		      u32 cmd_flags,
1237 		      u16 token,
1238 		      const u8 mac_addr[6])
1239 {
1240 	struct fsl_mc_command cmd = { 0 };
1241 	struct dpni_cmd_add_mac_addr *cmd_params;
1242 	int i;
1243 
1244 	/* prepare command */
1245 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1246 					  cmd_flags,
1247 					  token);
1248 	cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1249 	for (i = 0; i < 6; i++)
1250 		cmd_params->mac_addr[i] = mac_addr[5 - i];
1251 
1252 	/* send command to mc*/
1253 	return mc_send_command(mc_io, &cmd);
1254 }
1255 
1256 /**
1257  * dpni_remove_mac_addr() - Remove MAC address filter
1258  * @mc_io:	Pointer to MC portal's I/O object
1259  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1260  * @token:	Token of DPNI object
1261  * @mac_addr:	MAC address to remove
1262  *
1263  * Return:	'0' on Success; Error code otherwise.
1264  */
1265 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1266 			 u32 cmd_flags,
1267 			 u16 token,
1268 			 const u8 mac_addr[6])
1269 {
1270 	struct fsl_mc_command cmd = { 0 };
1271 	struct dpni_cmd_remove_mac_addr *cmd_params;
1272 	int i;
1273 
1274 	/* prepare command */
1275 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1276 					  cmd_flags,
1277 					  token);
1278 	cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1279 	for (i = 0; i < 6; i++)
1280 		cmd_params->mac_addr[i] = mac_addr[5 - i];
1281 
1282 	/* send command to mc*/
1283 	return mc_send_command(mc_io, &cmd);
1284 }
1285 
1286 /**
1287  * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1288  * @mc_io:	Pointer to MC portal's I/O object
1289  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1290  * @token:	Token of DPNI object
1291  * @unicast:	Set to '1' to clear unicast addresses
1292  * @multicast:	Set to '1' to clear multicast addresses
1293  *
1294  * The primary MAC address is not cleared by this operation.
1295  *
1296  * Return:	'0' on Success; Error code otherwise.
1297  */
1298 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1299 			   u32 cmd_flags,
1300 			   u16 token,
1301 			   int unicast,
1302 			   int multicast)
1303 {
1304 	struct fsl_mc_command cmd = { 0 };
1305 	struct dpni_cmd_clear_mac_filters *cmd_params;
1306 
1307 	/* prepare command */
1308 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1309 					  cmd_flags,
1310 					  token);
1311 	cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1312 	dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1313 	dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1314 
1315 	/* send command to mc*/
1316 	return mc_send_command(mc_io, &cmd);
1317 }
1318 
1319 /**
1320  * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1321  * @mc_io:	Pointer to MC portal's I/O object
1322  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1323  * @token:	Token of DPNI object
1324  * @tc_id:	Traffic class selection (0-7)
1325  * @cfg:	Traffic class distribution configuration
1326  *
1327  * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpni_prepare_key_cfg()
1328  *			first to prepare the key_cfg_iova parameter
1329  *
1330  * Return:	'0' on Success; error code otherwise.
1331  */
1332 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1333 			u32 cmd_flags,
1334 			u16 token,
1335 			u8 tc_id,
1336 			const struct dpni_rx_tc_dist_cfg *cfg)
1337 {
1338 	struct fsl_mc_command cmd = { 0 };
1339 	struct dpni_cmd_set_rx_tc_dist *cmd_params;
1340 
1341 	/* prepare command */
1342 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1343 					  cmd_flags,
1344 					  token);
1345 	cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1346 	cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1347 	cmd_params->tc_id = tc_id;
1348 	dpni_set_field(cmd_params->flags, DIST_MODE, cfg->dist_mode);
1349 	dpni_set_field(cmd_params->flags, MISS_ACTION, cfg->fs_cfg.miss_action);
1350 	cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1351 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1352 
1353 	/* send command to mc*/
1354 	return mc_send_command(mc_io, &cmd);
1355 }
1356 
1357 /**
1358  * dpni_set_congestion_notification() - Set traffic class congestion
1359  *					notification configuration
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  * @qtype:	Type of queue - Rx, Tx and Tx confirm types are supported
1364  * @tc_id:	Traffic class selection (0-7)
1365  * @cfg:	Congestion notification configuration
1366  *
1367  * Return:	'0' on Success; error code otherwise.
1368  */
1369 int dpni_set_congestion_notification(
1370 			struct fsl_mc_io *mc_io,
1371 			u32 cmd_flags,
1372 			u16 token,
1373 			enum dpni_queue_type qtype,
1374 			u8 tc_id,
1375 			const struct dpni_congestion_notification_cfg *cfg)
1376 {
1377 	struct dpni_cmd_set_congestion_notification *cmd_params;
1378 	struct fsl_mc_command cmd = { 0 };
1379 
1380 	/* prepare command */
1381 	cmd.header =
1382 		mc_encode_cmd_header(DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1383 				     cmd_flags,
1384 				     token);
1385 	cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1386 	cmd_params->qtype = qtype;
1387 	cmd_params->tc = tc_id;
1388 	cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1389 	cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1390 	cmd_params->dest_priority = cfg->dest_cfg.priority;
1391 	dpni_set_field(cmd_params->type_units, DEST_TYPE,
1392 		       cfg->dest_cfg.dest_type);
1393 	dpni_set_field(cmd_params->type_units, CONG_UNITS, cfg->units);
1394 	cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1395 	cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1396 	cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1397 	cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1398 
1399 	/* send command to mc*/
1400 	return mc_send_command(mc_io, &cmd);
1401 }
1402 
1403 /**
1404  * dpni_set_queue() - Set queue parameters
1405  * @mc_io:	Pointer to MC portal's I/O object
1406  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1407  * @token:	Token of DPNI object
1408  * @qtype:	Type of queue - all queue types are supported, although
1409  *		the command is ignored for Tx
1410  * @tc:		Traffic class, in range 0 to NUM_TCS - 1
1411  * @index:	Selects the specific queue out of the set allocated for the
1412  *		same TC. Value must be in range 0 to NUM_QUEUES - 1
1413  * @options:	A combination of DPNI_QUEUE_OPT_ values that control what
1414  *		configuration options are set on the queue
1415  * @queue:	Queue structure
1416  *
1417  * Return:	'0' on Success; Error code otherwise.
1418  */
1419 int dpni_set_queue(struct fsl_mc_io *mc_io,
1420 		   u32 cmd_flags,
1421 		   u16 token,
1422 		   enum dpni_queue_type qtype,
1423 		   u8 tc,
1424 		   u8 index,
1425 		   u8 options,
1426 		   const struct dpni_queue *queue)
1427 {
1428 	struct fsl_mc_command cmd = { 0 };
1429 	struct dpni_cmd_set_queue *cmd_params;
1430 
1431 	/* prepare command */
1432 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1433 					  cmd_flags,
1434 					  token);
1435 	cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1436 	cmd_params->qtype = qtype;
1437 	cmd_params->tc = tc;
1438 	cmd_params->index = index;
1439 	cmd_params->options = options;
1440 	cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1441 	cmd_params->dest_prio = queue->destination.priority;
1442 	dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1443 	dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1444 	dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1445 		       queue->destination.hold_active);
1446 	cmd_params->flc = cpu_to_le64(queue->flc.value);
1447 	cmd_params->user_context = cpu_to_le64(queue->user_context);
1448 
1449 	/* send command to mc */
1450 	return mc_send_command(mc_io, &cmd);
1451 }
1452 
1453 /**
1454  * dpni_get_queue() - Get queue parameters
1455  * @mc_io:	Pointer to MC portal's I/O object
1456  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1457  * @token:	Token of DPNI object
1458  * @qtype:	Type of queue - all queue types are supported
1459  * @tc:		Traffic class, in range 0 to NUM_TCS - 1
1460  * @index:	Selects the specific queue out of the set allocated for the
1461  *		same TC. Value must be in range 0 to NUM_QUEUES - 1
1462  * @queue:	Queue configuration structure
1463  * @qid:	Queue identification
1464  *
1465  * Return:	'0' on Success; Error code otherwise.
1466  */
1467 int dpni_get_queue(struct fsl_mc_io *mc_io,
1468 		   u32 cmd_flags,
1469 		   u16 token,
1470 		   enum dpni_queue_type qtype,
1471 		   u8 tc,
1472 		   u8 index,
1473 		   struct dpni_queue *queue,
1474 		   struct dpni_queue_id *qid)
1475 {
1476 	struct fsl_mc_command cmd = { 0 };
1477 	struct dpni_cmd_get_queue *cmd_params;
1478 	struct dpni_rsp_get_queue *rsp_params;
1479 	int err;
1480 
1481 	/* prepare command */
1482 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1483 					  cmd_flags,
1484 					  token);
1485 	cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1486 	cmd_params->qtype = qtype;
1487 	cmd_params->tc = tc;
1488 	cmd_params->index = index;
1489 
1490 	/* send command to mc */
1491 	err = mc_send_command(mc_io, &cmd);
1492 	if (err)
1493 		return err;
1494 
1495 	/* retrieve response parameters */
1496 	rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
1497 	queue->destination.id = le32_to_cpu(rsp_params->dest_id);
1498 	queue->destination.priority = rsp_params->dest_prio;
1499 	queue->destination.type = dpni_get_field(rsp_params->flags,
1500 						 DEST_TYPE);
1501 	queue->flc.stash_control = dpni_get_field(rsp_params->flags,
1502 						  STASH_CTRL);
1503 	queue->destination.hold_active = dpni_get_field(rsp_params->flags,
1504 							HOLD_ACTIVE);
1505 	queue->flc.value = le64_to_cpu(rsp_params->flc);
1506 	queue->user_context = le64_to_cpu(rsp_params->user_context);
1507 	qid->fqid = le32_to_cpu(rsp_params->fqid);
1508 	qid->qdbin = le16_to_cpu(rsp_params->qdbin);
1509 
1510 	return 0;
1511 }
1512 
1513 /**
1514  * dpni_get_statistics() - Get DPNI statistics
1515  * @mc_io:	Pointer to MC portal's I/O object
1516  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1517  * @token:	Token of DPNI object
1518  * @page:	Selects the statistics page to retrieve, see
1519  *		DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
1520  * @stat:	Structure containing the statistics
1521  *
1522  * Return:	'0' on Success; Error code otherwise.
1523  */
1524 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1525 			u32 cmd_flags,
1526 			u16 token,
1527 			u8 page,
1528 			union dpni_statistics *stat)
1529 {
1530 	struct fsl_mc_command cmd = { 0 };
1531 	struct dpni_cmd_get_statistics *cmd_params;
1532 	struct dpni_rsp_get_statistics *rsp_params;
1533 	int i, err;
1534 
1535 	/* prepare command */
1536 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
1537 					  cmd_flags,
1538 					  token);
1539 	cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
1540 	cmd_params->page_number = page;
1541 
1542 	/* send command to mc */
1543 	err = mc_send_command(mc_io, &cmd);
1544 	if (err)
1545 		return err;
1546 
1547 	/* retrieve response parameters */
1548 	rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
1549 	for (i = 0; i < DPNI_STATISTICS_CNT; i++)
1550 		stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
1551 
1552 	return 0;
1553 }
1554 
1555 /**
1556  * dpni_set_taildrop() - Set taildrop per queue or TC
1557  * @mc_io:	Pointer to MC portal's I/O object
1558  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1559  * @token:	Token of DPNI object
1560  * @cg_point:	Congestion point
1561  * @qtype:	Queue type on which the taildrop is configured.
1562  *		Only Rx queues are supported for now
1563  * @tc:		Traffic class to apply this taildrop to
1564  * @index:	Index of the queue if the DPNI supports multiple queues for
1565  *		traffic distribution. Ignored if CONGESTION_POINT is not 0.
1566  * @taildrop:	Taildrop structure
1567  *
1568  * Return:	'0' on Success; Error code otherwise.
1569  */
1570 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1571 		      u32 cmd_flags,
1572 		      u16 token,
1573 		      enum dpni_congestion_point cg_point,
1574 		      enum dpni_queue_type qtype,
1575 		      u8 tc,
1576 		      u8 index,
1577 		      struct dpni_taildrop *taildrop)
1578 {
1579 	struct fsl_mc_command cmd = { 0 };
1580 	struct dpni_cmd_set_taildrop *cmd_params;
1581 
1582 	/* prepare command */
1583 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
1584 					  cmd_flags,
1585 					  token);
1586 	cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
1587 	cmd_params->congestion_point = cg_point;
1588 	cmd_params->qtype = qtype;
1589 	cmd_params->tc = tc;
1590 	cmd_params->index = index;
1591 	dpni_set_field(cmd_params->enable, ENABLE, taildrop->enable);
1592 	cmd_params->units = taildrop->units;
1593 	cmd_params->threshold = cpu_to_le32(taildrop->threshold);
1594 
1595 	/* send command to mc */
1596 	return mc_send_command(mc_io, &cmd);
1597 }
1598 
1599 /**
1600  * dpni_get_taildrop() - Get taildrop information
1601  * @mc_io:	Pointer to MC portal's I/O object
1602  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1603  * @token:	Token of DPNI object
1604  * @cg_point:	Congestion point
1605  * @qtype:	Queue type on which the taildrop is configured.
1606  *		Only Rx queues are supported for now
1607  * @tc:		Traffic class to apply this taildrop to
1608  * @index:	Index of the queue if the DPNI supports multiple queues for
1609  *		traffic distribution. Ignored if CONGESTION_POINT is not 0.
1610  * @taildrop:	Taildrop structure
1611  *
1612  * Return:	'0' on Success; Error code otherwise.
1613  */
1614 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1615 		      u32 cmd_flags,
1616 		      u16 token,
1617 		      enum dpni_congestion_point cg_point,
1618 		      enum dpni_queue_type qtype,
1619 		      u8 tc,
1620 		      u8 index,
1621 		      struct dpni_taildrop *taildrop)
1622 {
1623 	struct fsl_mc_command cmd = { 0 };
1624 	struct dpni_cmd_get_taildrop *cmd_params;
1625 	struct dpni_rsp_get_taildrop *rsp_params;
1626 	int err;
1627 
1628 	/* prepare command */
1629 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
1630 					  cmd_flags,
1631 					  token);
1632 	cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
1633 	cmd_params->congestion_point = cg_point;
1634 	cmd_params->qtype = qtype;
1635 	cmd_params->tc = tc;
1636 	cmd_params->index = index;
1637 
1638 	/* send command to mc */
1639 	err = mc_send_command(mc_io, &cmd);
1640 	if (err)
1641 		return err;
1642 
1643 	/* retrieve response parameters */
1644 	rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
1645 	taildrop->enable = dpni_get_field(rsp_params->enable, ENABLE);
1646 	taildrop->units = rsp_params->units;
1647 	taildrop->threshold = le32_to_cpu(rsp_params->threshold);
1648 
1649 	return 0;
1650 }
1651 
1652 /**
1653  * dpni_get_api_version() - Get Data Path Network Interface API version
1654  * @mc_io:	Pointer to MC portal's I/O object
1655  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1656  * @major_ver:	Major version of data path network interface API
1657  * @minor_ver:	Minor version of data path network interface API
1658  *
1659  * Return:	'0' on Success; Error code otherwise.
1660  */
1661 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1662 			 u32 cmd_flags,
1663 			 u16 *major_ver,
1664 			 u16 *minor_ver)
1665 {
1666 	struct dpni_rsp_get_api_version *rsp_params;
1667 	struct fsl_mc_command cmd = { 0 };
1668 	int err;
1669 
1670 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1671 					  cmd_flags, 0);
1672 
1673 	err = mc_send_command(mc_io, &cmd);
1674 	if (err)
1675 		return err;
1676 
1677 	rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1678 	*major_ver = le16_to_cpu(rsp_params->major);
1679 	*minor_ver = le16_to_cpu(rsp_params->minor);
1680 
1681 	return 0;
1682 }
1683 
1684 /**
1685  * dpni_set_rx_fs_dist() - Set Rx flow steering distribution
1686  * @mc_io:	Pointer to MC portal's I/O object
1687  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1688  * @token:	Token of DPNI object
1689  * @cfg: Distribution configuration
1690  *
1691  * If the FS is already enabled with a previous call the classification
1692  * key will be changed but all the table rules are kept. If the
1693  * existing rules do not match the key the results will not be
1694  * predictable. It is the user responsibility to keep key integrity.
1695  * If cfg.enable is set to 1 the command will create a flow steering table
1696  * and will classify packets according to this table. The packets that
1697  * miss all the table rules will be classified according to settings
1698  * made in dpni_set_rx_hash_dist()
1699  * If cfg.enable is set to 0 the command will clear flow steering table.
1700  * The packets will be classified according to settings made in
1701  * dpni_set_rx_hash_dist()
1702  */
1703 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io,
1704 			u32 cmd_flags,
1705 			u16 token,
1706 			const struct dpni_rx_dist_cfg *cfg)
1707 {
1708 	struct dpni_cmd_set_rx_fs_dist *cmd_params;
1709 	struct fsl_mc_command cmd = { 0 };
1710 
1711 	/* prepare command */
1712 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
1713 					  cmd_flags,
1714 					  token);
1715 	cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
1716 	cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1717 	dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
1718 	cmd_params->tc = cfg->tc;
1719 	cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
1720 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1721 
1722 	/* send command to mc*/
1723 	return mc_send_command(mc_io, &cmd);
1724 }
1725 
1726 /**
1727  * dpni_set_rx_hash_dist() - Set Rx hash distribution
1728  * @mc_io:	Pointer to MC portal's I/O object
1729  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1730  * @token:	Token of DPNI object
1731  * @cfg: Distribution configuration
1732  * If cfg.enable is set to 1 the packets will be classified using a hash
1733  * function based on the key received in cfg.key_cfg_iova parameter.
1734  * If cfg.enable is set to 0 the packets will be sent to the default queue
1735  */
1736 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io,
1737 			  u32 cmd_flags,
1738 			  u16 token,
1739 			  const struct dpni_rx_dist_cfg *cfg)
1740 {
1741 	struct dpni_cmd_set_rx_hash_dist *cmd_params;
1742 	struct fsl_mc_command cmd = { 0 };
1743 
1744 	/* prepare command */
1745 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
1746 					  cmd_flags,
1747 					  token);
1748 	cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
1749 	cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1750 	dpni_set_field(cmd_params->enable, RX_HASH_DIST_ENABLE, cfg->enable);
1751 	cmd_params->tc = cfg->tc;
1752 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1753 
1754 	/* send command to mc*/
1755 	return mc_send_command(mc_io, &cmd);
1756 }
1757 
1758 /**
1759  * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1760  *			(to select a flow ID)
1761  * @mc_io:	Pointer to MC portal's I/O object
1762  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1763  * @token:	Token of DPNI object
1764  * @tc_id:	Traffic class selection (0-7)
1765  * @index:	Location in the FS table where to insert the entry.
1766  *		Only relevant if MASKING is enabled for FS
1767  *		classification on this DPNI, it is ignored for exact match.
1768  * @cfg:	Flow steering rule to add
1769  * @action:	Action to be taken as result of a classification hit
1770  *
1771  * Return:	'0' on Success; Error code otherwise.
1772  */
1773 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1774 		      u32 cmd_flags,
1775 		      u16 token,
1776 		      u8 tc_id,
1777 		      u16 index,
1778 		      const struct dpni_rule_cfg *cfg,
1779 		      const struct dpni_fs_action_cfg *action)
1780 {
1781 	struct dpni_cmd_add_fs_entry *cmd_params;
1782 	struct fsl_mc_command cmd = { 0 };
1783 
1784 	/* prepare command */
1785 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1786 					  cmd_flags,
1787 					  token);
1788 	cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1789 	cmd_params->tc_id = tc_id;
1790 	cmd_params->key_size = cfg->key_size;
1791 	cmd_params->index = cpu_to_le16(index);
1792 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1793 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1794 	cmd_params->options = cpu_to_le16(action->options);
1795 	cmd_params->flow_id = cpu_to_le16(action->flow_id);
1796 	cmd_params->flc = cpu_to_le64(action->flc);
1797 
1798 	/* send command to mc*/
1799 	return mc_send_command(mc_io, &cmd);
1800 }
1801 
1802 /**
1803  * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1804  *			    traffic class
1805  * @mc_io:	Pointer to MC portal's I/O object
1806  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1807  * @token:	Token of DPNI object
1808  * @tc_id:	Traffic class selection (0-7)
1809  * @cfg:	Flow steering rule to remove
1810  *
1811  * Return:	'0' on Success; Error code otherwise.
1812  */
1813 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1814 			 u32 cmd_flags,
1815 			 u16 token,
1816 			 u8 tc_id,
1817 			 const struct dpni_rule_cfg *cfg)
1818 {
1819 	struct dpni_cmd_remove_fs_entry *cmd_params;
1820 	struct fsl_mc_command cmd = { 0 };
1821 
1822 	/* prepare command */
1823 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1824 					  cmd_flags,
1825 					  token);
1826 	cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1827 	cmd_params->tc_id = tc_id;
1828 	cmd_params->key_size = cfg->key_size;
1829 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1830 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1831 
1832 	/* send command to mc*/
1833 	return mc_send_command(mc_io, &cmd);
1834 }
1835 
1836 /**
1837  * dpni_set_qos_table() - Set QoS mapping table
1838  * @mc_io:	Pointer to MC portal's I/O object
1839  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1840  * @token:	Token of DPNI object
1841  * @cfg:	QoS table configuration
1842  *
1843  * This function and all QoS-related functions require that
1844  *'max_tcs > 1' was set at DPNI creation.
1845  *
1846  * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1847  *			prepare the key_cfg_iova parameter
1848  *
1849  * Return:	'0' on Success; Error code otherwise.
1850  */
1851 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1852 		       u32 cmd_flags,
1853 		       u16 token,
1854 		       const struct dpni_qos_tbl_cfg *cfg)
1855 {
1856 	struct dpni_cmd_set_qos_table *cmd_params;
1857 	struct fsl_mc_command cmd = { 0 };
1858 
1859 	/* prepare command */
1860 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1861 					  cmd_flags,
1862 					  token);
1863 	cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1864 	cmd_params->default_tc = cfg->default_tc;
1865 	cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1866 	dpni_set_field(cmd_params->discard_on_miss, DISCARD_ON_MISS,
1867 		       cfg->discard_on_miss);
1868 
1869 	/* send command to mc*/
1870 	return mc_send_command(mc_io, &cmd);
1871 }
1872 
1873 /**
1874  * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1875  * @mc_io:	Pointer to MC portal's I/O object
1876  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1877  * @token:	Token of DPNI object
1878  * @cfg:	QoS rule to add
1879  * @tc_id:	Traffic class selection (0-7)
1880  * @index:	Location in the QoS table where to insert the entry.
1881  *		Only relevant if MASKING is enabled for QoS classification on
1882  *		this DPNI, it is ignored for exact match.
1883  *
1884  * Return:	'0' on Success; Error code otherwise.
1885  */
1886 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1887 		       u32 cmd_flags,
1888 		       u16 token,
1889 		       const struct dpni_rule_cfg *cfg,
1890 		       u8 tc_id,
1891 		       u16 index)
1892 {
1893 	struct dpni_cmd_add_qos_entry *cmd_params;
1894 	struct fsl_mc_command cmd = { 0 };
1895 
1896 	/* prepare command */
1897 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1898 					  cmd_flags,
1899 					  token);
1900 	cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1901 	cmd_params->tc_id = tc_id;
1902 	cmd_params->key_size = cfg->key_size;
1903 	cmd_params->index = cpu_to_le16(index);
1904 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1905 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1906 
1907 	/* send command to mc*/
1908 	return mc_send_command(mc_io, &cmd);
1909 }
1910 
1911 /**
1912  * dpni_remove_qos_entry() - Remove QoS mapping entry
1913  * @mc_io:	Pointer to MC portal's I/O object
1914  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1915  * @token:	Token of DPNI object
1916  * @cfg:	QoS rule to remove
1917  *
1918  * Return:	'0' on Success; Error code otherwise.
1919  */
1920 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1921 			  u32 cmd_flags,
1922 			  u16 token,
1923 			  const struct dpni_rule_cfg *cfg)
1924 {
1925 	struct dpni_cmd_remove_qos_entry *cmd_params;
1926 	struct fsl_mc_command cmd = { 0 };
1927 
1928 	/* prepare command */
1929 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1930 					  cmd_flags,
1931 					  token);
1932 	cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1933 	cmd_params->key_size = cfg->key_size;
1934 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1935 	cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1936 
1937 	/* send command to mc*/
1938 	return mc_send_command(mc_io, &cmd);
1939 }
1940 
1941 /**
1942  * dpni_clear_qos_table() - Clear all QoS mapping entries
1943  * @mc_io:	Pointer to MC portal's I/O object
1944  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1945  * @token:	Token of DPNI object
1946  *
1947  * Following this function call, all frames are directed to
1948  * the default traffic class (0)
1949  *
1950  * Return:	'0' on Success; Error code otherwise.
1951  */
1952 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1953 			 u32 cmd_flags,
1954 			 u16 token)
1955 {
1956 	struct fsl_mc_command cmd = { 0 };
1957 
1958 	/* prepare command */
1959 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1960 					  cmd_flags,
1961 					  token);
1962 
1963 	/* send command to mc*/
1964 	return mc_send_command(mc_io, &cmd);
1965 }
1966 
1967 /**
1968  * dpni_set_tx_shaping() - Set the transmit shaping
1969  * @mc_io:		Pointer to MC portal's I/O object
1970  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
1971  * @token:		Token of DPNI object
1972  * @tx_cr_shaper:	TX committed rate shaping configuration
1973  * @tx_er_shaper:	TX excess rate shaping configuration
1974  * @coupled:		Committed and excess rate shapers are coupled
1975  *
1976  * Return:	'0' on Success; Error code otherwise.
1977  */
1978 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
1979 			u32 cmd_flags,
1980 			u16 token,
1981 			const struct dpni_tx_shaping_cfg *tx_cr_shaper,
1982 			const struct dpni_tx_shaping_cfg *tx_er_shaper,
1983 			int coupled)
1984 {
1985 	struct dpni_cmd_set_tx_shaping *cmd_params;
1986 	struct fsl_mc_command cmd = { 0 };
1987 
1988 	/* prepare command */
1989 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
1990 					  cmd_flags,
1991 					  token);
1992 	cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
1993 	cmd_params->tx_cr_max_burst_size = cpu_to_le16(tx_cr_shaper->max_burst_size);
1994 	cmd_params->tx_er_max_burst_size = cpu_to_le16(tx_er_shaper->max_burst_size);
1995 	cmd_params->tx_cr_rate_limit = cpu_to_le32(tx_cr_shaper->rate_limit);
1996 	cmd_params->tx_er_rate_limit = cpu_to_le32(tx_er_shaper->rate_limit);
1997 	dpni_set_field(cmd_params->coupled, COUPLED, coupled);
1998 
1999 	/* send command to mc*/
2000 	return mc_send_command(mc_io, &cmd);
2001 }
2002