2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2013-2016 Freescale Semiconductor Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
40 #include <fsl_mc_sys.h>
41 #include <fsl_mc_cmd.h>
43 #include <fsl_dpni_cmd.h>
46 * dpni_open() - Open a control session for the specified object
47 * @mc_io: Pointer to MC portal's I/O object
48 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
49 * @dpni_id: DPNI unique ID
50 * @token: Returned token; use in subsequent API calls
52 * This function can be used to open a control session for an
53 * already created object; an object may have been declared in
54 * the DPL or by calling the dpni_create() function.
55 * This function returns a unique authentication token,
56 * associated with the specific object ID and the specific MC
57 * portal; this token must be used in all subsequent commands for
58 * this specific object.
60 * Return: '0' on Success; Error code otherwise.
62 int dpni_open(struct fsl_mc_io *mc_io,
67 struct mc_command cmd = { 0 };
68 struct dpni_cmd_open *cmd_params;
73 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
76 cmd_params = (struct dpni_cmd_open *)cmd.params;
77 cmd_params->dpni_id = cpu_to_le32(dpni_id);
79 /* send command to mc*/
80 err = mc_send_command(mc_io, &cmd);
84 /* retrieve response parameters */
85 *token = mc_cmd_hdr_read_token(&cmd);
91 * dpni_close() - Close the control session of the object
92 * @mc_io: Pointer to MC portal's I/O object
93 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
94 * @token: Token of DPNI object
96 * After this function is called, no further operations are
97 * allowed on the object without opening a new control session.
99 * Return: '0' on Success; Error code otherwise.
101 int dpni_close(struct fsl_mc_io *mc_io,
105 struct mc_command cmd = { 0 };
107 /* prepare command */
108 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
112 /* send command to mc*/
113 return mc_send_command(mc_io, &cmd);
117 * dpni_create() - Create the DPNI object
118 * @mc_io: Pointer to MC portal's I/O object
119 * @dprc_token: Parent container token; '0' for default container
120 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
121 * @cfg: Configuration structure
122 * @obj_id: Returned object id
124 * Create the DPNI object, allocate required resources and
125 * perform required initialization.
127 * The object can be created either by declaring it in the
128 * DPL file, or by calling this function.
130 * The function accepts an authentication token of a parent
131 * container that this object should be assigned to. The token
132 * can be '0' so the object will be assigned to the default container.
133 * The newly created object can be opened with the returned
134 * object id and using the container's associated tokens and MC portals.
136 * Return: '0' on Success; Error code otherwise.
138 int dpni_create(struct fsl_mc_io *mc_io,
141 const struct dpni_cfg *cfg,
144 struct dpni_cmd_create *cmd_params;
145 struct mc_command cmd = { 0 };
148 /* prepare command */
149 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
152 cmd_params = (struct dpni_cmd_create *)cmd.params;
153 cmd_params->options = cpu_to_le32(cfg->options);
154 cmd_params->num_queues = cfg->num_queues;
155 cmd_params->num_tcs = cfg->num_tcs;
156 cmd_params->mac_filter_entries = cfg->mac_filter_entries;
157 cmd_params->vlan_filter_entries = cfg->vlan_filter_entries;
158 cmd_params->qos_entries = cfg->qos_entries;
159 cmd_params->fs_entries = cpu_to_le16(cfg->fs_entries);
161 /* send command to mc*/
162 err = mc_send_command(mc_io, &cmd);
166 /* retrieve response parameters */
167 *obj_id = mc_cmd_read_object_id(&cmd);
173 * dpni_destroy() - Destroy the DPNI object and release all its resources.
174 * @mc_io: Pointer to MC portal's I/O object
175 * @dprc_token: Parent container token; '0' for default container
176 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
177 * @object_id: The object id; it must be a valid id within the container that
178 * created this object;
180 * The function accepts the authentication token of the parent container that
181 * created the object (not the one that currently owns the object). The object
182 * is searched within parent using the provided 'object_id'.
183 * All tokens to the object must be closed before calling destroy.
185 * Return: '0' on Success; error code otherwise.
187 int dpni_destroy(struct fsl_mc_io *mc_io,
192 struct dpni_cmd_destroy *cmd_params;
193 struct mc_command cmd = { 0 };
195 /* prepare command */
196 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
199 /* set object id to destroy */
200 cmd_params = (struct dpni_cmd_destroy *)cmd.params;
201 cmd_params->dpsw_id = cpu_to_le32(object_id);
203 /* send command to mc*/
204 return mc_send_command(mc_io, &cmd);
208 * dpni_set_pools() - Set buffer pools configuration
209 * @mc_io: Pointer to MC portal's I/O object
210 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
211 * @token: Token of DPNI object
212 * @cfg: Buffer pools configuration
214 * mandatory for DPNI operation
215 * warning:Allowed only when DPNI is disabled
217 * Return: '0' on Success; Error code otherwise.
219 int dpni_set_pools(struct fsl_mc_io *mc_io,
222 const struct dpni_pools_cfg *cfg)
224 struct mc_command cmd = { 0 };
225 struct dpni_cmd_set_pools *cmd_params;
228 /* prepare command */
229 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
232 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
233 cmd_params->num_dpbp = cfg->num_dpbp;
234 for (i = 0; i < cmd_params->num_dpbp; i++) {
235 cmd_params->pool[i].dpbp_id =
236 cpu_to_le16(cfg->pools[i].dpbp_id);
237 cmd_params->pool[i].priority_mask =
238 cfg->pools[i].priority_mask;
239 cmd_params->buffer_size[i] =
240 cpu_to_le16(cfg->pools[i].buffer_size);
241 cmd_params->backup_pool_mask |=
242 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
245 /* send command to mc*/
246 return mc_send_command(mc_io, &cmd);
250 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
251 * @mc_io: Pointer to MC portal's I/O object
252 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
253 * @token: Token of DPNI object
255 * Return: '0' on Success; Error code otherwise.
257 int dpni_enable(struct fsl_mc_io *mc_io,
261 struct mc_command cmd = { 0 };
263 /* prepare command */
264 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
268 /* send command to mc*/
269 return mc_send_command(mc_io, &cmd);
273 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
274 * @mc_io: Pointer to MC portal's I/O object
275 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
276 * @token: Token of DPNI object
278 * Return: '0' on Success; Error code otherwise.
280 int dpni_disable(struct fsl_mc_io *mc_io,
284 struct mc_command cmd = { 0 };
286 /* prepare command */
287 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
291 /* send command to mc*/
292 return mc_send_command(mc_io, &cmd);
296 * dpni_is_enabled() - Check if the DPNI is enabled.
297 * @mc_io: Pointer to MC portal's I/O object
298 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
299 * @token: Token of DPNI object
300 * @en: Returns '1' if object is enabled; '0' otherwise
302 * Return: '0' on Success; Error code otherwise.
304 int dpni_is_enabled(struct fsl_mc_io *mc_io,
309 struct mc_command cmd = { 0 };
310 struct dpni_rsp_is_enabled *rsp_params;
313 /* prepare command */
314 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
318 /* send command to mc*/
319 err = mc_send_command(mc_io, &cmd);
323 /* retrieve response parameters */
324 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
325 *en = dpni_get_field(rsp_params->enabled, ENABLE);
331 * dpni_reset() - Reset the DPNI, returns the object to initial state.
332 * @mc_io: Pointer to MC portal's I/O object
333 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
334 * @token: Token of DPNI object
336 * Return: '0' on Success; Error code otherwise.
338 int dpni_reset(struct fsl_mc_io *mc_io,
342 struct mc_command cmd = { 0 };
344 /* prepare command */
345 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
349 /* send command to mc*/
350 return mc_send_command(mc_io, &cmd);
354 * dpni_set_irq_enable() - Set overall interrupt state.
355 * @mc_io: Pointer to MC portal's I/O object
356 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
357 * @token: Token of DPNI object
358 * @irq_index: The interrupt index to configure
359 * @en: Interrupt state: - enable = 1, disable = 0
361 * Allows GPP software to control when interrupts are generated.
362 * Each interrupt can have up to 32 causes. The enable/disable control's the
363 * overall interrupt state. if the interrupt is disabled no causes will cause
366 * Return: '0' on Success; Error code otherwise.
368 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
374 struct mc_command cmd = { 0 };
375 struct dpni_cmd_set_irq_enable *cmd_params;
377 /* prepare command */
378 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
381 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
382 dpni_set_field(cmd_params->enable, ENABLE, en);
383 cmd_params->irq_index = irq_index;
385 /* send command to mc*/
386 return mc_send_command(mc_io, &cmd);
390 * dpni_get_irq_enable() - Get overall interrupt state
391 * @mc_io: Pointer to MC portal's I/O object
392 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
393 * @token: Token of DPNI object
394 * @irq_index: The interrupt index to configure
395 * @en: Returned interrupt state - enable = 1, disable = 0
397 * Return: '0' on Success; Error code otherwise.
399 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
405 struct mc_command cmd = { 0 };
406 struct dpni_cmd_get_irq_enable *cmd_params;
407 struct dpni_rsp_get_irq_enable *rsp_params;
411 /* prepare command */
412 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
415 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
416 cmd_params->irq_index = irq_index;
418 /* send command to mc*/
419 err = mc_send_command(mc_io, &cmd);
423 /* retrieve response parameters */
424 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
425 *en = dpni_get_field(rsp_params->enabled, ENABLE);
431 * dpni_set_irq_mask() - Set 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: Event mask to trigger interrupt;
439 * 1 = consider event for asserting IRQ
441 * Every interrupt can have up to 32 causes and the interrupt model supports
442 * masking/unmasking each cause independently
444 * Return: '0' on Success; Error code otherwise.
446 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
452 struct mc_command cmd = { 0 };
453 struct dpni_cmd_set_irq_mask *cmd_params;
455 /* prepare command */
456 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
459 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
460 cmd_params->mask = cpu_to_le32(mask);
461 cmd_params->irq_index = irq_index;
463 /* send command to mc*/
464 return mc_send_command(mc_io, &cmd);
468 * dpni_get_irq_mask() - Get interrupt mask.
469 * @mc_io: Pointer to MC portal's I/O object
470 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
471 * @token: Token of DPNI object
472 * @irq_index: The interrupt index to configure
473 * @mask: Returned event mask to trigger interrupt
475 * Every interrupt can have up to 32 causes and the interrupt model supports
476 * masking/unmasking each cause independently
478 * Return: '0' on Success; Error code otherwise.
480 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
486 struct mc_command cmd = { 0 };
487 struct dpni_cmd_get_irq_mask *cmd_params;
488 struct dpni_rsp_get_irq_mask *rsp_params;
491 /* prepare command */
492 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
495 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
496 cmd_params->irq_index = irq_index;
498 /* send command to mc*/
499 err = mc_send_command(mc_io, &cmd);
503 /* retrieve response parameters */
504 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
505 *mask = le32_to_cpu(rsp_params->mask);
511 * dpni_get_irq_status() - Get the current status of any pending interrupts.
512 * @mc_io: Pointer to MC portal's I/O object
513 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
514 * @token: Token of DPNI object
515 * @irq_index: The interrupt index to configure
516 * @status: Returned interrupts status - one bit per cause:
517 * 0 = no interrupt pending
518 * 1 = interrupt pending
520 * Return: '0' on Success; Error code otherwise.
522 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
528 struct mc_command cmd = { 0 };
529 struct dpni_cmd_get_irq_status *cmd_params;
530 struct dpni_rsp_get_irq_status *rsp_params;
533 /* prepare command */
534 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
537 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
538 cmd_params->status = cpu_to_le32(*status);
539 cmd_params->irq_index = irq_index;
541 /* send command to mc*/
542 err = mc_send_command(mc_io, &cmd);
546 /* retrieve response parameters */
547 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
548 *status = le32_to_cpu(rsp_params->status);
554 * dpni_clear_irq_status() - Clear a pending interrupt's status
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 * @irq_index: The interrupt index to configure
559 * @status: bits to clear (W1C) - one bit per cause:
561 * 1 = clear status bit
563 * Return: '0' on Success; Error code otherwise.
565 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
571 struct mc_command cmd = { 0 };
572 struct dpni_cmd_clear_irq_status *cmd_params;
574 /* prepare command */
575 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
578 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
579 cmd_params->irq_index = irq_index;
580 cmd_params->status = cpu_to_le32(status);
582 /* send command to mc*/
583 return mc_send_command(mc_io, &cmd);
587 * dpni_get_attributes() - Retrieve DPNI attributes.
588 * @mc_io: Pointer to MC portal's I/O object
589 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
590 * @token: Token of DPNI object
591 * @attr: Object's attributes
593 * Return: '0' on Success; Error code otherwise.
595 int dpni_get_attributes(struct fsl_mc_io *mc_io,
598 struct dpni_attr *attr)
600 struct mc_command cmd = { 0 };
601 struct dpni_rsp_get_attr *rsp_params;
605 /* prepare command */
606 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
610 /* send command to mc*/
611 err = mc_send_command(mc_io, &cmd);
615 /* retrieve response parameters */
616 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
617 attr->options = le32_to_cpu(rsp_params->options);
618 attr->num_queues = rsp_params->num_queues;
619 attr->num_rx_tcs = rsp_params->num_rx_tcs;
620 attr->num_tx_tcs = rsp_params->num_tx_tcs;
621 attr->mac_filter_entries = rsp_params->mac_filter_entries;
622 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
623 attr->qos_entries = rsp_params->qos_entries;
624 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
625 attr->qos_key_size = rsp_params->qos_key_size;
626 attr->fs_key_size = rsp_params->fs_key_size;
627 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
633 * dpni_set_errors_behavior() - Set errors behavior
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 * @cfg: Errors configuration
639 * This function may be called numerous times with different
642 * Return: '0' on Success; Error code otherwise.
644 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
647 struct dpni_error_cfg *cfg)
649 struct mc_command cmd = { 0 };
650 struct dpni_cmd_set_errors_behavior *cmd_params;
652 /* prepare command */
653 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
656 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
657 cmd_params->errors = cpu_to_le32(cfg->errors);
658 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
659 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
661 /* send command to mc*/
662 return mc_send_command(mc_io, &cmd);
666 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
667 * @mc_io: Pointer to MC portal's I/O object
668 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
669 * @token: Token of DPNI object
670 * @qtype: Type of queue to retrieve configuration for
671 * @layout: Returns buffer layout attributes
673 * Return: '0' on Success; Error code otherwise.
675 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
678 enum dpni_queue_type qtype,
679 struct dpni_buffer_layout *layout)
681 struct mc_command cmd = { 0 };
682 struct dpni_cmd_get_buffer_layout *cmd_params;
683 struct dpni_rsp_get_buffer_layout *rsp_params;
686 /* prepare command */
687 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
690 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
691 cmd_params->qtype = qtype;
693 /* send command to mc*/
694 err = mc_send_command(mc_io, &cmd);
698 /* retrieve response parameters */
699 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
700 layout->pass_timestamp = dpni_get_field(rsp_params->flags, PASS_TS);
701 layout->pass_parser_result = dpni_get_field(rsp_params->flags, PASS_PR);
702 layout->pass_frame_status = dpni_get_field(rsp_params->flags, PASS_FS);
703 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
704 layout->data_align = le16_to_cpu(rsp_params->data_align);
705 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
706 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
712 * dpni_set_buffer_layout() - Set buffer layout configuration.
713 * @mc_io: Pointer to MC portal's I/O object
714 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
715 * @token: Token of DPNI object
716 * @qtype: Type of queue this configuration applies to
717 * @layout: Buffer layout configuration
719 * Return: '0' on Success; Error code otherwise.
721 * @warning Allowed only when DPNI is disabled
723 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
726 enum dpni_queue_type qtype,
727 const struct dpni_buffer_layout *layout)
729 struct mc_command cmd = { 0 };
730 struct dpni_cmd_set_buffer_layout *cmd_params;
732 /* prepare command */
733 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
736 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
737 cmd_params->qtype = qtype;
738 cmd_params->options = cpu_to_le16(layout->options);
739 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
740 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
741 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
742 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
743 cmd_params->data_align = cpu_to_le16(layout->data_align);
744 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
745 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
747 /* send command to mc*/
748 return mc_send_command(mc_io, &cmd);
752 * dpni_set_offload() - Set 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, non-zero value enables the offload
760 * Return: '0' on Success; Error code otherwise.
762 * @warning Allowed only when DPNI is disabled
765 int dpni_set_offload(struct fsl_mc_io *mc_io,
768 enum dpni_offload type,
771 struct mc_command cmd = { 0 };
772 struct dpni_cmd_set_offload *cmd_params;
774 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
777 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
778 cmd_params->dpni_offload = type;
779 cmd_params->config = cpu_to_le32(config);
781 return mc_send_command(mc_io, &cmd);
785 * dpni_get_offload() - Get DPNI offload configuration.
786 * @mc_io: Pointer to MC portal's I/O object
787 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
788 * @token: Token of DPNI object
789 * @type: Type of DPNI offload
790 * @config: Offload configuration.
791 * For checksum offloads, a value of 1 indicates that the
792 * offload is enabled.
794 * Return: '0' on Success; Error code otherwise.
796 * @warning Allowed only when DPNI is disabled
798 int dpni_get_offload(struct fsl_mc_io *mc_io,
801 enum dpni_offload type,
804 struct mc_command cmd = { 0 };
805 struct dpni_cmd_get_offload *cmd_params;
806 struct dpni_rsp_get_offload *rsp_params;
809 /* prepare command */
810 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
813 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
814 cmd_params->dpni_offload = type;
816 /* send command to mc*/
817 err = mc_send_command(mc_io, &cmd);
821 /* retrieve response parameters */
822 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
823 *config = le32_to_cpu(rsp_params->config);
829 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
830 * for enqueue operations
831 * @mc_io: Pointer to MC portal's I/O object
832 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
833 * @token: Token of DPNI object
834 * @qtype: Type of queue to receive QDID for
835 * @qdid: Returned virtual QDID value that should be used as an argument
836 * in all enqueue operations
838 * Return: '0' on Success; Error code otherwise.
840 int dpni_get_qdid(struct fsl_mc_io *mc_io,
843 enum dpni_queue_type qtype,
846 struct mc_command cmd = { 0 };
847 struct dpni_cmd_get_qdid *cmd_params;
848 struct dpni_rsp_get_qdid *rsp_params;
851 /* prepare command */
852 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
855 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
856 cmd_params->qtype = qtype;
858 /* send command to mc*/
859 err = mc_send_command(mc_io, &cmd);
863 /* retrieve response parameters */
864 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
865 *qdid = le16_to_cpu(rsp_params->qdid);
871 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
872 * @mc_io: Pointer to MC portal's I/O object
873 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
874 * @token: Token of DPNI object
875 * @data_offset: Tx data offset (from start of buffer)
877 * Return: '0' on Success; Error code otherwise.
879 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
882 uint16_t *data_offset)
884 struct mc_command cmd = { 0 };
885 struct dpni_rsp_get_tx_data_offset *rsp_params;
888 /* prepare command */
889 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
893 /* send command to mc*/
894 err = mc_send_command(mc_io, &cmd);
898 /* retrieve response parameters */
899 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
900 *data_offset = le16_to_cpu(rsp_params->data_offset);
906 * dpni_set_link_cfg() - set the link configuration.
907 * @mc_io: Pointer to MC portal's I/O object
908 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
909 * @token: Token of DPNI object
910 * @cfg: Link configuration
912 * Return: '0' on Success; Error code otherwise.
914 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
917 const struct dpni_link_cfg *cfg)
919 struct mc_command cmd = { 0 };
920 struct dpni_cmd_set_link_cfg *cmd_params;
922 /* prepare command */
923 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
926 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
927 cmd_params->rate = cpu_to_le32(cfg->rate);
928 cmd_params->options = cpu_to_le64(cfg->options);
930 /* send command to mc*/
931 return mc_send_command(mc_io, &cmd);
935 * dpni_get_link_state() - Return the link state (either up or down)
936 * @mc_io: Pointer to MC portal's I/O object
937 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
938 * @token: Token of DPNI object
939 * @state: Returned link state;
941 * Return: '0' on Success; Error code otherwise.
943 int dpni_get_link_state(struct fsl_mc_io *mc_io,
946 struct dpni_link_state *state)
948 struct mc_command cmd = { 0 };
949 struct dpni_rsp_get_link_state *rsp_params;
952 /* prepare command */
953 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
957 /* send command to mc*/
958 err = mc_send_command(mc_io, &cmd);
962 /* retrieve response parameters */
963 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
964 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
965 state->rate = le32_to_cpu(rsp_params->rate);
966 state->options = le64_to_cpu(rsp_params->options);
972 * dpni_set_max_frame_length() - Set the maximum received frame length.
973 * @mc_io: Pointer to MC portal's I/O object
974 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
975 * @token: Token of DPNI object
976 * @max_frame_length: Maximum received frame length (in bytes);
977 * frame is discarded if its length exceeds this value
979 * Return: '0' on Success; Error code otherwise.
981 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
984 uint16_t max_frame_length)
986 struct mc_command cmd = { 0 };
987 struct dpni_cmd_set_max_frame_length *cmd_params;
989 /* prepare command */
990 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
993 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
994 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
996 /* send command to mc*/
997 return mc_send_command(mc_io, &cmd);
1001 * dpni_get_max_frame_length() - Get the maximum received frame length.
1002 * @mc_io: Pointer to MC portal's I/O object
1003 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1004 * @token: Token of DPNI object
1005 * @max_frame_length: Maximum received frame length (in bytes);
1006 * frame is discarded if its length exceeds this value
1008 * Return: '0' on Success; Error code otherwise.
1010 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
1013 uint16_t *max_frame_length)
1015 struct mc_command cmd = { 0 };
1016 struct dpni_rsp_get_max_frame_length *rsp_params;
1019 /* prepare command */
1020 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1024 /* send command to mc*/
1025 err = mc_send_command(mc_io, &cmd);
1029 /* retrieve response parameters */
1030 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1031 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1037 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1038 * @mc_io: Pointer to MC portal's I/O object
1039 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1040 * @token: Token of DPNI object
1041 * @en: Set to '1' to enable; '0' to disable
1043 * Return: '0' on Success; Error code otherwise.
1045 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1050 struct mc_command cmd = { 0 };
1051 struct dpni_cmd_set_multicast_promisc *cmd_params;
1053 /* prepare command */
1054 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1057 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1058 dpni_set_field(cmd_params->enable, ENABLE, en);
1060 /* send command to mc*/
1061 return mc_send_command(mc_io, &cmd);
1065 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1066 * @mc_io: Pointer to MC portal's I/O object
1067 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1068 * @token: Token of DPNI object
1069 * @en: Returns '1' if enabled; '0' otherwise
1071 * Return: '0' on Success; Error code otherwise.
1073 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1078 struct mc_command cmd = { 0 };
1079 struct dpni_rsp_get_multicast_promisc *rsp_params;
1082 /* prepare command */
1083 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1087 /* send command to mc*/
1088 err = mc_send_command(mc_io, &cmd);
1092 /* retrieve response parameters */
1093 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1094 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1100 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1101 * @mc_io: Pointer to MC portal's I/O object
1102 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1103 * @token: Token of DPNI object
1104 * @en: Set to '1' to enable; '0' to disable
1106 * Return: '0' on Success; Error code otherwise.
1108 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1113 struct mc_command cmd = { 0 };
1114 struct dpni_cmd_set_unicast_promisc *cmd_params;
1116 /* prepare command */
1117 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1120 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1121 dpni_set_field(cmd_params->enable, ENABLE, en);
1123 /* send command to mc*/
1124 return mc_send_command(mc_io, &cmd);
1128 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1129 * @mc_io: Pointer to MC portal's I/O object
1130 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1131 * @token: Token of DPNI object
1132 * @en: Returns '1' if enabled; '0' otherwise
1134 * Return: '0' on Success; Error code otherwise.
1136 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1141 struct mc_command cmd = { 0 };
1142 struct dpni_rsp_get_unicast_promisc *rsp_params;
1145 /* prepare command */
1146 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1150 /* send command to mc*/
1151 err = mc_send_command(mc_io, &cmd);
1155 /* retrieve response parameters */
1156 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1157 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1163 * dpni_set_primary_mac_addr() - Set the primary MAC address
1164 * @mc_io: Pointer to MC portal's I/O object
1165 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1166 * @token: Token of DPNI object
1167 * @mac_addr: MAC address to set as primary address
1169 * Return: '0' on Success; Error code otherwise.
1171 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1174 const uint8_t mac_addr[6])
1176 struct mc_command cmd = { 0 };
1177 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1180 /* prepare command */
1181 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1184 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1185 for (i = 0; i < 6; i++)
1186 cmd_params->mac_addr[i] = mac_addr[5 - i];
1188 /* send command to mc*/
1189 return mc_send_command(mc_io, &cmd);
1193 * dpni_get_primary_mac_addr() - Get the primary MAC address
1194 * @mc_io: Pointer to MC portal's I/O object
1195 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1196 * @token: Token of DPNI object
1197 * @mac_addr: Returned MAC address
1199 * Return: '0' on Success; Error code otherwise.
1201 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1204 uint8_t mac_addr[6])
1206 struct mc_command cmd = { 0 };
1207 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1210 /* prepare command */
1211 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1215 /* send command to mc*/
1216 err = mc_send_command(mc_io, &cmd);
1220 /* retrieve response parameters */
1221 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1222 for (i = 0; i < 6; i++)
1223 mac_addr[5 - i] = rsp_params->mac_addr[i];
1229 * dpni_add_mac_addr() - Add MAC address filter
1230 * @mc_io: Pointer to MC portal's I/O object
1231 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1232 * @token: Token of DPNI object
1233 * @mac_addr: MAC address to add
1235 * Return: '0' on Success; Error code otherwise.
1237 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1240 const uint8_t mac_addr[6])
1242 struct mc_command cmd = { 0 };
1243 struct dpni_cmd_add_mac_addr *cmd_params;
1246 /* prepare command */
1247 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1250 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1251 for (i = 0; i < 6; i++)
1252 cmd_params->mac_addr[i] = mac_addr[5 - i];
1254 /* send command to mc*/
1255 return mc_send_command(mc_io, &cmd);
1259 * dpni_remove_mac_addr() - Remove MAC address filter
1260 * @mc_io: Pointer to MC portal's I/O object
1261 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1262 * @token: Token of DPNI object
1263 * @mac_addr: MAC address to remove
1265 * Return: '0' on Success; Error code otherwise.
1267 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1270 const uint8_t mac_addr[6])
1272 struct mc_command cmd = { 0 };
1273 struct dpni_cmd_remove_mac_addr *cmd_params;
1276 /* prepare command */
1277 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1280 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1281 for (i = 0; i < 6; i++)
1282 cmd_params->mac_addr[i] = mac_addr[5 - i];
1284 /* send command to mc*/
1285 return mc_send_command(mc_io, &cmd);
1289 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1290 * @mc_io: Pointer to MC portal's I/O object
1291 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1292 * @token: Token of DPNI object
1293 * @unicast: Set to '1' to clear unicast addresses
1294 * @multicast: Set to '1' to clear multicast addresses
1296 * The primary MAC address is not cleared by this operation.
1298 * Return: '0' on Success; Error code otherwise.
1300 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1306 struct mc_command cmd = { 0 };
1307 struct dpni_cmd_clear_mac_filters *cmd_params;
1309 /* prepare command */
1310 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1313 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1314 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1315 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1317 /* send command to mc*/
1318 return mc_send_command(mc_io, &cmd);
1322 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1323 * port the DPNI is attached to
1324 * @mc_io: Pointer to MC portal's I/O object
1325 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1326 * @token: Token of DPNI object
1327 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1329 * The primary MAC address is not cleared by this operation.
1331 * Return: '0' on Success; Error code otherwise.
1333 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1336 uint8_t mac_addr[6])
1338 struct mc_command cmd = { 0 };
1339 struct dpni_rsp_get_port_mac_addr *rsp_params;
1342 /* prepare command */
1343 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1347 /* send command to mc*/
1348 err = mc_send_command(mc_io, &cmd);
1352 /* retrieve response parameters */
1353 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1354 for (i = 0; i < 6; i++)
1355 mac_addr[5 - i] = rsp_params->mac_addr[i];
1361 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1362 * @mc_io: Pointer to MC portal's I/O object
1363 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1364 * @token: Token of DPNI object
1365 * @en: Set to '1' to enable; '0' to disable
1367 * Return: '0' on Success; Error code otherwise.
1369 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1374 struct dpni_cmd_enable_vlan_filter *cmd_params;
1375 struct mc_command cmd = { 0 };
1377 /* prepare command */
1378 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1381 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1382 dpni_set_field(cmd_params->en, ENABLE, en);
1384 /* send command to mc*/
1385 return mc_send_command(mc_io, &cmd);
1389 * dpni_add_vlan_id() - Add VLAN ID filter
1390 * @mc_io: Pointer to MC portal's I/O object
1391 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1392 * @token: Token of DPNI object
1393 * @vlan_id: VLAN ID to add
1395 * Return: '0' on Success; Error code otherwise.
1397 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1402 struct dpni_cmd_vlan_id *cmd_params;
1403 struct mc_command cmd = { 0 };
1405 /* prepare command */
1406 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1409 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1410 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1412 /* send command to mc*/
1413 return mc_send_command(mc_io, &cmd);
1417 * dpni_remove_vlan_id() - Remove VLAN ID filter
1418 * @mc_io: Pointer to MC portal's I/O object
1419 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1420 * @token: Token of DPNI object
1421 * @vlan_id: VLAN ID to remove
1423 * Return: '0' on Success; Error code otherwise.
1425 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1430 struct dpni_cmd_vlan_id *cmd_params;
1431 struct mc_command cmd = { 0 };
1433 /* prepare command */
1434 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1437 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1438 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1440 /* send command to mc*/
1441 return mc_send_command(mc_io, &cmd);
1445 * dpni_clear_vlan_filters() - Clear all VLAN filters
1446 * @mc_io: Pointer to MC portal's I/O object
1447 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1448 * @token: Token of DPNI object
1450 * Return: '0' on Success; Error code otherwise.
1452 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1456 struct mc_command cmd = { 0 };
1458 /* prepare command */
1459 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1463 /* send command to mc*/
1464 return mc_send_command(mc_io, &cmd);
1468 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1469 * @mc_io: Pointer to MC portal's I/O object
1470 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1471 * @token: Token of DPNI object
1472 * @tc_id: Traffic class selection (0-7)
1473 * @cfg: Traffic class distribution configuration
1475 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1476 * first to prepare the key_cfg_iova parameter
1478 * Return: '0' on Success; error code otherwise.
1480 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1484 const struct dpni_rx_tc_dist_cfg *cfg)
1486 struct mc_command cmd = { 0 };
1487 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1489 /* prepare command */
1490 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1493 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1494 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1495 cmd_params->tc_id = tc_id;
1496 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1497 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1498 dpni_set_field(cmd_params->flags,
1501 dpni_set_field(cmd_params->flags,
1503 cfg->fs_cfg.miss_action);
1504 dpni_set_field(cmd_params->keep_hash_key,
1506 cfg->fs_cfg.keep_hash_key);
1508 /* send command to mc*/
1509 return mc_send_command(mc_io, &cmd);
1513 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1514 * @mc_io: Pointer to MC portal's I/O object
1515 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1516 * @token: Token of DPNI object
1517 * @mode: Tx confirmation mode
1519 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1520 * selected at DPNI creation.
1521 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1522 * transmit confirmation (including the private confirmation queues), regardless
1523 * of previous settings; Note that in this case, Tx error frames are still
1524 * enqueued to the general transmit errors queue.
1525 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1526 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1527 * command will be ignored.
1529 * Return: '0' on Success; Error code otherwise.
1531 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1534 enum dpni_confirmation_mode mode)
1536 struct dpni_tx_confirmation_mode *cmd_params;
1537 struct mc_command cmd = { 0 };
1539 /* prepare command */
1540 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1543 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1544 cmd_params->confirmation_mode = mode;
1546 /* send command to mc*/
1547 return mc_send_command(mc_io, &cmd);
1551 * dpni_set_congestion_notification() - Set traffic class congestion
1552 * notification configuration
1553 * @mc_io: Pointer to MC portal's I/O object
1554 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1555 * @token: Token of DPNI object
1556 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1557 * @tc_id: Traffic class selection (0-7)
1558 * @cfg: congestion notification configuration
1560 * Return: '0' on Success; error code otherwise.
1562 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1565 enum dpni_queue_type qtype,
1567 const struct dpni_congestion_notification_cfg *cfg)
1569 struct dpni_cmd_set_congestion_notification *cmd_params;
1570 struct mc_command cmd = { 0 };
1572 /* prepare command */
1573 cmd.header = mc_encode_cmd_header(
1574 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1577 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1578 cmd_params->qtype = qtype;
1579 cmd_params->tc = tc_id;
1580 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1581 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1582 cmd_params->dest_priority = cfg->dest_cfg.priority;
1583 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1584 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1585 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1586 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1587 dpni_set_field(cmd_params->type_units,
1589 cfg->dest_cfg.dest_type);
1590 dpni_set_field(cmd_params->type_units,
1594 /* send command to mc*/
1595 return mc_send_command(mc_io, &cmd);
1599 * dpni_get_congestion_notification() - Get traffic class congestion
1600 * notification configuration
1601 * @mc_io: Pointer to MC portal's I/O object
1602 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1603 * @token: Token of DPNI object
1604 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1605 * @tc_id: Traffic class selection (0-7)
1606 * @cfg: congestion notification configuration
1608 * Return: '0' on Success; error code otherwise.
1610 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1613 enum dpni_queue_type qtype,
1615 struct dpni_congestion_notification_cfg *cfg)
1617 struct dpni_rsp_get_congestion_notification *rsp_params;
1618 struct dpni_cmd_get_congestion_notification *cmd_params;
1619 struct mc_command cmd = { 0 };
1622 /* prepare command */
1623 cmd.header = mc_encode_cmd_header(
1624 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
1627 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
1628 cmd_params->qtype = qtype;
1629 cmd_params->tc = tc_id;
1631 /* send command to mc*/
1632 err = mc_send_command(mc_io, &cmd);
1636 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
1637 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
1638 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
1639 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
1640 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
1641 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
1642 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
1643 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
1644 cfg->dest_cfg.priority = rsp_params->dest_priority;
1645 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
1652 * dpni_get_api_version() - Get Data Path Network Interface API version
1653 * @mc_io: Pointer to MC portal's I/O object
1654 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1655 * @major_ver: Major version of data path network interface API
1656 * @minor_ver: Minor version of data path network interface API
1658 * Return: '0' on Success; Error code otherwise.
1660 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1662 uint16_t *major_ver,
1663 uint16_t *minor_ver)
1665 struct dpni_rsp_get_api_version *rsp_params;
1666 struct mc_command cmd = { 0 };
1669 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1673 err = mc_send_command(mc_io, &cmd);
1677 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1678 *major_ver = le16_to_cpu(rsp_params->major);
1679 *minor_ver = le16_to_cpu(rsp_params->minor);
1685 * dpni_set_queue() - Set queue parameters
1686 * @mc_io: Pointer to MC portal's I/O object
1687 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1688 * @token: Token of DPNI object
1689 * @qtype: Type of queue - all queue types are supported, although
1690 * the command is ignored for Tx
1691 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1692 * @index: Selects the specific queue out of the set allocated for the
1693 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1694 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
1695 * configuration options are set on the queue
1696 * @queue: Queue structure
1698 * Return: '0' on Success; Error code otherwise.
1700 int dpni_set_queue(struct fsl_mc_io *mc_io,
1703 enum dpni_queue_type qtype,
1707 const struct dpni_queue *queue)
1709 struct mc_command cmd = { 0 };
1710 struct dpni_cmd_set_queue *cmd_params;
1712 /* prepare command */
1713 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1716 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1717 cmd_params->qtype = qtype;
1718 cmd_params->tc = tc;
1719 cmd_params->index = index;
1720 cmd_params->options = options;
1721 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1722 cmd_params->dest_prio = queue->destination.priority;
1723 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1724 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1725 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1726 queue->destination.hold_active);
1727 cmd_params->flc = cpu_to_le64(queue->flc.value);
1728 cmd_params->user_context = cpu_to_le64(queue->user_context);
1730 /* send command to mc */
1731 return mc_send_command(mc_io, &cmd);
1735 * dpni_get_queue() - Get queue parameters
1736 * @mc_io: Pointer to MC portal's I/O object
1737 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1738 * @token: Token of DPNI object
1739 * @qtype: Type of queue - all queue types are supported
1740 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1741 * @index: Selects the specific queue out of the set allocated for the
1742 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1743 * @queue: Queue configuration structure
1744 * @qid: Queue identification
1746 * Return: '0' on Success; Error code otherwise.
1748 int dpni_get_queue(struct fsl_mc_io *mc_io,
1751 enum dpni_queue_type qtype,
1754 struct dpni_queue *queue,
1755 struct dpni_queue_id *qid)
1757 struct mc_command cmd = { 0 };
1758 struct dpni_cmd_get_queue *cmd_params;
1759 struct dpni_rsp_get_queue *rsp_params;
1762 /* prepare command */
1763 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1766 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1767 cmd_params->qtype = qtype;
1768 cmd_params->tc = tc;
1769 cmd_params->index = index;
1771 /* send command to mc */
1772 err = mc_send_command(mc_io, &cmd);
1776 /* retrieve response parameters */
1777 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
1778 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
1779 queue->destination.priority = rsp_params->dest_prio;
1780 queue->destination.type = dpni_get_field(rsp_params->flags,
1782 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
1784 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
1786 queue->flc.value = le64_to_cpu(rsp_params->flc);
1787 queue->user_context = le64_to_cpu(rsp_params->user_context);
1788 qid->fqid = le32_to_cpu(rsp_params->fqid);
1789 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
1795 * dpni_get_statistics() - Get DPNI statistics
1796 * @mc_io: Pointer to MC portal's I/O object
1797 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1798 * @token: Token of DPNI object
1799 * @page: Selects the statistics page to retrieve, see
1800 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 2.
1801 * @param: Custom parameter for some pages used to select
1802 * a certain statistic source, for example the TC.
1803 * @stat: Structure containing the statistics
1805 * Return: '0' on Success; Error code otherwise.
1807 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1812 union dpni_statistics *stat)
1814 struct mc_command cmd = { 0 };
1815 struct dpni_cmd_get_statistics *cmd_params;
1816 struct dpni_rsp_get_statistics *rsp_params;
1819 /* prepare command */
1820 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
1823 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
1824 cmd_params->page_number = page;
1825 cmd_params->param = param;
1827 /* send command to mc */
1828 err = mc_send_command(mc_io, &cmd);
1832 /* retrieve response parameters */
1833 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
1834 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
1835 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
1841 * dpni_reset_statistics() - Clears DPNI statistics
1842 * @mc_io: Pointer to MC portal's I/O object
1843 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1844 * @token: Token of DPNI object
1846 * Return: '0' on Success; Error code otherwise.
1848 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1852 struct mc_command cmd = { 0 };
1854 /* prepare command */
1855 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
1859 /* send command to mc*/
1860 return mc_send_command(mc_io, &cmd);
1864 * dpni_set_taildrop() - Set taildrop per queue or TC
1866 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
1867 * congestion notification or early drop (WRED) configuration previously applied
1870 * @mc_io: Pointer to MC portal's I/O object
1871 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1872 * @token: Token of DPNI object
1873 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in
1874 * combination with DPNI_QUEUE_RX.
1875 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
1876 * @tc: Traffic class to apply this taildrop to
1877 * @q_index: Index of the queue if the DPNI supports multiple queues for
1878 * traffic distribution.
1879 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
1880 * @taildrop: Taildrop structure
1882 * Return: '0' on Success; Error code otherwise.
1884 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1887 enum dpni_congestion_point cg_point,
1888 enum dpni_queue_type qtype,
1891 struct dpni_taildrop *taildrop)
1893 struct mc_command cmd = { 0 };
1894 struct dpni_cmd_set_taildrop *cmd_params;
1896 /* prepare command */
1897 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
1900 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
1901 cmd_params->congestion_point = cg_point;
1902 cmd_params->qtype = qtype;
1903 cmd_params->tc = tc;
1904 cmd_params->index = index;
1905 cmd_params->units = taildrop->units;
1906 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
1907 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
1908 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
1909 dpni_set_field(cmd_params->oal_hi,
1911 taildrop->oal >> DPNI_OAL_LO_SIZE);
1913 /* send command to mc */
1914 return mc_send_command(mc_io, &cmd);
1918 * dpni_get_taildrop() - Get taildrop information
1919 * @mc_io: Pointer to MC portal's I/O object
1920 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1921 * @token: Token of DPNI object
1922 * @cg_point: Congestion point
1923 * @q_type: Queue type on which the taildrop is configured.
1924 * Only Rx queues are supported for now
1925 * @tc: Traffic class to apply this taildrop to
1926 * @q_index: Index of the queue if the DPNI supports multiple queues for
1927 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
1928 * @taildrop: Taildrop structure
1930 * Return: '0' on Success; Error code otherwise.
1932 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1935 enum dpni_congestion_point cg_point,
1936 enum dpni_queue_type qtype,
1939 struct dpni_taildrop *taildrop)
1941 struct mc_command cmd = { 0 };
1942 struct dpni_cmd_get_taildrop *cmd_params;
1943 struct dpni_rsp_get_taildrop *rsp_params;
1944 uint8_t oal_lo, oal_hi;
1947 /* prepare command */
1948 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
1951 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
1952 cmd_params->congestion_point = cg_point;
1953 cmd_params->qtype = qtype;
1954 cmd_params->tc = tc;
1955 cmd_params->index = index;
1957 /* send command to mc */
1958 err = mc_send_command(mc_io, &cmd);
1962 /* retrieve response parameters */
1963 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
1964 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
1965 taildrop->units = rsp_params->units;
1966 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
1967 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
1968 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
1969 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
1971 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
1972 if (taildrop->oal >= 0x0800)
1973 taildrop->oal |= 0xF000;