1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
10 #include <fsl_dpni_cmd.h>
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
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.
27 * Return: '0' on Success; Error code otherwise.
29 int dpni_open(struct fsl_mc_io *mc_io,
34 struct mc_command cmd = { 0 };
35 struct dpni_cmd_open *cmd_params;
40 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
43 cmd_params = (struct dpni_cmd_open *)cmd.params;
44 cmd_params->dpni_id = cpu_to_le32(dpni_id);
46 /* send command to mc*/
47 err = mc_send_command(mc_io, &cmd);
51 /* retrieve response parameters */
52 *token = mc_cmd_hdr_read_token(&cmd);
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
63 * After this function is called, no further operations are
64 * allowed on the object without opening a new control session.
66 * Return: '0' on Success; Error code otherwise.
68 int dpni_close(struct fsl_mc_io *mc_io,
72 struct mc_command cmd = { 0 };
75 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
79 /* send command to mc*/
80 return mc_send_command(mc_io, &cmd);
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
91 * Create the DPNI object, allocate required resources and
92 * perform required initialization.
94 * The object can be created either by declaring it in the
95 * DPL file, or by calling this function.
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.
103 * Return: '0' on Success; Error code otherwise.
105 int dpni_create(struct fsl_mc_io *mc_io,
108 const struct dpni_cfg *cfg,
111 struct dpni_cmd_create *cmd_params;
112 struct mc_command cmd = { 0 };
115 /* prepare command */
116 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
119 cmd_params = (struct dpni_cmd_create *)cmd.params;
120 cmd_params->options = cpu_to_le32(cfg->options);
121 cmd_params->num_queues = cfg->num_queues;
122 cmd_params->num_tcs = cfg->num_tcs;
123 cmd_params->mac_filter_entries = cfg->mac_filter_entries;
124 cmd_params->num_rx_tcs = cfg->num_rx_tcs;
125 cmd_params->vlan_filter_entries = cfg->vlan_filter_entries;
126 cmd_params->qos_entries = cfg->qos_entries;
127 cmd_params->fs_entries = cpu_to_le16(cfg->fs_entries);
129 /* send command to mc*/
130 err = mc_send_command(mc_io, &cmd);
134 /* retrieve response parameters */
135 *obj_id = mc_cmd_read_object_id(&cmd);
141 * dpni_destroy() - Destroy the DPNI object and release all its resources.
142 * @mc_io: Pointer to MC portal's I/O object
143 * @dprc_token: Parent container token; '0' for default container
144 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
145 * @object_id: The object id; it must be a valid id within the container that
146 * created this object;
148 * The function accepts the authentication token of the parent container that
149 * created the object (not the one that currently owns the object). The object
150 * is searched within parent using the provided 'object_id'.
151 * All tokens to the object must be closed before calling destroy.
153 * Return: '0' on Success; error code otherwise.
155 int dpni_destroy(struct fsl_mc_io *mc_io,
160 struct dpni_cmd_destroy *cmd_params;
161 struct mc_command cmd = { 0 };
163 /* prepare command */
164 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
167 /* set object id to destroy */
168 cmd_params = (struct dpni_cmd_destroy *)cmd.params;
169 cmd_params->dpsw_id = cpu_to_le32(object_id);
171 /* send command to mc*/
172 return mc_send_command(mc_io, &cmd);
176 * dpni_set_pools() - Set buffer pools configuration
177 * @mc_io: Pointer to MC portal's I/O object
178 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
179 * @token: Token of DPNI object
180 * @cfg: Buffer pools configuration
182 * mandatory for DPNI operation
183 * warning:Allowed only when DPNI is disabled
185 * Return: '0' on Success; Error code otherwise.
187 int dpni_set_pools(struct fsl_mc_io *mc_io,
190 const struct dpni_pools_cfg *cfg)
192 struct mc_command cmd = { 0 };
193 struct dpni_cmd_set_pools *cmd_params;
196 /* prepare command */
197 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
200 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
201 cmd_params->num_dpbp = cfg->num_dpbp;
202 for (i = 0; i < cmd_params->num_dpbp; i++) {
203 cmd_params->pool[i].dpbp_id =
204 cpu_to_le16(cfg->pools[i].dpbp_id);
205 cmd_params->pool[i].priority_mask =
206 cfg->pools[i].priority_mask;
207 cmd_params->buffer_size[i] =
208 cpu_to_le16(cfg->pools[i].buffer_size);
209 cmd_params->backup_pool_mask |=
210 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
213 /* send command to mc*/
214 return mc_send_command(mc_io, &cmd);
218 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
219 * @mc_io: Pointer to MC portal's I/O object
220 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
221 * @token: Token of DPNI object
223 * Return: '0' on Success; Error code otherwise.
225 int dpni_enable(struct fsl_mc_io *mc_io,
229 struct mc_command cmd = { 0 };
231 /* prepare command */
232 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
236 /* send command to mc*/
237 return mc_send_command(mc_io, &cmd);
241 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
242 * @mc_io: Pointer to MC portal's I/O object
243 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
244 * @token: Token of DPNI object
246 * Return: '0' on Success; Error code otherwise.
248 int dpni_disable(struct fsl_mc_io *mc_io,
252 struct mc_command cmd = { 0 };
254 /* prepare command */
255 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
259 /* send command to mc*/
260 return mc_send_command(mc_io, &cmd);
264 * dpni_is_enabled() - Check if the DPNI is enabled.
265 * @mc_io: Pointer to MC portal's I/O object
266 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
267 * @token: Token of DPNI object
268 * @en: Returns '1' if object is enabled; '0' otherwise
270 * Return: '0' on Success; Error code otherwise.
272 int dpni_is_enabled(struct fsl_mc_io *mc_io,
277 struct mc_command cmd = { 0 };
278 struct dpni_rsp_is_enabled *rsp_params;
281 /* prepare command */
282 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
286 /* send command to mc*/
287 err = mc_send_command(mc_io, &cmd);
291 /* retrieve response parameters */
292 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
293 *en = dpni_get_field(rsp_params->enabled, ENABLE);
299 * dpni_reset() - Reset the DPNI, returns the object to initial state.
300 * @mc_io: Pointer to MC portal's I/O object
301 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
302 * @token: Token of DPNI object
304 * Return: '0' on Success; Error code otherwise.
306 int dpni_reset(struct fsl_mc_io *mc_io,
310 struct mc_command cmd = { 0 };
312 /* prepare command */
313 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
317 /* send command to mc*/
318 return mc_send_command(mc_io, &cmd);
322 * dpni_set_irq_enable() - Set overall interrupt state.
323 * @mc_io: Pointer to MC portal's I/O object
324 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
325 * @token: Token of DPNI object
326 * @irq_index: The interrupt index to configure
327 * @en: Interrupt state: - enable = 1, disable = 0
329 * Allows GPP software to control when interrupts are generated.
330 * Each interrupt can have up to 32 causes. The enable/disable control's the
331 * overall interrupt state. if the interrupt is disabled no causes will cause
334 * Return: '0' on Success; Error code otherwise.
336 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
342 struct mc_command cmd = { 0 };
343 struct dpni_cmd_set_irq_enable *cmd_params;
345 /* prepare command */
346 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
349 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
350 dpni_set_field(cmd_params->enable, ENABLE, en);
351 cmd_params->irq_index = irq_index;
353 /* send command to mc*/
354 return mc_send_command(mc_io, &cmd);
358 * dpni_get_irq_enable() - Get overall interrupt state
359 * @mc_io: Pointer to MC portal's I/O object
360 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
361 * @token: Token of DPNI object
362 * @irq_index: The interrupt index to configure
363 * @en: Returned interrupt state - enable = 1, disable = 0
365 * Return: '0' on Success; Error code otherwise.
367 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
373 struct mc_command cmd = { 0 };
374 struct dpni_cmd_get_irq_enable *cmd_params;
375 struct dpni_rsp_get_irq_enable *rsp_params;
379 /* prepare command */
380 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
383 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
384 cmd_params->irq_index = irq_index;
386 /* send command to mc*/
387 err = mc_send_command(mc_io, &cmd);
391 /* retrieve response parameters */
392 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
393 *en = dpni_get_field(rsp_params->enabled, ENABLE);
399 * dpni_set_irq_mask() - Set interrupt mask.
400 * @mc_io: Pointer to MC portal's I/O object
401 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
402 * @token: Token of DPNI object
403 * @irq_index: The interrupt index to configure
404 * @mask: Event mask to trigger interrupt;
407 * 1 = consider event for asserting IRQ
409 * Every interrupt can have up to 32 causes and the interrupt model supports
410 * masking/unmasking each cause independently
412 * Return: '0' on Success; Error code otherwise.
414 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
420 struct mc_command cmd = { 0 };
421 struct dpni_cmd_set_irq_mask *cmd_params;
423 /* prepare command */
424 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
427 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
428 cmd_params->mask = cpu_to_le32(mask);
429 cmd_params->irq_index = irq_index;
431 /* send command to mc*/
432 return mc_send_command(mc_io, &cmd);
436 * dpni_get_irq_mask() - Get interrupt mask.
437 * @mc_io: Pointer to MC portal's I/O object
438 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
439 * @token: Token of DPNI object
440 * @irq_index: The interrupt index to configure
441 * @mask: Returned event mask to trigger interrupt
443 * Every interrupt can have up to 32 causes and the interrupt model supports
444 * masking/unmasking each cause independently
446 * Return: '0' on Success; Error code otherwise.
448 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
454 struct mc_command cmd = { 0 };
455 struct dpni_cmd_get_irq_mask *cmd_params;
456 struct dpni_rsp_get_irq_mask *rsp_params;
459 /* prepare command */
460 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
463 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
464 cmd_params->irq_index = irq_index;
466 /* send command to mc*/
467 err = mc_send_command(mc_io, &cmd);
471 /* retrieve response parameters */
472 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
473 *mask = le32_to_cpu(rsp_params->mask);
479 * dpni_get_irq_status() - Get the current status of any pending interrupts.
480 * @mc_io: Pointer to MC portal's I/O object
481 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
482 * @token: Token of DPNI object
483 * @irq_index: The interrupt index to configure
484 * @status: Returned interrupts status - one bit per cause:
485 * 0 = no interrupt pending
486 * 1 = interrupt pending
488 * Return: '0' on Success; Error code otherwise.
490 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
496 struct mc_command cmd = { 0 };
497 struct dpni_cmd_get_irq_status *cmd_params;
498 struct dpni_rsp_get_irq_status *rsp_params;
501 /* prepare command */
502 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
505 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
506 cmd_params->status = cpu_to_le32(*status);
507 cmd_params->irq_index = irq_index;
509 /* send command to mc*/
510 err = mc_send_command(mc_io, &cmd);
514 /* retrieve response parameters */
515 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
516 *status = le32_to_cpu(rsp_params->status);
522 * dpni_clear_irq_status() - Clear a pending interrupt's status
523 * @mc_io: Pointer to MC portal's I/O object
524 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
525 * @token: Token of DPNI object
526 * @irq_index: The interrupt index to configure
527 * @status: bits to clear (W1C) - one bit per cause:
529 * 1 = clear status bit
531 * Return: '0' on Success; Error code otherwise.
533 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
539 struct mc_command cmd = { 0 };
540 struct dpni_cmd_clear_irq_status *cmd_params;
542 /* prepare command */
543 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
546 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
547 cmd_params->irq_index = irq_index;
548 cmd_params->status = cpu_to_le32(status);
550 /* send command to mc*/
551 return mc_send_command(mc_io, &cmd);
555 * dpni_get_attributes() - Retrieve DPNI attributes.
556 * @mc_io: Pointer to MC portal's I/O object
557 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
558 * @token: Token of DPNI object
559 * @attr: Object's attributes
561 * Return: '0' on Success; Error code otherwise.
563 int dpni_get_attributes(struct fsl_mc_io *mc_io,
566 struct dpni_attr *attr)
568 struct mc_command cmd = { 0 };
569 struct dpni_rsp_get_attr *rsp_params;
573 /* prepare command */
574 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
578 /* send command to mc*/
579 err = mc_send_command(mc_io, &cmd);
583 /* retrieve response parameters */
584 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
585 attr->options = le32_to_cpu(rsp_params->options);
586 attr->num_queues = rsp_params->num_queues;
587 attr->num_rx_tcs = rsp_params->num_rx_tcs;
588 attr->num_tx_tcs = rsp_params->num_tx_tcs;
589 attr->mac_filter_entries = rsp_params->mac_filter_entries;
590 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
591 attr->qos_entries = rsp_params->qos_entries;
592 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
593 attr->qos_key_size = rsp_params->qos_key_size;
594 attr->fs_key_size = rsp_params->fs_key_size;
595 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
601 * dpni_set_errors_behavior() - Set errors behavior
602 * @mc_io: Pointer to MC portal's I/O object
603 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
604 * @token: Token of DPNI object
605 * @cfg: Errors configuration
607 * This function may be called numerous times with different
610 * Return: '0' on Success; Error code otherwise.
612 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
615 struct dpni_error_cfg *cfg)
617 struct mc_command cmd = { 0 };
618 struct dpni_cmd_set_errors_behavior *cmd_params;
620 /* prepare command */
621 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
624 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
625 cmd_params->errors = cpu_to_le32(cfg->errors);
626 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
627 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
629 /* send command to mc*/
630 return mc_send_command(mc_io, &cmd);
634 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
635 * @mc_io: Pointer to MC portal's I/O object
636 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
637 * @token: Token of DPNI object
638 * @qtype: Type of queue to retrieve configuration for
639 * @layout: Returns buffer layout attributes
641 * Return: '0' on Success; Error code otherwise.
643 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
646 enum dpni_queue_type qtype,
647 struct dpni_buffer_layout *layout)
649 struct mc_command cmd = { 0 };
650 struct dpni_cmd_get_buffer_layout *cmd_params;
651 struct dpni_rsp_get_buffer_layout *rsp_params;
654 /* prepare command */
655 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
658 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
659 cmd_params->qtype = qtype;
661 /* send command to mc*/
662 err = mc_send_command(mc_io, &cmd);
666 /* retrieve response parameters */
667 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
668 layout->pass_timestamp =
669 (int)dpni_get_field(rsp_params->flags, PASS_TS);
670 layout->pass_parser_result =
671 (int)dpni_get_field(rsp_params->flags, PASS_PR);
672 layout->pass_frame_status =
673 (int)dpni_get_field(rsp_params->flags, PASS_FS);
674 layout->pass_sw_opaque =
675 (int)dpni_get_field(rsp_params->flags, PASS_SWO);
676 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
677 layout->data_align = le16_to_cpu(rsp_params->data_align);
678 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
679 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
685 * dpni_set_buffer_layout() - Set buffer layout configuration.
686 * @mc_io: Pointer to MC portal's I/O object
687 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
688 * @token: Token of DPNI object
689 * @qtype: Type of queue this configuration applies to
690 * @layout: Buffer layout configuration
692 * Return: '0' on Success; Error code otherwise.
694 * @warning Allowed only when DPNI is disabled
696 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
699 enum dpni_queue_type qtype,
700 const struct dpni_buffer_layout *layout)
702 struct mc_command cmd = { 0 };
703 struct dpni_cmd_set_buffer_layout *cmd_params;
705 /* prepare command */
706 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
709 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
710 cmd_params->qtype = qtype;
711 cmd_params->options = cpu_to_le16((uint16_t)layout->options);
712 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
713 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
714 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
715 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
716 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
717 cmd_params->data_align = cpu_to_le16(layout->data_align);
718 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
719 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
721 /* send command to mc*/
722 return mc_send_command(mc_io, &cmd);
726 * dpni_set_offload() - Set DPNI offload configuration.
727 * @mc_io: Pointer to MC portal's I/O object
728 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
729 * @token: Token of DPNI object
730 * @type: Type of DPNI offload
731 * @config: Offload configuration.
732 * For checksum offloads, non-zero value enables the offload
734 * Return: '0' on Success; Error code otherwise.
736 * @warning Allowed only when DPNI is disabled
739 int dpni_set_offload(struct fsl_mc_io *mc_io,
742 enum dpni_offload type,
745 struct mc_command cmd = { 0 };
746 struct dpni_cmd_set_offload *cmd_params;
748 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
751 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
752 cmd_params->dpni_offload = type;
753 cmd_params->config = cpu_to_le32(config);
755 return mc_send_command(mc_io, &cmd);
759 * dpni_get_offload() - Get DPNI offload configuration.
760 * @mc_io: Pointer to MC portal's I/O object
761 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
762 * @token: Token of DPNI object
763 * @type: Type of DPNI offload
764 * @config: Offload configuration.
765 * For checksum offloads, a value of 1 indicates that the
766 * offload is enabled.
768 * Return: '0' on Success; Error code otherwise.
770 * @warning Allowed only when DPNI is disabled
772 int dpni_get_offload(struct fsl_mc_io *mc_io,
775 enum dpni_offload type,
778 struct mc_command cmd = { 0 };
779 struct dpni_cmd_get_offload *cmd_params;
780 struct dpni_rsp_get_offload *rsp_params;
783 /* prepare command */
784 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
787 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
788 cmd_params->dpni_offload = type;
790 /* send command to mc*/
791 err = mc_send_command(mc_io, &cmd);
795 /* retrieve response parameters */
796 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
797 *config = le32_to_cpu(rsp_params->config);
803 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
804 * for enqueue operations
805 * @mc_io: Pointer to MC portal's I/O object
806 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
807 * @token: Token of DPNI object
808 * @qtype: Type of queue to receive QDID for
809 * @qdid: Returned virtual QDID value that should be used as an argument
810 * in all enqueue operations
812 * Return: '0' on Success; Error code otherwise.
814 int dpni_get_qdid(struct fsl_mc_io *mc_io,
817 enum dpni_queue_type qtype,
820 struct mc_command cmd = { 0 };
821 struct dpni_cmd_get_qdid *cmd_params;
822 struct dpni_rsp_get_qdid *rsp_params;
825 /* prepare command */
826 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
829 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
830 cmd_params->qtype = qtype;
832 /* send command to mc*/
833 err = mc_send_command(mc_io, &cmd);
837 /* retrieve response parameters */
838 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
839 *qdid = le16_to_cpu(rsp_params->qdid);
845 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
846 * @mc_io: Pointer to MC portal's I/O object
847 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
848 * @token: Token of DPNI object
849 * @data_offset: Tx data offset (from start of buffer)
851 * Return: '0' on Success; Error code otherwise.
853 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
856 uint16_t *data_offset)
858 struct mc_command cmd = { 0 };
859 struct dpni_rsp_get_tx_data_offset *rsp_params;
862 /* prepare command */
863 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
867 /* send command to mc*/
868 err = mc_send_command(mc_io, &cmd);
872 /* retrieve response parameters */
873 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
874 *data_offset = le16_to_cpu(rsp_params->data_offset);
880 * dpni_set_link_cfg() - set the link configuration.
881 * @mc_io: Pointer to MC portal's I/O object
882 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
883 * @token: Token of DPNI object
884 * @cfg: Link configuration
886 * Return: '0' on Success; Error code otherwise.
888 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
891 const struct dpni_link_cfg *cfg)
893 struct mc_command cmd = { 0 };
894 struct dpni_cmd_set_link_cfg *cmd_params;
896 /* prepare command */
897 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
900 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
901 cmd_params->rate = cpu_to_le32(cfg->rate);
902 cmd_params->options = cpu_to_le64(cfg->options);
903 cmd_params->advertising = cpu_to_le64(cfg->advertising);
905 /* send command to mc*/
906 return mc_send_command(mc_io, &cmd);
910 * dpni_get_link_state() - Return the link state (either up or down)
911 * @mc_io: Pointer to MC portal's I/O object
912 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
913 * @token: Token of DPNI object
914 * @state: Returned link state;
916 * Return: '0' on Success; Error code otherwise.
918 int dpni_get_link_state(struct fsl_mc_io *mc_io,
921 struct dpni_link_state *state)
923 struct mc_command cmd = { 0 };
924 struct dpni_rsp_get_link_state *rsp_params;
927 /* prepare command */
928 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
932 /* send command to mc*/
933 err = mc_send_command(mc_io, &cmd);
937 /* retrieve response parameters */
938 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
939 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
940 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
941 state->rate = le32_to_cpu(rsp_params->rate);
942 state->options = le64_to_cpu(rsp_params->options);
943 state->supported = le64_to_cpu(rsp_params->supported);
944 state->advertising = le64_to_cpu(rsp_params->advertising);
950 * dpni_set_max_frame_length() - Set the maximum received frame length.
951 * @mc_io: Pointer to MC portal's I/O object
952 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
953 * @token: Token of DPNI object
954 * @max_frame_length: Maximum received frame length (in bytes);
955 * frame is discarded if its length exceeds this value
957 * Return: '0' on Success; Error code otherwise.
959 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
962 uint16_t max_frame_length)
964 struct mc_command cmd = { 0 };
965 struct dpni_cmd_set_max_frame_length *cmd_params;
967 /* prepare command */
968 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
971 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
972 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
974 /* send command to mc*/
975 return mc_send_command(mc_io, &cmd);
979 * dpni_get_max_frame_length() - Get the maximum received frame length.
980 * @mc_io: Pointer to MC portal's I/O object
981 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
982 * @token: Token of DPNI object
983 * @max_frame_length: Maximum received frame length (in bytes);
984 * frame is discarded if its length exceeds this value
986 * Return: '0' on Success; Error code otherwise.
988 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
991 uint16_t *max_frame_length)
993 struct mc_command cmd = { 0 };
994 struct dpni_rsp_get_max_frame_length *rsp_params;
997 /* prepare command */
998 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1002 /* send command to mc*/
1003 err = mc_send_command(mc_io, &cmd);
1007 /* retrieve response parameters */
1008 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1009 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1015 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1016 * @mc_io: Pointer to MC portal's I/O object
1017 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1018 * @token: Token of DPNI object
1019 * @en: Set to '1' to enable; '0' to disable
1021 * Return: '0' on Success; Error code otherwise.
1023 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1028 struct mc_command cmd = { 0 };
1029 struct dpni_cmd_set_multicast_promisc *cmd_params;
1031 /* prepare command */
1032 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1035 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1036 dpni_set_field(cmd_params->enable, ENABLE, en);
1038 /* send command to mc*/
1039 return mc_send_command(mc_io, &cmd);
1043 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1044 * @mc_io: Pointer to MC portal's I/O object
1045 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1046 * @token: Token of DPNI object
1047 * @en: Returns '1' if enabled; '0' otherwise
1049 * Return: '0' on Success; Error code otherwise.
1051 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1056 struct mc_command cmd = { 0 };
1057 struct dpni_rsp_get_multicast_promisc *rsp_params;
1060 /* prepare command */
1061 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1065 /* send command to mc*/
1066 err = mc_send_command(mc_io, &cmd);
1070 /* retrieve response parameters */
1071 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1072 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1078 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1079 * @mc_io: Pointer to MC portal's I/O object
1080 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1081 * @token: Token of DPNI object
1082 * @en: Set to '1' to enable; '0' to disable
1084 * Return: '0' on Success; Error code otherwise.
1086 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1091 struct mc_command cmd = { 0 };
1092 struct dpni_cmd_set_unicast_promisc *cmd_params;
1094 /* prepare command */
1095 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1098 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1099 dpni_set_field(cmd_params->enable, ENABLE, en);
1101 /* send command to mc*/
1102 return mc_send_command(mc_io, &cmd);
1106 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1107 * @mc_io: Pointer to MC portal's I/O object
1108 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1109 * @token: Token of DPNI object
1110 * @en: Returns '1' if enabled; '0' otherwise
1112 * Return: '0' on Success; Error code otherwise.
1114 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1119 struct mc_command cmd = { 0 };
1120 struct dpni_rsp_get_unicast_promisc *rsp_params;
1123 /* prepare command */
1124 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1128 /* send command to mc*/
1129 err = mc_send_command(mc_io, &cmd);
1133 /* retrieve response parameters */
1134 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1135 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1141 * dpni_set_primary_mac_addr() - Set the primary MAC address
1142 * @mc_io: Pointer to MC portal's I/O object
1143 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1144 * @token: Token of DPNI object
1145 * @mac_addr: MAC address to set as primary address
1147 * Return: '0' on Success; Error code otherwise.
1149 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1152 const uint8_t mac_addr[6])
1154 struct mc_command cmd = { 0 };
1155 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1158 /* prepare command */
1159 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1162 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1163 for (i = 0; i < 6; i++)
1164 cmd_params->mac_addr[i] = mac_addr[5 - i];
1166 /* send command to mc*/
1167 return mc_send_command(mc_io, &cmd);
1171 * dpni_get_primary_mac_addr() - Get the primary MAC address
1172 * @mc_io: Pointer to MC portal's I/O object
1173 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1174 * @token: Token of DPNI object
1175 * @mac_addr: Returned MAC address
1177 * Return: '0' on Success; Error code otherwise.
1179 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1182 uint8_t mac_addr[6])
1184 struct mc_command cmd = { 0 };
1185 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1188 /* prepare command */
1189 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1193 /* send command to mc*/
1194 err = mc_send_command(mc_io, &cmd);
1198 /* retrieve response parameters */
1199 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1200 for (i = 0; i < 6; i++)
1201 mac_addr[5 - i] = rsp_params->mac_addr[i];
1207 * dpni_add_mac_addr() - Add MAC address filter
1208 * @mc_io: Pointer to MC portal's I/O object
1209 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1210 * @token: Token of DPNI object
1211 * @mac_addr: MAC address to add
1213 * Return: '0' on Success; Error code otherwise.
1215 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1218 const uint8_t mac_addr[6])
1220 struct mc_command cmd = { 0 };
1221 struct dpni_cmd_add_mac_addr *cmd_params;
1224 /* prepare command */
1225 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1228 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1229 for (i = 0; i < 6; i++)
1230 cmd_params->mac_addr[i] = mac_addr[5 - i];
1232 /* send command to mc*/
1233 return mc_send_command(mc_io, &cmd);
1237 * dpni_remove_mac_addr() - Remove MAC address filter
1238 * @mc_io: Pointer to MC portal's I/O object
1239 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1240 * @token: Token of DPNI object
1241 * @mac_addr: MAC address to remove
1243 * Return: '0' on Success; Error code otherwise.
1245 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1248 const uint8_t mac_addr[6])
1250 struct mc_command cmd = { 0 };
1251 struct dpni_cmd_remove_mac_addr *cmd_params;
1254 /* prepare command */
1255 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1258 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1259 for (i = 0; i < 6; i++)
1260 cmd_params->mac_addr[i] = mac_addr[5 - i];
1262 /* send command to mc*/
1263 return mc_send_command(mc_io, &cmd);
1267 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1268 * @mc_io: Pointer to MC portal's I/O object
1269 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1270 * @token: Token of DPNI object
1271 * @unicast: Set to '1' to clear unicast addresses
1272 * @multicast: Set to '1' to clear multicast addresses
1274 * The primary MAC address is not cleared by this operation.
1276 * Return: '0' on Success; Error code otherwise.
1278 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1284 struct mc_command cmd = { 0 };
1285 struct dpni_cmd_clear_mac_filters *cmd_params;
1287 /* prepare command */
1288 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1291 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1292 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1293 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1295 /* send command to mc*/
1296 return mc_send_command(mc_io, &cmd);
1300 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1301 * port the DPNI is attached to
1302 * @mc_io: Pointer to MC portal's I/O object
1303 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1304 * @token: Token of DPNI object
1305 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1307 * The primary MAC address is not cleared by this operation.
1309 * Return: '0' on Success; Error code otherwise.
1311 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1314 uint8_t mac_addr[6])
1316 struct mc_command cmd = { 0 };
1317 struct dpni_rsp_get_port_mac_addr *rsp_params;
1320 /* prepare command */
1321 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1325 /* send command to mc*/
1326 err = mc_send_command(mc_io, &cmd);
1330 /* retrieve response parameters */
1331 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1332 for (i = 0; i < 6; i++)
1333 mac_addr[5 - i] = rsp_params->mac_addr[i];
1339 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1340 * @mc_io: Pointer to MC portal's I/O object
1341 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1342 * @token: Token of DPNI object
1343 * @en: Set to '1' to enable; '0' to disable
1345 * Return: '0' on Success; Error code otherwise.
1347 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1352 struct dpni_cmd_enable_vlan_filter *cmd_params;
1353 struct mc_command cmd = { 0 };
1355 /* prepare command */
1356 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1359 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1360 dpni_set_field(cmd_params->en, ENABLE, en);
1362 /* send command to mc*/
1363 return mc_send_command(mc_io, &cmd);
1367 * dpni_add_vlan_id() - Add VLAN ID filter
1368 * @mc_io: Pointer to MC portal's I/O object
1369 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1370 * @token: Token of DPNI object
1371 * @vlan_id: VLAN ID to add
1373 * Return: '0' on Success; Error code otherwise.
1375 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1380 struct dpni_cmd_vlan_id *cmd_params;
1381 struct mc_command cmd = { 0 };
1383 /* prepare command */
1384 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1387 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1388 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1390 /* send command to mc*/
1391 return mc_send_command(mc_io, &cmd);
1395 * dpni_remove_vlan_id() - Remove VLAN ID filter
1396 * @mc_io: Pointer to MC portal's I/O object
1397 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1398 * @token: Token of DPNI object
1399 * @vlan_id: VLAN ID to remove
1401 * Return: '0' on Success; Error code otherwise.
1403 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1408 struct dpni_cmd_vlan_id *cmd_params;
1409 struct mc_command cmd = { 0 };
1411 /* prepare command */
1412 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1415 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1416 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1418 /* send command to mc*/
1419 return mc_send_command(mc_io, &cmd);
1423 * dpni_clear_vlan_filters() - Clear all VLAN filters
1424 * @mc_io: Pointer to MC portal's I/O object
1425 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1426 * @token: Token of DPNI object
1428 * Return: '0' on Success; Error code otherwise.
1430 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1434 struct mc_command cmd = { 0 };
1436 /* prepare command */
1437 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1441 /* send command to mc*/
1442 return mc_send_command(mc_io, &cmd);
1446 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1447 * @mc_io: Pointer to MC portal's I/O object
1448 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1449 * @token: Token of DPNI object
1450 * @tc_id: Traffic class selection (0-7)
1451 * @cfg: Traffic class distribution configuration
1453 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1454 * first to prepare the key_cfg_iova parameter
1456 * Return: '0' on Success; error code otherwise.
1458 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1462 const struct dpni_rx_tc_dist_cfg *cfg)
1464 struct mc_command cmd = { 0 };
1465 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1467 /* prepare command */
1468 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1471 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1472 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1473 cmd_params->tc_id = tc_id;
1474 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1475 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1476 dpni_set_field(cmd_params->flags,
1479 dpni_set_field(cmd_params->flags,
1481 cfg->fs_cfg.miss_action);
1482 dpni_set_field(cmd_params->keep_hash_key,
1484 cfg->fs_cfg.keep_hash_key);
1485 dpni_set_field(cmd_params->keep_hash_key,
1487 cfg->fs_cfg.keep_entries);
1489 /* send command to mc*/
1490 return mc_send_command(mc_io, &cmd);
1494 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1495 * @mc_io: Pointer to MC portal's I/O object
1496 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1497 * @token: Token of DPNI object
1498 * @mode: Tx confirmation mode
1500 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1501 * selected at DPNI creation.
1502 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1503 * transmit confirmation (including the private confirmation queues), regardless
1504 * of previous settings; Note that in this case, Tx error frames are still
1505 * enqueued to the general transmit errors queue.
1506 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1507 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1508 * command will be ignored.
1510 * Return: '0' on Success; Error code otherwise.
1512 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1515 enum dpni_confirmation_mode mode)
1517 struct dpni_tx_confirmation_mode *cmd_params;
1518 struct mc_command cmd = { 0 };
1520 /* prepare command */
1521 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1524 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1525 cmd_params->confirmation_mode = mode;
1527 /* send command to mc*/
1528 return mc_send_command(mc_io, &cmd);
1532 * dpni_set_qos_table() - Set QoS mapping table
1533 * @mc_io: Pointer to MC portal's I/O object
1534 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1535 * @token: Token of DPNI object
1536 * @cfg: QoS table configuration
1538 * This function and all QoS-related functions require that
1539 *'max_tcs > 1' was set at DPNI creation.
1541 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1542 * prepare the key_cfg_iova parameter
1544 * Return: '0' on Success; Error code otherwise.
1546 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1549 const struct dpni_qos_tbl_cfg *cfg)
1551 struct dpni_cmd_set_qos_table *cmd_params;
1552 struct mc_command cmd = { 0 };
1554 /* prepare command */
1555 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1558 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1559 cmd_params->default_tc = cfg->default_tc;
1560 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1561 dpni_set_field(cmd_params->discard_on_miss,
1563 cfg->discard_on_miss);
1564 dpni_set_field(cmd_params->discard_on_miss,
1568 /* send command to mc*/
1569 return mc_send_command(mc_io, &cmd);
1573 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1574 * @mc_io: Pointer to MC portal's I/O object
1575 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1576 * @token: Token of DPNI object
1577 * @cfg: QoS rule to add
1578 * @tc_id: Traffic class selection (0-7)
1579 * @index: Location in the QoS table where to insert the entry.
1580 * Only relevant if MASKING is enabled for QoS classification on
1581 * this DPNI, it is ignored for exact match.
1583 * Return: '0' on Success; Error code otherwise.
1585 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1588 const struct dpni_rule_cfg *cfg,
1592 struct dpni_cmd_add_qos_entry *cmd_params;
1593 struct mc_command cmd = { 0 };
1595 /* prepare command */
1596 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1599 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1600 cmd_params->tc_id = tc_id;
1601 cmd_params->key_size = cfg->key_size;
1602 cmd_params->index = cpu_to_le16(index);
1603 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1604 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1606 /* send command to mc*/
1607 return mc_send_command(mc_io, &cmd);
1611 * dpni_remove_qos_entry() - Remove QoS mapping entry
1612 * @mc_io: Pointer to MC portal's I/O object
1613 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1614 * @token: Token of DPNI object
1615 * @cfg: QoS rule to remove
1617 * Return: '0' on Success; Error code otherwise.
1619 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1622 const struct dpni_rule_cfg *cfg)
1624 struct dpni_cmd_remove_qos_entry *cmd_params;
1625 struct mc_command cmd = { 0 };
1627 /* prepare command */
1628 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1631 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1632 cmd_params->key_size = cfg->key_size;
1633 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1634 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1636 /* send command to mc*/
1637 return mc_send_command(mc_io, &cmd);
1641 * dpni_clear_qos_table() - Clear all QoS mapping entries
1642 * @mc_io: Pointer to MC portal's I/O object
1643 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1644 * @token: Token of DPNI object
1646 * Following this function call, all frames are directed to
1647 * the default traffic class (0)
1649 * Return: '0' on Success; Error code otherwise.
1651 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1655 struct mc_command cmd = { 0 };
1657 /* prepare command */
1658 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1662 /* send command to mc*/
1663 return mc_send_command(mc_io, &cmd);
1667 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1668 * (to select a flow ID)
1669 * @mc_io: Pointer to MC portal's I/O object
1670 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1671 * @token: Token of DPNI object
1672 * @tc_id: Traffic class selection (0-7)
1673 * @index: Location in the QoS table where to insert the entry.
1674 * Only relevant if MASKING is enabled for QoS classification
1675 * on this DPNI, it is ignored for exact match.
1676 * @cfg: Flow steering rule to add
1677 * @action: Action to be taken as result of a classification hit
1679 * Return: '0' on Success; Error code otherwise.
1681 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1686 const struct dpni_rule_cfg *cfg,
1687 const struct dpni_fs_action_cfg *action)
1689 struct dpni_cmd_add_fs_entry *cmd_params;
1690 struct mc_command cmd = { 0 };
1692 /* prepare command */
1693 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1696 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1697 cmd_params->tc_id = tc_id;
1698 cmd_params->key_size = cfg->key_size;
1699 cmd_params->index = cpu_to_le16(index);
1700 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1701 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1702 cmd_params->options = cpu_to_le16(action->options);
1703 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1704 cmd_params->flc = cpu_to_le64(action->flc);
1706 /* send command to mc*/
1707 return mc_send_command(mc_io, &cmd);
1711 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1713 * @mc_io: Pointer to MC portal's I/O object
1714 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1715 * @token: Token of DPNI object
1716 * @tc_id: Traffic class selection (0-7)
1717 * @cfg: Flow steering rule to remove
1719 * Return: '0' on Success; Error code otherwise.
1721 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1725 const struct dpni_rule_cfg *cfg)
1727 struct dpni_cmd_remove_fs_entry *cmd_params;
1728 struct mc_command cmd = { 0 };
1730 /* prepare command */
1731 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1734 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1735 cmd_params->tc_id = tc_id;
1736 cmd_params->key_size = cfg->key_size;
1737 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1738 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1740 /* send command to mc*/
1741 return mc_send_command(mc_io, &cmd);
1745 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1747 * @mc_io: Pointer to MC portal's I/O object
1748 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1749 * @token: Token of DPNI object
1750 * @tc_id: Traffic class selection (0-7)
1752 * Return: '0' on Success; Error code otherwise.
1754 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1759 struct dpni_cmd_clear_fs_entries *cmd_params;
1760 struct mc_command cmd = { 0 };
1762 /* prepare command */
1763 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1766 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1767 cmd_params->tc_id = tc_id;
1769 /* send command to mc*/
1770 return mc_send_command(mc_io, &cmd);
1774 * dpni_set_congestion_notification() - Set traffic class congestion
1775 * notification configuration
1776 * @mc_io: Pointer to MC portal's I/O object
1777 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1778 * @token: Token of DPNI object
1779 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1780 * @tc_id: Traffic class selection (0-7)
1781 * @cfg: congestion notification configuration
1783 * Return: '0' on Success; error code otherwise.
1785 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1788 enum dpni_queue_type qtype,
1790 const struct dpni_congestion_notification_cfg *cfg)
1792 struct dpni_cmd_set_congestion_notification *cmd_params;
1793 struct mc_command cmd = { 0 };
1795 /* prepare command */
1796 cmd.header = mc_encode_cmd_header(
1797 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1800 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1801 cmd_params->qtype = qtype;
1802 cmd_params->tc = tc_id;
1803 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1804 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1805 cmd_params->dest_priority = cfg->dest_cfg.priority;
1806 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1807 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1808 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1809 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1810 dpni_set_field(cmd_params->type_units,
1812 cfg->dest_cfg.dest_type);
1813 dpni_set_field(cmd_params->type_units,
1817 /* send command to mc*/
1818 return mc_send_command(mc_io, &cmd);
1822 * dpni_get_congestion_notification() - Get traffic class congestion
1823 * notification configuration
1824 * @mc_io: Pointer to MC portal's I/O object
1825 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1826 * @token: Token of DPNI object
1827 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1828 * @tc_id: Traffic class selection (0-7)
1829 * @cfg: congestion notification configuration
1831 * Return: '0' on Success; error code otherwise.
1833 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1836 enum dpni_queue_type qtype,
1838 struct dpni_congestion_notification_cfg *cfg)
1840 struct dpni_rsp_get_congestion_notification *rsp_params;
1841 struct dpni_cmd_get_congestion_notification *cmd_params;
1842 struct mc_command cmd = { 0 };
1845 /* prepare command */
1846 cmd.header = mc_encode_cmd_header(
1847 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
1850 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
1851 cmd_params->qtype = qtype;
1852 cmd_params->tc = tc_id;
1854 /* send command to mc*/
1855 err = mc_send_command(mc_io, &cmd);
1859 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
1860 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
1861 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
1862 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
1863 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
1864 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
1865 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
1866 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
1867 cfg->dest_cfg.priority = rsp_params->dest_priority;
1868 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
1875 * dpni_get_api_version() - Get Data Path Network Interface API version
1876 * @mc_io: Pointer to MC portal's I/O object
1877 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1878 * @major_ver: Major version of data path network interface API
1879 * @minor_ver: Minor version of data path network interface API
1881 * Return: '0' on Success; Error code otherwise.
1883 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1885 uint16_t *major_ver,
1886 uint16_t *minor_ver)
1888 struct dpni_rsp_get_api_version *rsp_params;
1889 struct mc_command cmd = { 0 };
1892 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1896 err = mc_send_command(mc_io, &cmd);
1900 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1901 *major_ver = le16_to_cpu(rsp_params->major);
1902 *minor_ver = le16_to_cpu(rsp_params->minor);
1908 * dpni_set_queue() - Set queue parameters
1909 * @mc_io: Pointer to MC portal's I/O object
1910 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1911 * @token: Token of DPNI object
1912 * @qtype: Type of queue - all queue types are supported, although
1913 * the command is ignored for Tx
1914 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1915 * @index: Selects the specific queue out of the set allocated for the
1916 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1917 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
1918 * configuration options are set on the queue
1919 * @queue: Queue structure
1921 * Return: '0' on Success; Error code otherwise.
1923 int dpni_set_queue(struct fsl_mc_io *mc_io,
1926 enum dpni_queue_type qtype,
1930 const struct dpni_queue *queue)
1932 struct mc_command cmd = { 0 };
1933 struct dpni_cmd_set_queue *cmd_params;
1935 /* prepare command */
1936 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1939 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1940 cmd_params->qtype = qtype;
1941 cmd_params->tc = tc;
1942 cmd_params->index = index;
1943 cmd_params->options = options;
1944 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1945 cmd_params->dest_prio = queue->destination.priority;
1946 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1947 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1948 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1949 queue->destination.hold_active);
1950 cmd_params->flc = cpu_to_le64(queue->flc.value);
1951 cmd_params->user_context = cpu_to_le64(queue->user_context);
1953 /* send command to mc */
1954 return mc_send_command(mc_io, &cmd);
1958 * dpni_get_queue() - Get queue parameters
1959 * @mc_io: Pointer to MC portal's I/O object
1960 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1961 * @token: Token of DPNI object
1962 * @qtype: Type of queue - all queue types are supported
1963 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1964 * @index: Selects the specific queue out of the set allocated for the
1965 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1966 * @queue: Queue configuration structure
1967 * @qid: Queue identification
1969 * Return: '0' on Success; Error code otherwise.
1971 int dpni_get_queue(struct fsl_mc_io *mc_io,
1974 enum dpni_queue_type qtype,
1977 struct dpni_queue *queue,
1978 struct dpni_queue_id *qid)
1980 struct mc_command cmd = { 0 };
1981 struct dpni_cmd_get_queue *cmd_params;
1982 struct dpni_rsp_get_queue *rsp_params;
1985 /* prepare command */
1986 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1989 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1990 cmd_params->qtype = qtype;
1991 cmd_params->tc = tc;
1992 cmd_params->index = index;
1994 /* send command to mc */
1995 err = mc_send_command(mc_io, &cmd);
1999 /* retrieve response parameters */
2000 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2001 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2002 queue->destination.priority = rsp_params->dest_prio;
2003 queue->destination.type = dpni_get_field(rsp_params->flags,
2005 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2007 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2009 queue->flc.value = le64_to_cpu(rsp_params->flc);
2010 queue->user_context = le64_to_cpu(rsp_params->user_context);
2011 qid->fqid = le32_to_cpu(rsp_params->fqid);
2012 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2018 * dpni_get_statistics() - Get DPNI statistics
2019 * @mc_io: Pointer to MC portal's I/O object
2020 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2021 * @token: Token of DPNI object
2022 * @page: Selects the statistics page to retrieve, see
2023 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 3.
2024 * @param: Custom parameter for some pages used to select
2025 * a certain statistic source, for example the TC.
2026 * @stat: Structure containing the statistics
2028 * Return: '0' on Success; Error code otherwise.
2030 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2035 union dpni_statistics *stat)
2037 struct mc_command cmd = { 0 };
2038 struct dpni_cmd_get_statistics *cmd_params;
2039 struct dpni_rsp_get_statistics *rsp_params;
2042 /* prepare command */
2043 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2046 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2047 cmd_params->page_number = page;
2048 cmd_params->param = param;
2050 /* send command to mc */
2051 err = mc_send_command(mc_io, &cmd);
2055 /* retrieve response parameters */
2056 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2057 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2058 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2064 * dpni_reset_statistics() - Clears DPNI statistics
2065 * @mc_io: Pointer to MC portal's I/O object
2066 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2067 * @token: Token of DPNI object
2069 * Return: '0' on Success; Error code otherwise.
2071 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2075 struct mc_command cmd = { 0 };
2077 /* prepare command */
2078 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2082 /* send command to mc*/
2083 return mc_send_command(mc_io, &cmd);
2087 * dpni_set_taildrop() - Set taildrop per queue or TC
2089 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2090 * congestion notification or early drop (WRED) configuration previously applied
2093 * @mc_io: Pointer to MC portal's I/O object
2094 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2095 * @token: Token of DPNI object
2096 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in
2097 * combination with DPNI_QUEUE_RX.
2098 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2099 * @tc: Traffic class to apply this taildrop to
2100 * @q_index: Index of the queue if the DPNI supports multiple queues for
2101 * traffic distribution.
2102 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
2103 * @taildrop: Taildrop structure
2105 * Return: '0' on Success; Error code otherwise.
2107 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2110 enum dpni_congestion_point cg_point,
2111 enum dpni_queue_type qtype,
2114 struct dpni_taildrop *taildrop)
2116 struct mc_command cmd = { 0 };
2117 struct dpni_cmd_set_taildrop *cmd_params;
2119 /* prepare command */
2120 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2123 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2124 cmd_params->congestion_point = cg_point;
2125 cmd_params->qtype = qtype;
2126 cmd_params->tc = tc;
2127 cmd_params->index = index;
2128 cmd_params->units = taildrop->units;
2129 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2130 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2131 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2132 dpni_set_field(cmd_params->oal_hi,
2134 taildrop->oal >> DPNI_OAL_LO_SIZE);
2136 /* send command to mc */
2137 return mc_send_command(mc_io, &cmd);
2141 * dpni_get_taildrop() - Get taildrop information
2142 * @mc_io: Pointer to MC portal's I/O object
2143 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2144 * @token: Token of DPNI object
2145 * @cg_point: Congestion point
2146 * @q_type: Queue type on which the taildrop is configured.
2147 * Only Rx queues are supported for now
2148 * @tc: Traffic class to apply this taildrop to
2149 * @q_index: Index of the queue if the DPNI supports multiple queues for
2150 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2151 * @taildrop: Taildrop structure
2153 * Return: '0' on Success; Error code otherwise.
2155 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2158 enum dpni_congestion_point cg_point,
2159 enum dpni_queue_type qtype,
2162 struct dpni_taildrop *taildrop)
2164 struct mc_command cmd = { 0 };
2165 struct dpni_cmd_get_taildrop *cmd_params;
2166 struct dpni_rsp_get_taildrop *rsp_params;
2167 uint8_t oal_lo, oal_hi;
2170 /* prepare command */
2171 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2174 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2175 cmd_params->congestion_point = cg_point;
2176 cmd_params->qtype = qtype;
2177 cmd_params->tc = tc;
2178 cmd_params->index = index;
2180 /* send command to mc */
2181 err = mc_send_command(mc_io, &cmd);
2185 /* retrieve response parameters */
2186 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2187 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2188 taildrop->units = rsp_params->units;
2189 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2190 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2191 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2192 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2194 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2195 if (taildrop->oal >= 0x0800)
2196 taildrop->oal |= 0xF000;
2202 * dpni_set_opr() - Set Order Restoration configuration.
2203 * @mc_io: Pointer to MC portal's I/O object
2204 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2205 * @token: Token of DPNI object
2206 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2207 * @index: Selects the specific queue out of the set allocated
2208 * for the same TC. Value must be in range 0 to
2210 * @options: Configuration mode options
2211 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2212 * @cfg: Configuration options for the OPR
2214 * Return: '0' on Success; Error code otherwise.
2216 int dpni_set_opr(struct fsl_mc_io *mc_io,
2222 struct opr_cfg *cfg)
2224 struct dpni_cmd_set_opr *cmd_params;
2225 struct mc_command cmd = { 0 };
2227 /* prepare command */
2228 cmd.header = mc_encode_cmd_header(
2232 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2233 cmd_params->tc_id = tc;
2234 cmd_params->index = index;
2235 cmd_params->options = options;
2236 cmd_params->oloe = cfg->oloe;
2237 cmd_params->oeane = cfg->oeane;
2238 cmd_params->olws = cfg->olws;
2239 cmd_params->oa = cfg->oa;
2240 cmd_params->oprrws = cfg->oprrws;
2242 /* send command to mc*/
2243 return mc_send_command(mc_io, &cmd);
2247 * dpni_get_opr() - Retrieve Order Restoration config and query.
2248 * @mc_io: Pointer to MC portal's I/O object
2249 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2250 * @token: Token of DPNI object
2251 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2252 * @index: Selects the specific queue out of the set allocated
2253 * for the same TC. Value must be in range 0 to
2255 * @cfg: Returned OPR configuration
2256 * @qry: Returned OPR query
2258 * Return: '0' on Success; Error code otherwise.
2260 int dpni_get_opr(struct fsl_mc_io *mc_io,
2265 struct opr_cfg *cfg,
2266 struct opr_qry *qry)
2268 struct dpni_rsp_get_opr *rsp_params;
2269 struct dpni_cmd_get_opr *cmd_params;
2270 struct mc_command cmd = { 0 };
2273 /* prepare command */
2274 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2277 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2278 cmd_params->index = index;
2279 cmd_params->tc_id = tc;
2281 /* send command to mc*/
2282 err = mc_send_command(mc_io, &cmd);
2286 /* retrieve response parameters */
2287 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2288 cfg->oloe = rsp_params->oloe;
2289 cfg->oeane = rsp_params->oeane;
2290 cfg->olws = rsp_params->olws;
2291 cfg->oa = rsp_params->oa;
2292 cfg->oprrws = rsp_params->oprrws;
2293 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2294 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2295 qry->nesn = le16_to_cpu(rsp_params->nesn);
2296 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2297 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2298 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2299 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2300 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2301 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2302 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2303 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2304 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2310 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2311 * @mc_io: Pointer to MC portal's I/O object
2312 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2313 * @token: Token of DPNI object
2314 * @cfg: Distribution configuration
2315 * If the FS is already enabled with a previous call the classification
2316 * key will be changed but all the table rules are kept. If the
2317 * existing rules do not match the key the results will not be
2318 * predictable. It is the user responsibility to keep key integrity
2319 * If cfg.enable is set to 1 the command will create a flow steering table
2320 * and will classify packets according to this table. The packets
2321 * that miss all the table rules will be classified according to
2322 * settings made in dpni_set_rx_hash_dist()
2323 * If cfg.enable is set to 0 the command will clear flow steering table. The
2324 * packets will be classified according to settings made in
2325 * dpni_set_rx_hash_dist()
2327 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2328 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2330 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2331 struct mc_command cmd = { 0 };
2333 /* prepare command */
2334 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2337 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2338 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2339 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2340 cmd_params->tc = cfg->tc;
2341 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2342 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2344 /* send command to mc*/
2345 return mc_send_command(mc_io, &cmd);
2349 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2350 * @mc_io: Pointer to MC portal's I/O object
2351 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2352 * @token: Token of DPNI object
2353 * @cfg: Distribution configuration
2354 * If cfg.enable is set to 1 the packets will be classified using a hash
2355 * function based on the key received in cfg.key_cfg_iova parameter
2356 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2357 * dpni_set_rx_dist_default_queue() call
2359 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2360 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2362 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2363 struct mc_command cmd = { 0 };
2365 /* prepare command */
2366 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2369 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2370 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2371 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2372 cmd_params->tc_id = cfg->tc;
2373 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2375 /* send command to mc*/
2376 return mc_send_command(mc_io, &cmd);
2380 * dpni_add_custom_tpid() - Configures a distinct Ethertype value
2381 * (or TPID value) to indicate VLAN tag in addition to the common
2382 * TPID values 0x8100 and 0x88A8
2383 * @mc_io: Pointer to MC portal's I/O object
2384 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2385 * @token: Token of DPNI object
2386 * @tpid: New value for TPID
2388 * Only two custom values are accepted. If the function is called for the third
2389 * time it will return error.
2390 * To replace an existing value use dpni_remove_custom_tpid() to remove
2391 * a previous TPID and after that use again the function.
2393 * Return: '0' on Success; Error code otherwise.
2395 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2396 uint16_t token, uint16_t tpid)
2398 struct dpni_cmd_add_custom_tpid *cmd_params;
2399 struct mc_command cmd = { 0 };
2401 /* prepare command */
2402 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
2405 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
2406 cmd_params->tpid = cpu_to_le16(tpid);
2408 /* send command to mc*/
2409 return mc_send_command(mc_io, &cmd);
2413 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
2414 * previously with dpni_add_custom_tpid()
2415 * @mc_io: Pointer to MC portal's I/O object
2416 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2417 * @token: Token of DPNI object
2418 * @tpid: New value for TPID
2420 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
2423 * Return: '0' on Success; Error code otherwise.
2425 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2426 uint16_t token, uint16_t tpid)
2428 struct dpni_cmd_remove_custom_tpid *cmd_params;
2429 struct mc_command cmd = { 0 };
2431 /* prepare command */
2432 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
2435 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
2436 cmd_params->tpid = cpu_to_le16(tpid);
2438 /* send command to mc*/
2439 return mc_send_command(mc_io, &cmd);
2443 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured
2444 * to detect 802.1q frames
2445 * @mc_io: Pointer to MC portal's I/O object
2446 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2447 * @token: Token of DPNI object
2448 * @tpid: TPID values. Only nonzero members of the structure are valid.
2450 * Return: '0' on Success; Error code otherwise.
2452 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2453 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
2455 struct dpni_rsp_get_custom_tpid *rsp_params;
2456 struct mc_command cmd = { 0 };
2459 /* prepare command */
2460 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
2464 /* send command to mc*/
2465 err = mc_send_command(mc_io, &cmd);
2469 /* read command response */
2470 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
2471 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
2472 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);