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