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