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