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