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_congestion_notification() - Set traffic class congestion
1533 * notification configuration
1534 * @mc_io: Pointer to MC portal's I/O object
1535 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1536 * @token: Token of DPNI object
1537 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1538 * @tc_id: Traffic class selection (0-7)
1539 * @cfg: congestion notification configuration
1541 * Return: '0' on Success; error code otherwise.
1543 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1546 enum dpni_queue_type qtype,
1548 const struct dpni_congestion_notification_cfg *cfg)
1550 struct dpni_cmd_set_congestion_notification *cmd_params;
1551 struct mc_command cmd = { 0 };
1553 /* prepare command */
1554 cmd.header = mc_encode_cmd_header(
1555 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1558 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1559 cmd_params->qtype = qtype;
1560 cmd_params->tc = tc_id;
1561 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1562 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1563 cmd_params->dest_priority = cfg->dest_cfg.priority;
1564 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1565 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1566 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1567 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1568 dpni_set_field(cmd_params->type_units,
1570 cfg->dest_cfg.dest_type);
1571 dpni_set_field(cmd_params->type_units,
1575 /* send command to mc*/
1576 return mc_send_command(mc_io, &cmd);
1580 * dpni_get_congestion_notification() - Get traffic class congestion
1581 * notification configuration
1582 * @mc_io: Pointer to MC portal's I/O object
1583 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1584 * @token: Token of DPNI object
1585 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1586 * @tc_id: Traffic class selection (0-7)
1587 * @cfg: congestion notification configuration
1589 * Return: '0' on Success; error code otherwise.
1591 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1594 enum dpni_queue_type qtype,
1596 struct dpni_congestion_notification_cfg *cfg)
1598 struct dpni_rsp_get_congestion_notification *rsp_params;
1599 struct dpni_cmd_get_congestion_notification *cmd_params;
1600 struct mc_command cmd = { 0 };
1603 /* prepare command */
1604 cmd.header = mc_encode_cmd_header(
1605 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
1608 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
1609 cmd_params->qtype = qtype;
1610 cmd_params->tc = tc_id;
1612 /* send command to mc*/
1613 err = mc_send_command(mc_io, &cmd);
1617 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
1618 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
1619 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
1620 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
1621 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
1622 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
1623 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
1624 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
1625 cfg->dest_cfg.priority = rsp_params->dest_priority;
1626 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
1633 * dpni_get_api_version() - Get Data Path Network Interface API version
1634 * @mc_io: Pointer to MC portal's I/O object
1635 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1636 * @major_ver: Major version of data path network interface API
1637 * @minor_ver: Minor version of data path network interface API
1639 * Return: '0' on Success; Error code otherwise.
1641 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1643 uint16_t *major_ver,
1644 uint16_t *minor_ver)
1646 struct dpni_rsp_get_api_version *rsp_params;
1647 struct mc_command cmd = { 0 };
1650 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1654 err = mc_send_command(mc_io, &cmd);
1658 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1659 *major_ver = le16_to_cpu(rsp_params->major);
1660 *minor_ver = le16_to_cpu(rsp_params->minor);
1666 * dpni_set_queue() - Set queue parameters
1667 * @mc_io: Pointer to MC portal's I/O object
1668 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1669 * @token: Token of DPNI object
1670 * @qtype: Type of queue - all queue types are supported, although
1671 * the command is ignored for Tx
1672 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1673 * @index: Selects the specific queue out of the set allocated for the
1674 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1675 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
1676 * configuration options are set on the queue
1677 * @queue: Queue structure
1679 * Return: '0' on Success; Error code otherwise.
1681 int dpni_set_queue(struct fsl_mc_io *mc_io,
1684 enum dpni_queue_type qtype,
1688 const struct dpni_queue *queue)
1690 struct mc_command cmd = { 0 };
1691 struct dpni_cmd_set_queue *cmd_params;
1693 /* prepare command */
1694 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1697 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1698 cmd_params->qtype = qtype;
1699 cmd_params->tc = tc;
1700 cmd_params->index = index;
1701 cmd_params->options = options;
1702 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1703 cmd_params->dest_prio = queue->destination.priority;
1704 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1705 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1706 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1707 queue->destination.hold_active);
1708 cmd_params->flc = cpu_to_le64(queue->flc.value);
1709 cmd_params->user_context = cpu_to_le64(queue->user_context);
1711 /* send command to mc */
1712 return mc_send_command(mc_io, &cmd);
1716 * dpni_get_queue() - Get queue parameters
1717 * @mc_io: Pointer to MC portal's I/O object
1718 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1719 * @token: Token of DPNI object
1720 * @qtype: Type of queue - all queue types are supported
1721 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1722 * @index: Selects the specific queue out of the set allocated for the
1723 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1724 * @queue: Queue configuration structure
1725 * @qid: Queue identification
1727 * Return: '0' on Success; Error code otherwise.
1729 int dpni_get_queue(struct fsl_mc_io *mc_io,
1732 enum dpni_queue_type qtype,
1735 struct dpni_queue *queue,
1736 struct dpni_queue_id *qid)
1738 struct mc_command cmd = { 0 };
1739 struct dpni_cmd_get_queue *cmd_params;
1740 struct dpni_rsp_get_queue *rsp_params;
1743 /* prepare command */
1744 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1747 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1748 cmd_params->qtype = qtype;
1749 cmd_params->tc = tc;
1750 cmd_params->index = index;
1752 /* send command to mc */
1753 err = mc_send_command(mc_io, &cmd);
1757 /* retrieve response parameters */
1758 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
1759 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
1760 queue->destination.priority = rsp_params->dest_prio;
1761 queue->destination.type = dpni_get_field(rsp_params->flags,
1763 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
1765 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
1767 queue->flc.value = le64_to_cpu(rsp_params->flc);
1768 queue->user_context = le64_to_cpu(rsp_params->user_context);
1769 qid->fqid = le32_to_cpu(rsp_params->fqid);
1770 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
1776 * dpni_get_statistics() - Get DPNI statistics
1777 * @mc_io: Pointer to MC portal's I/O object
1778 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1779 * @token: Token of DPNI object
1780 * @page: Selects the statistics page to retrieve, see
1781 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 3.
1782 * @param: Custom parameter for some pages used to select
1783 * a certain statistic source, for example the TC.
1784 * @stat: Structure containing the statistics
1786 * Return: '0' on Success; Error code otherwise.
1788 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1793 union dpni_statistics *stat)
1795 struct mc_command cmd = { 0 };
1796 struct dpni_cmd_get_statistics *cmd_params;
1797 struct dpni_rsp_get_statistics *rsp_params;
1800 /* prepare command */
1801 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
1804 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
1805 cmd_params->page_number = page;
1806 cmd_params->param = param;
1808 /* send command to mc */
1809 err = mc_send_command(mc_io, &cmd);
1813 /* retrieve response parameters */
1814 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
1815 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
1816 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
1822 * dpni_reset_statistics() - Clears DPNI statistics
1823 * @mc_io: Pointer to MC portal's I/O object
1824 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1825 * @token: Token of DPNI object
1827 * Return: '0' on Success; Error code otherwise.
1829 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1833 struct mc_command cmd = { 0 };
1835 /* prepare command */
1836 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
1840 /* send command to mc*/
1841 return mc_send_command(mc_io, &cmd);
1845 * dpni_set_taildrop() - Set taildrop per queue or TC
1847 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
1848 * congestion notification or early drop (WRED) configuration previously applied
1851 * @mc_io: Pointer to MC portal's I/O object
1852 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1853 * @token: Token of DPNI object
1854 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in
1855 * combination with DPNI_QUEUE_RX.
1856 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
1857 * @tc: Traffic class to apply this taildrop to
1858 * @q_index: Index of the queue if the DPNI supports multiple queues for
1859 * traffic distribution.
1860 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
1861 * @taildrop: Taildrop structure
1863 * Return: '0' on Success; Error code otherwise.
1865 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1868 enum dpni_congestion_point cg_point,
1869 enum dpni_queue_type qtype,
1872 struct dpni_taildrop *taildrop)
1874 struct mc_command cmd = { 0 };
1875 struct dpni_cmd_set_taildrop *cmd_params;
1877 /* prepare command */
1878 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
1881 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
1882 cmd_params->congestion_point = cg_point;
1883 cmd_params->qtype = qtype;
1884 cmd_params->tc = tc;
1885 cmd_params->index = index;
1886 cmd_params->units = taildrop->units;
1887 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
1888 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
1889 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
1890 dpni_set_field(cmd_params->oal_hi,
1892 taildrop->oal >> DPNI_OAL_LO_SIZE);
1894 /* send command to mc */
1895 return mc_send_command(mc_io, &cmd);
1899 * dpni_get_taildrop() - Get taildrop information
1900 * @mc_io: Pointer to MC portal's I/O object
1901 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1902 * @token: Token of DPNI object
1903 * @cg_point: Congestion point
1904 * @q_type: Queue type on which the taildrop is configured.
1905 * Only Rx queues are supported for now
1906 * @tc: Traffic class to apply this taildrop to
1907 * @q_index: Index of the queue if the DPNI supports multiple queues for
1908 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
1909 * @taildrop: Taildrop structure
1911 * Return: '0' on Success; Error code otherwise.
1913 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1916 enum dpni_congestion_point cg_point,
1917 enum dpni_queue_type qtype,
1920 struct dpni_taildrop *taildrop)
1922 struct mc_command cmd = { 0 };
1923 struct dpni_cmd_get_taildrop *cmd_params;
1924 struct dpni_rsp_get_taildrop *rsp_params;
1925 uint8_t oal_lo, oal_hi;
1928 /* prepare command */
1929 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
1932 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
1933 cmd_params->congestion_point = cg_point;
1934 cmd_params->qtype = qtype;
1935 cmd_params->tc = tc;
1936 cmd_params->index = index;
1938 /* send command to mc */
1939 err = mc_send_command(mc_io, &cmd);
1943 /* retrieve response parameters */
1944 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
1945 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
1946 taildrop->units = rsp_params->units;
1947 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
1948 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
1949 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
1950 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
1952 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
1953 if (taildrop->oal >= 0x0800)
1954 taildrop->oal |= 0xF000;
1960 * dpni_set_opr() - Set Order Restoration configuration.
1961 * @mc_io: Pointer to MC portal's I/O object
1962 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1963 * @token: Token of DPNI object
1964 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1965 * @index: Selects the specific queue out of the set allocated
1966 * for the same TC. Value must be in range 0 to
1968 * @options: Configuration mode options
1969 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
1970 * @cfg: Configuration options for the OPR
1972 * Return: '0' on Success; Error code otherwise.
1974 int dpni_set_opr(struct fsl_mc_io *mc_io,
1980 struct opr_cfg *cfg)
1982 struct dpni_cmd_set_opr *cmd_params;
1983 struct mc_command cmd = { 0 };
1985 /* prepare command */
1986 cmd.header = mc_encode_cmd_header(
1990 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
1991 cmd_params->tc_id = tc;
1992 cmd_params->index = index;
1993 cmd_params->options = options;
1994 cmd_params->oloe = cfg->oloe;
1995 cmd_params->oeane = cfg->oeane;
1996 cmd_params->olws = cfg->olws;
1997 cmd_params->oa = cfg->oa;
1998 cmd_params->oprrws = cfg->oprrws;
2000 /* send command to mc*/
2001 return mc_send_command(mc_io, &cmd);
2005 * dpni_get_opr() - Retrieve Order Restoration config and query.
2006 * @mc_io: Pointer to MC portal's I/O object
2007 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2008 * @token: Token of DPNI object
2009 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2010 * @index: Selects the specific queue out of the set allocated
2011 * for the same TC. Value must be in range 0 to
2013 * @cfg: Returned OPR configuration
2014 * @qry: Returned OPR query
2016 * Return: '0' on Success; Error code otherwise.
2018 int dpni_get_opr(struct fsl_mc_io *mc_io,
2023 struct opr_cfg *cfg,
2024 struct opr_qry *qry)
2026 struct dpni_rsp_get_opr *rsp_params;
2027 struct dpni_cmd_get_opr *cmd_params;
2028 struct mc_command cmd = { 0 };
2031 /* prepare command */
2032 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2035 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2036 cmd_params->index = index;
2037 cmd_params->tc_id = tc;
2039 /* send command to mc*/
2040 err = mc_send_command(mc_io, &cmd);
2044 /* retrieve response parameters */
2045 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2046 cfg->oloe = rsp_params->oloe;
2047 cfg->oeane = rsp_params->oeane;
2048 cfg->olws = rsp_params->olws;
2049 cfg->oa = rsp_params->oa;
2050 cfg->oprrws = rsp_params->oprrws;
2051 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2052 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2053 qry->nesn = le16_to_cpu(rsp_params->nesn);
2054 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2055 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2056 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2057 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2058 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2059 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2060 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2061 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2062 qry->opr_id = le16_to_cpu(rsp_params->opr_id);