]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/fsl-dpaa2/ethernet/dpni.c
Revert "staging: fsl-mc: move mc-cmd.h contents in the public header"
[karo-tx-linux.git] / drivers / staging / fsl-dpaa2 / ethernet / dpni.c
1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
2  * Copyright 2016 NXP
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the above-listed copyright holders nor the
12  * names of any contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 #include <linux/kernel.h>
34 #include <linux/errno.h>
35 #include "../../fsl-mc/include/mc.h"
36 #include "../../fsl-mc/include/mc-cmd.h"
37 #include "dpni.h"
38 #include "dpni-cmd.h"
39
40 /**
41  * dpni_prepare_key_cfg() - function prepare extract parameters
42  * @cfg: defining a full Key Generation profile (rule)
43  * @key_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
44  *
45  * This function has to be called before the following functions:
46  *      - dpni_set_rx_tc_dist()
47  *      - dpni_set_qos_table()
48  */
49 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg, u8 *key_cfg_buf)
50 {
51         int i, j;
52         struct dpni_ext_set_rx_tc_dist *dpni_ext;
53         struct dpni_dist_extract *extr;
54
55         if (cfg->num_extracts > DPKG_MAX_NUM_OF_EXTRACTS)
56                 return -EINVAL;
57
58         dpni_ext = (struct dpni_ext_set_rx_tc_dist *)key_cfg_buf;
59         dpni_ext->num_extracts = cfg->num_extracts;
60
61         for (i = 0; i < cfg->num_extracts; i++) {
62                 extr = &dpni_ext->extracts[i];
63
64                 switch (cfg->extracts[i].type) {
65                 case DPKG_EXTRACT_FROM_HDR:
66                         extr->prot = cfg->extracts[i].extract.from_hdr.prot;
67                         dpni_set_field(extr->efh_type, EFH_TYPE,
68                                        cfg->extracts[i].extract.from_hdr.type);
69                         extr->size = cfg->extracts[i].extract.from_hdr.size;
70                         extr->offset = cfg->extracts[i].extract.from_hdr.offset;
71                         extr->field = cpu_to_le32(
72                                 cfg->extracts[i].extract.from_hdr.field);
73                         extr->hdr_index =
74                                 cfg->extracts[i].extract.from_hdr.hdr_index;
75                         break;
76                 case DPKG_EXTRACT_FROM_DATA:
77                         extr->size = cfg->extracts[i].extract.from_data.size;
78                         extr->offset =
79                                 cfg->extracts[i].extract.from_data.offset;
80                         break;
81                 case DPKG_EXTRACT_FROM_PARSE:
82                         extr->size = cfg->extracts[i].extract.from_parse.size;
83                         extr->offset =
84                                 cfg->extracts[i].extract.from_parse.offset;
85                         break;
86                 default:
87                         return -EINVAL;
88                 }
89
90                 extr->num_of_byte_masks = cfg->extracts[i].num_of_byte_masks;
91                 dpni_set_field(extr->extract_type, EXTRACT_TYPE,
92                                cfg->extracts[i].type);
93
94                 for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
95                         extr->masks[j].mask = cfg->extracts[i].masks[j].mask;
96                         extr->masks[j].offset =
97                                 cfg->extracts[i].masks[j].offset;
98                 }
99         }
100
101         return 0;
102 }
103
104 /**
105  * dpni_open() - Open a control session for the specified object
106  * @mc_io:      Pointer to MC portal's I/O object
107  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
108  * @dpni_id:    DPNI unique ID
109  * @token:      Returned token; use in subsequent API calls
110  *
111  * This function can be used to open a control session for an
112  * already created object; an object may have been declared in
113  * the DPL or by calling the dpni_create() function.
114  * This function returns a unique authentication token,
115  * associated with the specific object ID and the specific MC
116  * portal; this token must be used in all subsequent commands for
117  * this specific object.
118  *
119  * Return:      '0' on Success; Error code otherwise.
120  */
121 int dpni_open(struct fsl_mc_io *mc_io,
122               u32 cmd_flags,
123               int dpni_id,
124               u16 *token)
125 {
126         struct mc_command cmd = { 0 };
127         struct dpni_cmd_open *cmd_params;
128
129         int err;
130
131         /* prepare command */
132         cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
133                                           cmd_flags,
134                                           0);
135         cmd_params = (struct dpni_cmd_open *)cmd.params;
136         cmd_params->dpni_id = cpu_to_le32(dpni_id);
137
138         /* send command to mc*/
139         err = mc_send_command(mc_io, &cmd);
140         if (err)
141                 return err;
142
143         /* retrieve response parameters */
144         *token = mc_cmd_hdr_read_token(&cmd);
145
146         return 0;
147 }
148
149 /**
150  * dpni_close() - Close the control session of the object
151  * @mc_io:      Pointer to MC portal's I/O object
152  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
153  * @token:      Token of DPNI object
154  *
155  * After this function is called, no further operations are
156  * allowed on the object without opening a new control session.
157  *
158  * Return:      '0' on Success; Error code otherwise.
159  */
160 int dpni_close(struct fsl_mc_io *mc_io,
161                u32 cmd_flags,
162                u16 token)
163 {
164         struct mc_command cmd = { 0 };
165
166         /* prepare command */
167         cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
168                                           cmd_flags,
169                                           token);
170
171         /* send command to mc*/
172         return mc_send_command(mc_io, &cmd);
173 }
174
175 /**
176  * dpni_set_pools() - Set buffer pools configuration
177  * @mc_io:      Pointer to MC portal's I/O object
178  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
179  * @token:      Token of DPNI object
180  * @cfg:        Buffer pools configuration
181  *
182  * mandatory for DPNI operation
183  * warning:Allowed only when DPNI is disabled
184  *
185  * Return:      '0' on Success; Error code otherwise.
186  */
187 int dpni_set_pools(struct fsl_mc_io *mc_io,
188                    u32 cmd_flags,
189                    u16 token,
190                    const struct dpni_pools_cfg *cfg)
191 {
192         struct mc_command cmd = { 0 };
193         struct dpni_cmd_set_pools *cmd_params;
194         int i;
195
196         /* prepare command */
197         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
198                                           cmd_flags,
199                                           token);
200         cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
201         cmd_params->num_dpbp = cfg->num_dpbp;
202         for (i = 0; i < DPNI_MAX_DPBP; i++) {
203                 cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
204                 cmd_params->buffer_size[i] =
205                         cpu_to_le16(cfg->pools[i].buffer_size);
206                 cmd_params->backup_pool_mask |=
207                         DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
208         }
209
210         /* send command to mc*/
211         return mc_send_command(mc_io, &cmd);
212 }
213
214 /**
215  * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
216  * @mc_io:      Pointer to MC portal's I/O object
217  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
218  * @token:              Token of DPNI object
219  *
220  * Return:      '0' on Success; Error code otherwise.
221  */
222 int dpni_enable(struct fsl_mc_io *mc_io,
223                 u32 cmd_flags,
224                 u16 token)
225 {
226         struct mc_command cmd = { 0 };
227
228         /* prepare command */
229         cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
230                                           cmd_flags,
231                                           token);
232
233         /* send command to mc*/
234         return mc_send_command(mc_io, &cmd);
235 }
236
237 /**
238  * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
239  * @mc_io:      Pointer to MC portal's I/O object
240  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
241  * @token:      Token of DPNI object
242  *
243  * Return:      '0' on Success; Error code otherwise.
244  */
245 int dpni_disable(struct fsl_mc_io *mc_io,
246                  u32 cmd_flags,
247                  u16 token)
248 {
249         struct mc_command cmd = { 0 };
250
251         /* prepare command */
252         cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
253                                           cmd_flags,
254                                           token);
255
256         /* send command to mc*/
257         return mc_send_command(mc_io, &cmd);
258 }
259
260 /**
261  * dpni_is_enabled() - Check if the DPNI is enabled.
262  * @mc_io:      Pointer to MC portal's I/O object
263  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
264  * @token:      Token of DPNI object
265  * @en:         Returns '1' if object is enabled; '0' otherwise
266  *
267  * Return:      '0' on Success; Error code otherwise.
268  */
269 int dpni_is_enabled(struct fsl_mc_io *mc_io,
270                     u32 cmd_flags,
271                     u16 token,
272                     int *en)
273 {
274         struct mc_command cmd = { 0 };
275         struct dpni_rsp_is_enabled *rsp_params;
276         int err;
277
278         /* prepare command */
279         cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
280                                           cmd_flags,
281                                           token);
282
283         /* send command to mc*/
284         err = mc_send_command(mc_io, &cmd);
285         if (err)
286                 return err;
287
288         /* retrieve response parameters */
289         rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
290         *en = dpni_get_field(rsp_params->enabled, ENABLE);
291
292         return 0;
293 }
294
295 /**
296  * dpni_reset() - Reset the DPNI, returns the object to initial state.
297  * @mc_io:      Pointer to MC portal's I/O object
298  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
299  * @token:      Token of DPNI object
300  *
301  * Return:      '0' on Success; Error code otherwise.
302  */
303 int dpni_reset(struct fsl_mc_io *mc_io,
304                u32 cmd_flags,
305                u16 token)
306 {
307         struct mc_command cmd = { 0 };
308
309         /* prepare command */
310         cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
311                                           cmd_flags,
312                                           token);
313
314         /* send command to mc*/
315         return mc_send_command(mc_io, &cmd);
316 }
317
318 /**
319  * dpni_set_irq_enable() - Set overall interrupt state.
320  * @mc_io:      Pointer to MC portal's I/O object
321  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
322  * @token:      Token of DPNI object
323  * @irq_index:  The interrupt index to configure
324  * @en:         Interrupt state: - enable = 1, disable = 0
325  *
326  * Allows GPP software to control when interrupts are generated.
327  * Each interrupt can have up to 32 causes.  The enable/disable control's the
328  * overall interrupt state. if the interrupt is disabled no causes will cause
329  * an interrupt.
330  *
331  * Return:      '0' on Success; Error code otherwise.
332  */
333 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
334                         u32 cmd_flags,
335                         u16 token,
336                         u8 irq_index,
337                         u8 en)
338 {
339         struct mc_command cmd = { 0 };
340         struct dpni_cmd_set_irq_enable *cmd_params;
341
342         /* prepare command */
343         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
344                                           cmd_flags,
345                                           token);
346         cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
347         dpni_set_field(cmd_params->enable, ENABLE, en);
348         cmd_params->irq_index = irq_index;
349
350         /* send command to mc*/
351         return mc_send_command(mc_io, &cmd);
352 }
353
354 /**
355  * dpni_get_irq_enable() - Get overall interrupt state
356  * @mc_io:      Pointer to MC portal's I/O object
357  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
358  * @token:      Token of DPNI object
359  * @irq_index:  The interrupt index to configure
360  * @en:         Returned interrupt state - enable = 1, disable = 0
361  *
362  * Return:      '0' on Success; Error code otherwise.
363  */
364 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
365                         u32 cmd_flags,
366                         u16 token,
367                         u8 irq_index,
368                         u8 *en)
369 {
370         struct mc_command cmd = { 0 };
371         struct dpni_cmd_get_irq_enable *cmd_params;
372         struct dpni_rsp_get_irq_enable *rsp_params;
373
374         int err;
375
376         /* prepare command */
377         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
378                                           cmd_flags,
379                                           token);
380         cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
381         cmd_params->irq_index = irq_index;
382
383         /* send command to mc*/
384         err = mc_send_command(mc_io, &cmd);
385         if (err)
386                 return err;
387
388         /* retrieve response parameters */
389         rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
390         *en = dpni_get_field(rsp_params->enabled, ENABLE);
391
392         return 0;
393 }
394
395 /**
396  * dpni_set_irq_mask() - Set interrupt mask.
397  * @mc_io:      Pointer to MC portal's I/O object
398  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
399  * @token:      Token of DPNI object
400  * @irq_index:  The interrupt index to configure
401  * @mask:       event mask to trigger interrupt;
402  *                      each bit:
403  *                              0 = ignore event
404  *                              1 = consider event for asserting IRQ
405  *
406  * Every interrupt can have up to 32 causes and the interrupt model supports
407  * masking/unmasking each cause independently
408  *
409  * Return:      '0' on Success; Error code otherwise.
410  */
411 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
412                       u32 cmd_flags,
413                       u16 token,
414                       u8 irq_index,
415                       u32 mask)
416 {
417         struct mc_command cmd = { 0 };
418         struct dpni_cmd_set_irq_mask *cmd_params;
419
420         /* prepare command */
421         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
422                                           cmd_flags,
423                                           token);
424         cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
425         cmd_params->mask = cpu_to_le32(mask);
426         cmd_params->irq_index = irq_index;
427
428         /* send command to mc*/
429         return mc_send_command(mc_io, &cmd);
430 }
431
432 /**
433  * dpni_get_irq_mask() - Get interrupt mask.
434  * @mc_io:      Pointer to MC portal's I/O object
435  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
436  * @token:      Token of DPNI object
437  * @irq_index:  The interrupt index to configure
438  * @mask:       Returned event mask to trigger interrupt
439  *
440  * Every interrupt can have up to 32 causes and the interrupt model supports
441  * masking/unmasking each cause independently
442  *
443  * Return:      '0' on Success; Error code otherwise.
444  */
445 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
446                       u32 cmd_flags,
447                       u16 token,
448                       u8 irq_index,
449                       u32 *mask)
450 {
451         struct mc_command cmd = { 0 };
452         struct dpni_cmd_get_irq_mask *cmd_params;
453         struct dpni_rsp_get_irq_mask *rsp_params;
454         int err;
455
456         /* prepare command */
457         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
458                                           cmd_flags,
459                                           token);
460         cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
461         cmd_params->irq_index = irq_index;
462
463         /* send command to mc*/
464         err = mc_send_command(mc_io, &cmd);
465         if (err)
466                 return err;
467
468         /* retrieve response parameters */
469         rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
470         *mask = le32_to_cpu(rsp_params->mask);
471
472         return 0;
473 }
474
475 /**
476  * dpni_get_irq_status() - Get the current status of any pending interrupts.
477  * @mc_io:      Pointer to MC portal's I/O object
478  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
479  * @token:      Token of DPNI object
480  * @irq_index:  The interrupt index to configure
481  * @status:     Returned interrupts status - one bit per cause:
482  *                      0 = no interrupt pending
483  *                      1 = interrupt pending
484  *
485  * Return:      '0' on Success; Error code otherwise.
486  */
487 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
488                         u32 cmd_flags,
489                         u16 token,
490                         u8 irq_index,
491                         u32 *status)
492 {
493         struct mc_command cmd = { 0 };
494         struct dpni_cmd_get_irq_status *cmd_params;
495         struct dpni_rsp_get_irq_status *rsp_params;
496         int err;
497
498         /* prepare command */
499         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
500                                           cmd_flags,
501                                           token);
502         cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
503         cmd_params->status = cpu_to_le32(*status);
504         cmd_params->irq_index = irq_index;
505
506         /* send command to mc*/
507         err = mc_send_command(mc_io, &cmd);
508         if (err)
509                 return err;
510
511         /* retrieve response parameters */
512         rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
513         *status = le32_to_cpu(rsp_params->status);
514
515         return 0;
516 }
517
518 /**
519  * dpni_clear_irq_status() - Clear a pending interrupt's status
520  * @mc_io:      Pointer to MC portal's I/O object
521  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
522  * @token:      Token of DPNI object
523  * @irq_index:  The interrupt index to configure
524  * @status:     bits to clear (W1C) - one bit per cause:
525  *                      0 = don't change
526  *                      1 = clear status bit
527  *
528  * Return:      '0' on Success; Error code otherwise.
529  */
530 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
531                           u32 cmd_flags,
532                           u16 token,
533                           u8 irq_index,
534                           u32 status)
535 {
536         struct mc_command cmd = { 0 };
537         struct dpni_cmd_clear_irq_status *cmd_params;
538
539         /* prepare command */
540         cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
541                                           cmd_flags,
542                                           token);
543         cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
544         cmd_params->irq_index = irq_index;
545         cmd_params->status = cpu_to_le32(status);
546
547         /* send command to mc*/
548         return mc_send_command(mc_io, &cmd);
549 }
550
551 /**
552  * dpni_get_attributes() - Retrieve DPNI attributes.
553  * @mc_io:      Pointer to MC portal's I/O object
554  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
555  * @token:      Token of DPNI object
556  * @attr:       Object's attributes
557  *
558  * Return:      '0' on Success; Error code otherwise.
559  */
560 int dpni_get_attributes(struct fsl_mc_io *mc_io,
561                         u32 cmd_flags,
562                         u16 token,
563                         struct dpni_attr *attr)
564 {
565         struct mc_command cmd = { 0 };
566         struct dpni_rsp_get_attr *rsp_params;
567
568         int err;
569
570         /* prepare command */
571         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
572                                           cmd_flags,
573                                           token);
574
575         /* send command to mc*/
576         err = mc_send_command(mc_io, &cmd);
577         if (err)
578                 return err;
579
580         /* retrieve response parameters */
581         rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
582         attr->options = le32_to_cpu(rsp_params->options);
583         attr->num_queues = rsp_params->num_queues;
584         attr->num_tcs = rsp_params->num_tcs;
585         attr->mac_filter_entries = rsp_params->mac_filter_entries;
586         attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
587         attr->qos_entries = rsp_params->qos_entries;
588         attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
589         attr->qos_key_size = rsp_params->qos_key_size;
590         attr->fs_key_size = rsp_params->fs_key_size;
591         attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
592
593         return 0;
594 }
595
596 /**
597  * dpni_set_errors_behavior() - Set errors behavior
598  * @mc_io:      Pointer to MC portal's I/O object
599  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
600  * @token:      Token of DPNI object
601  * @cfg:        Errors configuration
602  *
603  * this function may be called numerous times with different
604  * error masks
605  *
606  * Return:      '0' on Success; Error code otherwise.
607  */
608 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
609                              u32 cmd_flags,
610                              u16 token,
611                              struct dpni_error_cfg *cfg)
612 {
613         struct mc_command cmd = { 0 };
614         struct dpni_cmd_set_errors_behavior *cmd_params;
615
616         /* prepare command */
617         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
618                                           cmd_flags,
619                                           token);
620         cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
621         cmd_params->errors = cpu_to_le32(cfg->errors);
622         dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
623         dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
624
625         /* send command to mc*/
626         return mc_send_command(mc_io, &cmd);
627 }
628
629 /**
630  * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
631  * @mc_io:      Pointer to MC portal's I/O object
632  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
633  * @token:      Token of DPNI object
634  * @qtype:      Type of queue to retrieve configuration for
635  * @layout:     Returns buffer layout attributes
636  *
637  * Return:      '0' on Success; Error code otherwise.
638  */
639 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
640                            u32 cmd_flags,
641                            u16 token,
642                            enum dpni_queue_type qtype,
643                            struct dpni_buffer_layout *layout)
644 {
645         struct mc_command cmd = { 0 };
646         struct dpni_cmd_get_buffer_layout *cmd_params;
647         struct dpni_rsp_get_buffer_layout *rsp_params;
648         int err;
649
650         /* prepare command */
651         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
652                                           cmd_flags,
653                                           token);
654         cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
655         cmd_params->qtype = qtype;
656
657         /* send command to mc*/
658         err = mc_send_command(mc_io, &cmd);
659         if (err)
660                 return err;
661
662         /* retrieve response parameters */
663         rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
664         layout->pass_timestamp = dpni_get_field(rsp_params->flags, PASS_TS);
665         layout->pass_parser_result = dpni_get_field(rsp_params->flags, PASS_PR);
666         layout->pass_frame_status = dpni_get_field(rsp_params->flags, PASS_FS);
667         layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
668         layout->data_align = le16_to_cpu(rsp_params->data_align);
669         layout->data_head_room = le16_to_cpu(rsp_params->head_room);
670         layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
671
672         return 0;
673 }
674
675 /**
676  * dpni_set_buffer_layout() - Set buffer layout configuration.
677  * @mc_io:      Pointer to MC portal's I/O object
678  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
679  * @token:      Token of DPNI object
680  * @qtype:      Type of queue this configuration applies to
681  * @layout:     Buffer layout configuration
682  *
683  * Return:      '0' on Success; Error code otherwise.
684  *
685  * @warning     Allowed only when DPNI is disabled
686  */
687 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
688                            u32 cmd_flags,
689                            u16 token,
690                            enum dpni_queue_type qtype,
691                            const struct dpni_buffer_layout *layout)
692 {
693         struct mc_command cmd = { 0 };
694         struct dpni_cmd_set_buffer_layout *cmd_params;
695
696         /* prepare command */
697         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
698                                           cmd_flags,
699                                           token);
700         cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
701         cmd_params->qtype = qtype;
702         cmd_params->options = cpu_to_le16(layout->options);
703         dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
704         dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
705         dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
706         cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
707         cmd_params->data_align = cpu_to_le16(layout->data_align);
708         cmd_params->head_room = cpu_to_le16(layout->data_head_room);
709         cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
710
711         /* send command to mc*/
712         return mc_send_command(mc_io, &cmd);
713 }
714
715 /**
716  * dpni_set_offload() - Set DPNI offload configuration.
717  * @mc_io:      Pointer to MC portal's I/O object
718  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
719  * @token:      Token of DPNI object
720  * @type:       Type of DPNI offload
721  * @config:     Offload configuration.
722  *              For checksum offloads, non-zero value enables the offload
723  *
724  * Return:     '0' on Success; Error code otherwise.
725  *
726  * @warning    Allowed only when DPNI is disabled
727  */
728
729 int dpni_set_offload(struct fsl_mc_io *mc_io,
730                      u32 cmd_flags,
731                      u16 token,
732                      enum dpni_offload type,
733                      u32 config)
734 {
735         struct mc_command cmd = { 0 };
736         struct dpni_cmd_set_offload *cmd_params;
737
738         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
739                                           cmd_flags,
740                                           token);
741         cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
742         cmd_params->dpni_offload = type;
743         cmd_params->config = cpu_to_le32(config);
744
745         return mc_send_command(mc_io, &cmd);
746 }
747
748 int dpni_get_offload(struct fsl_mc_io *mc_io,
749                      u32 cmd_flags,
750                      u16 token,
751                      enum dpni_offload type,
752                      u32 *config)
753 {
754         struct mc_command cmd = { 0 };
755         struct dpni_cmd_get_offload *cmd_params;
756         struct dpni_rsp_get_offload *rsp_params;
757         int err;
758
759         /* prepare command */
760         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
761                                           cmd_flags,
762                                           token);
763         cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
764         cmd_params->dpni_offload = type;
765
766         /* send command to mc*/
767         err = mc_send_command(mc_io, &cmd);
768         if (err)
769                 return err;
770
771         /* retrieve response parameters */
772         rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
773         *config = le32_to_cpu(rsp_params->config);
774
775         return 0;
776 }
777
778 /**
779  * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
780  *                      for enqueue operations
781  * @mc_io:      Pointer to MC portal's I/O object
782  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
783  * @token:      Token of DPNI object
784  * @qtype:      Type of queue to receive QDID for
785  * @qdid:       Returned virtual QDID value that should be used as an argument
786  *                      in all enqueue operations
787  *
788  * Return:      '0' on Success; Error code otherwise.
789  */
790 int dpni_get_qdid(struct fsl_mc_io *mc_io,
791                   u32 cmd_flags,
792                   u16 token,
793                   enum dpni_queue_type qtype,
794                   u16 *qdid)
795 {
796         struct mc_command cmd = { 0 };
797         struct dpni_cmd_get_qdid *cmd_params;
798         struct dpni_rsp_get_qdid *rsp_params;
799         int err;
800
801         /* prepare command */
802         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
803                                           cmd_flags,
804                                           token);
805         cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
806         cmd_params->qtype = qtype;
807
808         /* send command to mc*/
809         err = mc_send_command(mc_io, &cmd);
810         if (err)
811                 return err;
812
813         /* retrieve response parameters */
814         rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
815         *qdid = le16_to_cpu(rsp_params->qdid);
816
817         return 0;
818 }
819
820 /**
821  * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
822  * @mc_io:      Pointer to MC portal's I/O object
823  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
824  * @token:      Token of DPNI object
825  * @data_offset: Tx data offset (from start of buffer)
826  *
827  * Return:      '0' on Success; Error code otherwise.
828  */
829 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
830                             u32 cmd_flags,
831                             u16 token,
832                             u16 *data_offset)
833 {
834         struct mc_command cmd = { 0 };
835         struct dpni_rsp_get_tx_data_offset *rsp_params;
836         int err;
837
838         /* prepare command */
839         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
840                                           cmd_flags,
841                                           token);
842
843         /* send command to mc*/
844         err = mc_send_command(mc_io, &cmd);
845         if (err)
846                 return err;
847
848         /* retrieve response parameters */
849         rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
850         *data_offset = le16_to_cpu(rsp_params->data_offset);
851
852         return 0;
853 }
854
855 /**
856  * dpni_set_link_cfg() - set the link configuration.
857  * @mc_io:      Pointer to MC portal's I/O object
858  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
859  * @token:      Token of DPNI object
860  * @cfg:        Link configuration
861  *
862  * Return:      '0' on Success; Error code otherwise.
863  */
864 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
865                       u32 cmd_flags,
866                       u16 token,
867                       const struct dpni_link_cfg *cfg)
868 {
869         struct mc_command cmd = { 0 };
870         struct dpni_cmd_set_link_cfg *cmd_params;
871
872         /* prepare command */
873         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
874                                           cmd_flags,
875                                           token);
876         cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
877         cmd_params->rate = cpu_to_le32(cfg->rate);
878         cmd_params->options = cpu_to_le64(cfg->options);
879
880         /* send command to mc*/
881         return mc_send_command(mc_io, &cmd);
882 }
883
884 /**
885  * dpni_get_link_state() - Return the link state (either up or down)
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  * @state:      Returned link state;
890  *
891  * Return:      '0' on Success; Error code otherwise.
892  */
893 int dpni_get_link_state(struct fsl_mc_io *mc_io,
894                         u32 cmd_flags,
895                         u16 token,
896                         struct dpni_link_state *state)
897 {
898         struct mc_command cmd = { 0 };
899         struct dpni_rsp_get_link_state *rsp_params;
900         int err;
901
902         /* prepare command */
903         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
904                                           cmd_flags,
905                                           token);
906
907         /* send command to mc*/
908         err = mc_send_command(mc_io, &cmd);
909         if (err)
910                 return err;
911
912         /* retrieve response parameters */
913         rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
914         state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
915         state->rate = le32_to_cpu(rsp_params->rate);
916         state->options = le64_to_cpu(rsp_params->options);
917
918         return 0;
919 }
920
921 /**
922  * dpni_set_max_frame_length() - Set the maximum received frame length.
923  * @mc_io:      Pointer to MC portal's I/O object
924  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
925  * @token:      Token of DPNI object
926  * @max_frame_length:   Maximum received frame length (in
927  *                              bytes); frame is discarded if its
928  *                              length exceeds this value
929  *
930  * Return:      '0' on Success; Error code otherwise.
931  */
932 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
933                               u32 cmd_flags,
934                               u16 token,
935                               u16 max_frame_length)
936 {
937         struct mc_command cmd = { 0 };
938         struct dpni_cmd_set_max_frame_length *cmd_params;
939
940         /* prepare command */
941         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
942                                           cmd_flags,
943                                           token);
944         cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
945         cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
946
947         /* send command to mc*/
948         return mc_send_command(mc_io, &cmd);
949 }
950
951 /**
952  * dpni_get_max_frame_length() - Get the maximum received frame length.
953  * @mc_io:      Pointer to MC portal's I/O object
954  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
955  * @token:      Token of DPNI object
956  * @max_frame_length:   Maximum received frame length (in
957  *                              bytes); frame is discarded if its
958  *                              length exceeds this value
959  *
960  * Return:      '0' on Success; Error code otherwise.
961  */
962 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
963                               u32 cmd_flags,
964                               u16 token,
965                               u16 *max_frame_length)
966 {
967         struct mc_command cmd = { 0 };
968         struct dpni_rsp_get_max_frame_length *rsp_params;
969         int err;
970
971         /* prepare command */
972         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
973                                           cmd_flags,
974                                           token);
975
976         /* send command to mc*/
977         err = mc_send_command(mc_io, &cmd);
978         if (err)
979                 return err;
980
981         /* retrieve response parameters */
982         rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
983         *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
984
985         return 0;
986 }
987
988 /**
989  * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
990  * @mc_io:      Pointer to MC portal's I/O object
991  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
992  * @token:      Token of DPNI object
993  * @en:         Set to '1' to enable; '0' to disable
994  *
995  * Return:      '0' on Success; Error code otherwise.
996  */
997 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
998                                u32 cmd_flags,
999                                u16 token,
1000                                int en)
1001 {
1002         struct mc_command cmd = { 0 };
1003         struct dpni_cmd_set_multicast_promisc *cmd_params;
1004
1005         /* prepare command */
1006         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1007                                           cmd_flags,
1008                                           token);
1009         cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1010         dpni_set_field(cmd_params->enable, ENABLE, en);
1011
1012         /* send command to mc*/
1013         return mc_send_command(mc_io, &cmd);
1014 }
1015
1016 /**
1017  * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1018  * @mc_io:      Pointer to MC portal's I/O object
1019  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1020  * @token:      Token of DPNI object
1021  * @en:         Returns '1' if enabled; '0' otherwise
1022  *
1023  * Return:      '0' on Success; Error code otherwise.
1024  */
1025 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1026                                u32 cmd_flags,
1027                                u16 token,
1028                                int *en)
1029 {
1030         struct mc_command cmd = { 0 };
1031         struct dpni_rsp_get_multicast_promisc *rsp_params;
1032         int err;
1033
1034         /* prepare command */
1035         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1036                                           cmd_flags,
1037                                           token);
1038
1039         /* send command to mc*/
1040         err = mc_send_command(mc_io, &cmd);
1041         if (err)
1042                 return err;
1043
1044         /* retrieve response parameters */
1045         rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1046         *en = dpni_get_field(rsp_params->enabled, ENABLE);
1047
1048         return 0;
1049 }
1050
1051 /**
1052  * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1053  * @mc_io:      Pointer to MC portal's I/O object
1054  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1055  * @token:      Token of DPNI object
1056  * @en:         Set to '1' to enable; '0' to disable
1057  *
1058  * Return:      '0' on Success; Error code otherwise.
1059  */
1060 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1061                              u32 cmd_flags,
1062                              u16 token,
1063                              int en)
1064 {
1065         struct mc_command cmd = { 0 };
1066         struct dpni_cmd_set_unicast_promisc *cmd_params;
1067
1068         /* prepare command */
1069         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1070                                           cmd_flags,
1071                                           token);
1072         cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1073         dpni_set_field(cmd_params->enable, ENABLE, en);
1074
1075         /* send command to mc*/
1076         return mc_send_command(mc_io, &cmd);
1077 }
1078
1079 /**
1080  * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1081  * @mc_io:      Pointer to MC portal's I/O object
1082  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1083  * @token:      Token of DPNI object
1084  * @en:         Returns '1' if enabled; '0' otherwise
1085  *
1086  * Return:      '0' on Success; Error code otherwise.
1087  */
1088 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1089                              u32 cmd_flags,
1090                              u16 token,
1091                              int *en)
1092 {
1093         struct mc_command cmd = { 0 };
1094         struct dpni_rsp_get_unicast_promisc *rsp_params;
1095         int err;
1096
1097         /* prepare command */
1098         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1099                                           cmd_flags,
1100                                           token);
1101
1102         /* send command to mc*/
1103         err = mc_send_command(mc_io, &cmd);
1104         if (err)
1105                 return err;
1106
1107         /* retrieve response parameters */
1108         rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1109         *en = dpni_get_field(rsp_params->enabled, ENABLE);
1110
1111         return 0;
1112 }
1113
1114 /**
1115  * dpni_set_primary_mac_addr() - Set the primary MAC address
1116  * @mc_io:      Pointer to MC portal's I/O object
1117  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1118  * @token:      Token of DPNI object
1119  * @mac_addr:   MAC address to set as primary address
1120  *
1121  * Return:      '0' on Success; Error code otherwise.
1122  */
1123 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1124                               u32 cmd_flags,
1125                               u16 token,
1126                               const u8 mac_addr[6])
1127 {
1128         struct mc_command cmd = { 0 };
1129         struct dpni_cmd_set_primary_mac_addr *cmd_params;
1130         int i;
1131
1132         /* prepare command */
1133         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1134                                           cmd_flags,
1135                                           token);
1136         cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1137         for (i = 0; i < 6; i++)
1138                 cmd_params->mac_addr[i] = mac_addr[5 - i];
1139
1140         /* send command to mc*/
1141         return mc_send_command(mc_io, &cmd);
1142 }
1143
1144 /**
1145  * dpni_get_primary_mac_addr() - Get the primary MAC address
1146  * @mc_io:      Pointer to MC portal's I/O object
1147  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1148  * @token:      Token of DPNI object
1149  * @mac_addr:   Returned MAC address
1150  *
1151  * Return:      '0' on Success; Error code otherwise.
1152  */
1153 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1154                               u32 cmd_flags,
1155                               u16 token,
1156                               u8 mac_addr[6])
1157 {
1158         struct mc_command cmd = { 0 };
1159         struct dpni_rsp_get_primary_mac_addr *rsp_params;
1160         int i, err;
1161
1162         /* prepare command */
1163         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1164                                           cmd_flags,
1165                                           token);
1166
1167         /* send command to mc*/
1168         err = mc_send_command(mc_io, &cmd);
1169         if (err)
1170                 return err;
1171
1172         /* retrieve response parameters */
1173         rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1174         for (i = 0; i < 6; i++)
1175                 mac_addr[5 - i] = rsp_params->mac_addr[i];
1176
1177         return 0;
1178 }
1179
1180 /**
1181  * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1182  *                      port the DPNI is attached to
1183  * @mc_io:      Pointer to MC portal's I/O object
1184  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1185  * @token:      Token of DPNI object
1186  * @mac_addr:   MAC address of the physical port, if any, otherwise 0
1187  *
1188  * The primary MAC address is not cleared by this operation.
1189  *
1190  * Return:      '0' on Success; Error code otherwise.
1191  */
1192 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1193                            u32 cmd_flags,
1194                            u16 token,
1195                            u8 mac_addr[6])
1196 {
1197         struct mc_command cmd = { 0 };
1198         struct dpni_rsp_get_port_mac_addr *rsp_params;
1199         int i, err;
1200
1201         /* prepare command */
1202         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1203                                           cmd_flags,
1204                                           token);
1205
1206         /* send command to mc*/
1207         err = mc_send_command(mc_io, &cmd);
1208         if (err)
1209                 return err;
1210
1211         /* retrieve response parameters */
1212         rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1213         for (i = 0; i < 6; i++)
1214                 mac_addr[5 - i] = rsp_params->mac_addr[i];
1215
1216         return 0;
1217 }
1218
1219 /**
1220  * dpni_add_mac_addr() - Add MAC address filter
1221  * @mc_io:      Pointer to MC portal's I/O object
1222  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1223  * @token:      Token of DPNI object
1224  * @mac_addr:   MAC address to add
1225  *
1226  * Return:      '0' on Success; Error code otherwise.
1227  */
1228 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1229                       u32 cmd_flags,
1230                       u16 token,
1231                       const u8 mac_addr[6])
1232 {
1233         struct mc_command cmd = { 0 };
1234         struct dpni_cmd_add_mac_addr *cmd_params;
1235         int i;
1236
1237         /* prepare command */
1238         cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1239                                           cmd_flags,
1240                                           token);
1241         cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1242         for (i = 0; i < 6; i++)
1243                 cmd_params->mac_addr[i] = mac_addr[5 - i];
1244
1245         /* send command to mc*/
1246         return mc_send_command(mc_io, &cmd);
1247 }
1248
1249 /**
1250  * dpni_remove_mac_addr() - Remove MAC address filter
1251  * @mc_io:      Pointer to MC portal's I/O object
1252  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1253  * @token:      Token of DPNI object
1254  * @mac_addr:   MAC address to remove
1255  *
1256  * Return:      '0' on Success; Error code otherwise.
1257  */
1258 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1259                          u32 cmd_flags,
1260                          u16 token,
1261                          const u8 mac_addr[6])
1262 {
1263         struct mc_command cmd = { 0 };
1264         struct dpni_cmd_remove_mac_addr *cmd_params;
1265         int i;
1266
1267         /* prepare command */
1268         cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1269                                           cmd_flags,
1270                                           token);
1271         cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1272         for (i = 0; i < 6; i++)
1273                 cmd_params->mac_addr[i] = mac_addr[5 - i];
1274
1275         /* send command to mc*/
1276         return mc_send_command(mc_io, &cmd);
1277 }
1278
1279 /**
1280  * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1281  * @mc_io:      Pointer to MC portal's I/O object
1282  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1283  * @token:      Token of DPNI object
1284  * @unicast:    Set to '1' to clear unicast addresses
1285  * @multicast:  Set to '1' to clear multicast addresses
1286  *
1287  * The primary MAC address is not cleared by this operation.
1288  *
1289  * Return:      '0' on Success; Error code otherwise.
1290  */
1291 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1292                            u32 cmd_flags,
1293                            u16 token,
1294                            int unicast,
1295                            int multicast)
1296 {
1297         struct mc_command cmd = { 0 };
1298         struct dpni_cmd_clear_mac_filters *cmd_params;
1299
1300         /* prepare command */
1301         cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1302                                           cmd_flags,
1303                                           token);
1304         cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1305         dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1306         dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1307
1308         /* send command to mc*/
1309         return mc_send_command(mc_io, &cmd);
1310 }
1311
1312 /**
1313  * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1314  * @mc_io:      Pointer to MC portal's I/O object
1315  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1316  * @token:      Token of DPNI object
1317  * @tc_id:      Traffic class selection (0-7)
1318  * @cfg:        Traffic class distribution configuration
1319  *
1320  * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpni_prepare_key_cfg()
1321  *                      first to prepare the key_cfg_iova parameter
1322  *
1323  * Return:      '0' on Success; error code otherwise.
1324  */
1325 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1326                         u32 cmd_flags,
1327                         u16 token,
1328                         u8 tc_id,
1329                         const struct dpni_rx_tc_dist_cfg *cfg)
1330 {
1331         struct mc_command cmd = { 0 };
1332         struct dpni_cmd_set_rx_tc_dist *cmd_params;
1333
1334         /* prepare command */
1335         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1336                                           cmd_flags,
1337                                           token);
1338         cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1339         cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1340         cmd_params->tc_id = tc_id;
1341         dpni_set_field(cmd_params->flags, DIST_MODE, cfg->dist_mode);
1342         dpni_set_field(cmd_params->flags, MISS_ACTION, cfg->fs_cfg.miss_action);
1343         cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1344         cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1345
1346         /* send command to mc*/
1347         return mc_send_command(mc_io, &cmd);
1348 }
1349
1350 /**
1351  * dpni_set_queue() - Set queue parameters
1352  * @mc_io:      Pointer to MC portal's I/O object
1353  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1354  * @token:      Token of DPNI object
1355  * @qtype:      Type of queue - all queue types are supported, although
1356  *              the command is ignored for Tx
1357  * @tc:         Traffic class, in range 0 to NUM_TCS - 1
1358  * @index:      Selects the specific queue out of the set allocated for the
1359  *              same TC. Value must be in range 0 to NUM_QUEUES - 1
1360  * @options:    A combination of DPNI_QUEUE_OPT_ values that control what
1361  *              configuration options are set on the queue
1362  * @queue:      Queue structure
1363  *
1364  * Return:      '0' on Success; Error code otherwise.
1365  */
1366 int dpni_set_queue(struct fsl_mc_io *mc_io,
1367                    u32 cmd_flags,
1368                    u16 token,
1369                    enum dpni_queue_type qtype,
1370                    u8 tc,
1371                    u8 index,
1372                    u8 options,
1373                    const struct dpni_queue *queue)
1374 {
1375         struct mc_command cmd = { 0 };
1376         struct dpni_cmd_set_queue *cmd_params;
1377
1378         /* prepare command */
1379         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1380                                           cmd_flags,
1381                                           token);
1382         cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1383         cmd_params->qtype = qtype;
1384         cmd_params->tc = tc;
1385         cmd_params->index = index;
1386         cmd_params->options = options;
1387         cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1388         cmd_params->dest_prio = queue->destination.priority;
1389         dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1390         dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1391         dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1392                        queue->destination.hold_active);
1393         cmd_params->flc = cpu_to_le64(queue->flc.value);
1394         cmd_params->user_context = cpu_to_le64(queue->user_context);
1395
1396         /* send command to mc */
1397         return mc_send_command(mc_io, &cmd);
1398 }
1399
1400 /**
1401  * dpni_get_queue() - Get queue parameters
1402  * @mc_io:      Pointer to MC portal's I/O object
1403  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1404  * @token:      Token of DPNI object
1405  * @qtype:      Type of queue - all queue types are supported
1406  * @tc:         Traffic class, in range 0 to NUM_TCS - 1
1407  * @index:      Selects the specific queue out of the set allocated for the
1408  *              same TC. Value must be in range 0 to NUM_QUEUES - 1
1409  * @queue:      Queue configuration structure
1410  * @qid:        Queue identification
1411  *
1412  * Return:      '0' on Success; Error code otherwise.
1413  */
1414 int dpni_get_queue(struct fsl_mc_io *mc_io,
1415                    u32 cmd_flags,
1416                    u16 token,
1417                    enum dpni_queue_type qtype,
1418                    u8 tc,
1419                    u8 index,
1420                    struct dpni_queue *queue,
1421                    struct dpni_queue_id *qid)
1422 {
1423         struct mc_command cmd = { 0 };
1424         struct dpni_cmd_get_queue *cmd_params;
1425         struct dpni_rsp_get_queue *rsp_params;
1426         int err;
1427
1428         /* prepare command */
1429         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1430                                           cmd_flags,
1431                                           token);
1432         cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1433         cmd_params->qtype = qtype;
1434         cmd_params->tc = tc;
1435         cmd_params->index = index;
1436
1437         /* send command to mc */
1438         err = mc_send_command(mc_io, &cmd);
1439         if (err)
1440                 return err;
1441
1442         /* retrieve response parameters */
1443         rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
1444         queue->destination.id = le32_to_cpu(rsp_params->dest_id);
1445         queue->destination.priority = rsp_params->dest_prio;
1446         queue->destination.type = dpni_get_field(rsp_params->flags,
1447                                                      DEST_TYPE);
1448         queue->flc.stash_control = dpni_get_field(rsp_params->flags,
1449                                                   STASH_CTRL);
1450         queue->destination.hold_active = dpni_get_field(rsp_params->flags,
1451                                                         HOLD_ACTIVE);
1452         queue->flc.value = le64_to_cpu(rsp_params->flc);
1453         queue->user_context = le64_to_cpu(rsp_params->user_context);
1454         qid->fqid = le32_to_cpu(rsp_params->fqid);
1455         qid->qdbin = le16_to_cpu(rsp_params->qdbin);
1456
1457         return 0;
1458 }
1459
1460 /**
1461  * dpni_get_statistics() - Get DPNI statistics
1462  * @mc_io:      Pointer to MC portal's I/O object
1463  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1464  * @token:      Token of DPNI object
1465  * @page:       Selects the statistics page to retrieve, see
1466  *              DPNI_GET_STATISTICS output. Pages are numbered 0 to 2.
1467  * @stat:       Structure containing the statistics
1468  *
1469  * Return:      '0' on Success; Error code otherwise.
1470  */
1471 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1472                         u32 cmd_flags,
1473                         u16 token,
1474                         u8 page,
1475                         union dpni_statistics *stat)
1476 {
1477         struct mc_command cmd = { 0 };
1478         struct dpni_cmd_get_statistics *cmd_params;
1479         struct dpni_rsp_get_statistics *rsp_params;
1480         int i, err;
1481
1482         /* prepare command */
1483         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
1484                                           cmd_flags,
1485                                           token);
1486         cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
1487         cmd_params->page_number = page;
1488
1489         /* send command to mc */
1490         err = mc_send_command(mc_io, &cmd);
1491         if (err)
1492                 return err;
1493
1494         /* retrieve response parameters */
1495         rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
1496         for (i = 0; i < DPNI_STATISTICS_CNT; i++)
1497                 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
1498
1499         return 0;
1500 }
1501
1502 /**
1503  * dpni_set_taildrop() - Set taildrop per queue or TC
1504  * @mc_io:      Pointer to MC portal's I/O object
1505  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1506  * @token:      Token of DPNI object
1507  * @cg_point:   Congestion point
1508  * @q_type:     Queue type on which the taildrop is configured.
1509  *              Only Rx queues are supported for now
1510  * @tc:         Traffic class to apply this taildrop to
1511  * @q_index:    Index of the queue if the DPNI supports multiple queues for
1512  *              traffic distribution. Ignored if CONGESTION_POINT is not 0.
1513  * @taildrop:   Taildrop structure
1514  *
1515  * Return:      '0' on Success; Error code otherwise.
1516  */
1517 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1518                       u32 cmd_flags,
1519                       u16 token,
1520                       enum dpni_congestion_point cg_point,
1521                       enum dpni_queue_type qtype,
1522                       u8 tc,
1523                       u8 index,
1524                       struct dpni_taildrop *taildrop)
1525 {
1526         struct mc_command cmd = { 0 };
1527         struct dpni_cmd_set_taildrop *cmd_params;
1528
1529         /* prepare command */
1530         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
1531                                           cmd_flags,
1532                                           token);
1533         cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
1534         cmd_params->congestion_point = cg_point;
1535         cmd_params->qtype = qtype;
1536         cmd_params->tc = tc;
1537         cmd_params->index = index;
1538         dpni_set_field(cmd_params->enable, ENABLE, taildrop->enable);
1539         cmd_params->units = taildrop->units;
1540         cmd_params->threshold = cpu_to_le32(taildrop->threshold);
1541
1542         /* send command to mc */
1543         return mc_send_command(mc_io, &cmd);
1544 }
1545
1546 /**
1547  * dpni_get_taildrop() - Get taildrop information
1548  * @mc_io:      Pointer to MC portal's I/O object
1549  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1550  * @token:      Token of DPNI object
1551  * @cg_point:   Congestion point
1552  * @q_type:     Queue type on which the taildrop is configured.
1553  *              Only Rx queues are supported for now
1554  * @tc:         Traffic class to apply this taildrop to
1555  * @q_index:    Index of the queue if the DPNI supports multiple queues for
1556  *              traffic distribution. Ignored if CONGESTION_POINT is not 0.
1557  * @taildrop:   Taildrop structure
1558  *
1559  * Return:      '0' on Success; Error code otherwise.
1560  */
1561 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1562                       u32 cmd_flags,
1563                       u16 token,
1564                       enum dpni_congestion_point cg_point,
1565                       enum dpni_queue_type qtype,
1566                       u8 tc,
1567                       u8 index,
1568                       struct dpni_taildrop *taildrop)
1569 {
1570         struct mc_command cmd = { 0 };
1571         struct dpni_cmd_get_taildrop *cmd_params;
1572         struct dpni_rsp_get_taildrop *rsp_params;
1573         int err;
1574
1575         /* prepare command */
1576         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
1577                                           cmd_flags,
1578                                           token);
1579         cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
1580         cmd_params->congestion_point = cg_point;
1581         cmd_params->qtype = qtype;
1582         cmd_params->tc = tc;
1583         cmd_params->index = index;
1584
1585         /* send command to mc */
1586         err = mc_send_command(mc_io, &cmd);
1587         if (err)
1588                 return err;
1589
1590         /* retrieve response parameters */
1591         rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
1592         taildrop->enable = dpni_get_field(rsp_params->enable, ENABLE);
1593         taildrop->units = rsp_params->units;
1594         taildrop->threshold = le32_to_cpu(rsp_params->threshold);
1595
1596         return 0;
1597 }