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);
128 cmd_params->num_cgs = cfg->num_cgs;
130 /* send command to mc*/
131 err = mc_send_command(mc_io, &cmd);
135 /* retrieve response parameters */
136 *obj_id = mc_cmd_read_object_id(&cmd);
142 * dpni_destroy() - Destroy the DPNI object and release all its resources.
143 * @mc_io: Pointer to MC portal's I/O object
144 * @dprc_token: Parent container token; '0' for default container
145 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
146 * @object_id: The object id; it must be a valid id within the container that
147 * created this object;
149 * The function accepts the authentication token of the parent container that
150 * created the object (not the one that currently owns the object). The object
151 * is searched within parent using the provided 'object_id'.
152 * All tokens to the object must be closed before calling destroy.
154 * Return: '0' on Success; error code otherwise.
156 int dpni_destroy(struct fsl_mc_io *mc_io,
161 struct dpni_cmd_destroy *cmd_params;
162 struct mc_command cmd = { 0 };
164 /* prepare command */
165 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
168 /* set object id to destroy */
169 cmd_params = (struct dpni_cmd_destroy *)cmd.params;
170 cmd_params->dpsw_id = cpu_to_le32(object_id);
172 /* send command to mc*/
173 return mc_send_command(mc_io, &cmd);
177 * dpni_set_pools() - Set buffer pools configuration
178 * @mc_io: Pointer to MC portal's I/O object
179 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
180 * @token: Token of DPNI object
181 * @cfg: Buffer pools configuration
183 * mandatory for DPNI operation
184 * warning:Allowed only when DPNI is disabled
186 * Return: '0' on Success; Error code otherwise.
188 int dpni_set_pools(struct fsl_mc_io *mc_io,
191 const struct dpni_pools_cfg *cfg)
193 struct mc_command cmd = { 0 };
194 struct dpni_cmd_set_pools *cmd_params;
197 /* prepare command */
198 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
201 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
202 cmd_params->num_dpbp = cfg->num_dpbp;
203 for (i = 0; i < cmd_params->num_dpbp; i++) {
204 cmd_params->pool[i].dpbp_id =
205 cpu_to_le16(cfg->pools[i].dpbp_id);
206 cmd_params->pool[i].priority_mask =
207 cfg->pools[i].priority_mask;
208 cmd_params->buffer_size[i] =
209 cpu_to_le16(cfg->pools[i].buffer_size);
210 cmd_params->backup_pool_mask |=
211 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
214 /* send command to mc*/
215 return mc_send_command(mc_io, &cmd);
219 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
220 * @mc_io: Pointer to MC portal's I/O object
221 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
222 * @token: Token of DPNI object
224 * Return: '0' on Success; Error code otherwise.
226 int dpni_enable(struct fsl_mc_io *mc_io,
230 struct mc_command cmd = { 0 };
232 /* prepare command */
233 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
237 /* send command to mc*/
238 return mc_send_command(mc_io, &cmd);
242 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
243 * @mc_io: Pointer to MC portal's I/O object
244 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
245 * @token: Token of DPNI object
247 * Return: '0' on Success; Error code otherwise.
249 int dpni_disable(struct fsl_mc_io *mc_io,
253 struct mc_command cmd = { 0 };
255 /* prepare command */
256 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
260 /* send command to mc*/
261 return mc_send_command(mc_io, &cmd);
265 * dpni_is_enabled() - Check if the DPNI is enabled.
266 * @mc_io: Pointer to MC portal's I/O object
267 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
268 * @token: Token of DPNI object
269 * @en: Returns '1' if object is enabled; '0' otherwise
271 * Return: '0' on Success; Error code otherwise.
273 int dpni_is_enabled(struct fsl_mc_io *mc_io,
278 struct mc_command cmd = { 0 };
279 struct dpni_rsp_is_enabled *rsp_params;
282 /* prepare command */
283 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
287 /* send command to mc*/
288 err = mc_send_command(mc_io, &cmd);
292 /* retrieve response parameters */
293 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
294 *en = dpni_get_field(rsp_params->enabled, ENABLE);
300 * dpni_reset() - Reset the DPNI, returns the object to initial state.
301 * @mc_io: Pointer to MC portal's I/O object
302 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
303 * @token: Token of DPNI object
305 * Return: '0' on Success; Error code otherwise.
307 int dpni_reset(struct fsl_mc_io *mc_io,
311 struct mc_command cmd = { 0 };
313 /* prepare command */
314 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
318 /* send command to mc*/
319 return mc_send_command(mc_io, &cmd);
323 * dpni_set_irq_enable() - Set overall interrupt state.
324 * @mc_io: Pointer to MC portal's I/O object
325 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
326 * @token: Token of DPNI object
327 * @irq_index: The interrupt index to configure
328 * @en: Interrupt state: - enable = 1, disable = 0
330 * Allows GPP software to control when interrupts are generated.
331 * Each interrupt can have up to 32 causes. The enable/disable control's the
332 * overall interrupt state. if the interrupt is disabled no causes will cause
335 * Return: '0' on Success; Error code otherwise.
337 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
343 struct mc_command cmd = { 0 };
344 struct dpni_cmd_set_irq_enable *cmd_params;
346 /* prepare command */
347 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
350 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
351 dpni_set_field(cmd_params->enable, ENABLE, en);
352 cmd_params->irq_index = irq_index;
354 /* send command to mc*/
355 return mc_send_command(mc_io, &cmd);
359 * dpni_get_irq_enable() - Get overall interrupt state
360 * @mc_io: Pointer to MC portal's I/O object
361 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
362 * @token: Token of DPNI object
363 * @irq_index: The interrupt index to configure
364 * @en: Returned interrupt state - enable = 1, disable = 0
366 * Return: '0' on Success; Error code otherwise.
368 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
374 struct mc_command cmd = { 0 };
375 struct dpni_cmd_get_irq_enable *cmd_params;
376 struct dpni_rsp_get_irq_enable *rsp_params;
380 /* prepare command */
381 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
384 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
385 cmd_params->irq_index = irq_index;
387 /* send command to mc*/
388 err = mc_send_command(mc_io, &cmd);
392 /* retrieve response parameters */
393 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
394 *en = dpni_get_field(rsp_params->enabled, ENABLE);
400 * dpni_set_irq_mask() - Set interrupt mask.
401 * @mc_io: Pointer to MC portal's I/O object
402 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
403 * @token: Token of DPNI object
404 * @irq_index: The interrupt index to configure
405 * @mask: Event mask to trigger interrupt;
408 * 1 = consider event for asserting IRQ
410 * Every interrupt can have up to 32 causes and the interrupt model supports
411 * masking/unmasking each cause independently
413 * Return: '0' on Success; Error code otherwise.
415 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
421 struct mc_command cmd = { 0 };
422 struct dpni_cmd_set_irq_mask *cmd_params;
424 /* prepare command */
425 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
428 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
429 cmd_params->mask = cpu_to_le32(mask);
430 cmd_params->irq_index = irq_index;
432 /* send command to mc*/
433 return mc_send_command(mc_io, &cmd);
437 * dpni_get_irq_mask() - Get interrupt mask.
438 * @mc_io: Pointer to MC portal's I/O object
439 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
440 * @token: Token of DPNI object
441 * @irq_index: The interrupt index to configure
442 * @mask: Returned event mask to trigger interrupt
444 * Every interrupt can have up to 32 causes and the interrupt model supports
445 * masking/unmasking each cause independently
447 * Return: '0' on Success; Error code otherwise.
449 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
455 struct mc_command cmd = { 0 };
456 struct dpni_cmd_get_irq_mask *cmd_params;
457 struct dpni_rsp_get_irq_mask *rsp_params;
460 /* prepare command */
461 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
464 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
465 cmd_params->irq_index = irq_index;
467 /* send command to mc*/
468 err = mc_send_command(mc_io, &cmd);
472 /* retrieve response parameters */
473 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
474 *mask = le32_to_cpu(rsp_params->mask);
480 * dpni_get_irq_status() - Get the current status of any pending interrupts.
481 * @mc_io: Pointer to MC portal's I/O object
482 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
483 * @token: Token of DPNI object
484 * @irq_index: The interrupt index to configure
485 * @status: Returned interrupts status - one bit per cause:
486 * 0 = no interrupt pending
487 * 1 = interrupt pending
489 * Return: '0' on Success; Error code otherwise.
491 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
497 struct mc_command cmd = { 0 };
498 struct dpni_cmd_get_irq_status *cmd_params;
499 struct dpni_rsp_get_irq_status *rsp_params;
502 /* prepare command */
503 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
506 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
507 cmd_params->status = cpu_to_le32(*status);
508 cmd_params->irq_index = irq_index;
510 /* send command to mc*/
511 err = mc_send_command(mc_io, &cmd);
515 /* retrieve response parameters */
516 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
517 *status = le32_to_cpu(rsp_params->status);
523 * dpni_clear_irq_status() - Clear a pending interrupt's status
524 * @mc_io: Pointer to MC portal's I/O object
525 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
526 * @token: Token of DPNI object
527 * @irq_index: The interrupt index to configure
528 * @status: bits to clear (W1C) - one bit per cause:
530 * 1 = clear status bit
532 * Return: '0' on Success; Error code otherwise.
534 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
540 struct mc_command cmd = { 0 };
541 struct dpni_cmd_clear_irq_status *cmd_params;
543 /* prepare command */
544 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
547 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
548 cmd_params->irq_index = irq_index;
549 cmd_params->status = cpu_to_le32(status);
551 /* send command to mc*/
552 return mc_send_command(mc_io, &cmd);
556 * dpni_get_attributes() - Retrieve DPNI attributes.
557 * @mc_io: Pointer to MC portal's I/O object
558 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
559 * @token: Token of DPNI object
560 * @attr: Object's attributes
562 * Return: '0' on Success; Error code otherwise.
564 int dpni_get_attributes(struct fsl_mc_io *mc_io,
567 struct dpni_attr *attr)
569 struct mc_command cmd = { 0 };
570 struct dpni_rsp_get_attr *rsp_params;
574 /* prepare command */
575 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
579 /* send command to mc*/
580 err = mc_send_command(mc_io, &cmd);
584 /* retrieve response parameters */
585 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
586 attr->options = le32_to_cpu(rsp_params->options);
587 attr->num_queues = rsp_params->num_queues;
588 attr->num_rx_tcs = rsp_params->num_rx_tcs;
589 attr->num_tx_tcs = rsp_params->num_tx_tcs;
590 attr->mac_filter_entries = rsp_params->mac_filter_entries;
591 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
592 attr->qos_entries = rsp_params->qos_entries;
593 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
594 attr->qos_key_size = rsp_params->qos_key_size;
595 attr->fs_key_size = rsp_params->fs_key_size;
596 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
597 attr->num_cgs = rsp_params->num_cgs;
603 * dpni_set_errors_behavior() - Set errors behavior
604 * @mc_io: Pointer to MC portal's I/O object
605 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
606 * @token: Token of DPNI object
607 * @cfg: Errors configuration
609 * This function may be called numerous times with different
612 * Return: '0' on Success; Error code otherwise.
614 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
617 struct dpni_error_cfg *cfg)
619 struct mc_command cmd = { 0 };
620 struct dpni_cmd_set_errors_behavior *cmd_params;
622 /* prepare command */
623 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
626 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
627 cmd_params->errors = cpu_to_le32(cfg->errors);
628 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
629 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
631 /* send command to mc*/
632 return mc_send_command(mc_io, &cmd);
636 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
637 * @mc_io: Pointer to MC portal's I/O object
638 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
639 * @token: Token of DPNI object
640 * @qtype: Type of queue to retrieve configuration for
641 * @layout: Returns buffer layout attributes
643 * Return: '0' on Success; Error code otherwise.
645 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
648 enum dpni_queue_type qtype,
649 struct dpni_buffer_layout *layout)
651 struct mc_command cmd = { 0 };
652 struct dpni_cmd_get_buffer_layout *cmd_params;
653 struct dpni_rsp_get_buffer_layout *rsp_params;
656 /* prepare command */
657 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
660 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
661 cmd_params->qtype = qtype;
663 /* send command to mc*/
664 err = mc_send_command(mc_io, &cmd);
668 /* retrieve response parameters */
669 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
670 layout->pass_timestamp =
671 (int)dpni_get_field(rsp_params->flags, PASS_TS);
672 layout->pass_parser_result =
673 (int)dpni_get_field(rsp_params->flags, PASS_PR);
674 layout->pass_frame_status =
675 (int)dpni_get_field(rsp_params->flags, PASS_FS);
676 layout->pass_sw_opaque =
677 (int)dpni_get_field(rsp_params->flags, PASS_SWO);
678 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
679 layout->data_align = le16_to_cpu(rsp_params->data_align);
680 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
681 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
687 * dpni_set_buffer_layout() - Set buffer layout configuration.
688 * @mc_io: Pointer to MC portal's I/O object
689 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
690 * @token: Token of DPNI object
691 * @qtype: Type of queue this configuration applies to
692 * @layout: Buffer layout configuration
694 * Return: '0' on Success; Error code otherwise.
696 * @warning Allowed only when DPNI is disabled
698 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
701 enum dpni_queue_type qtype,
702 const struct dpni_buffer_layout *layout)
704 struct mc_command cmd = { 0 };
705 struct dpni_cmd_set_buffer_layout *cmd_params;
707 /* prepare command */
708 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
711 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
712 cmd_params->qtype = qtype;
713 cmd_params->options = cpu_to_le16((uint16_t)layout->options);
714 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
715 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
716 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
717 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
718 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
719 cmd_params->data_align = cpu_to_le16(layout->data_align);
720 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
721 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
723 /* send command to mc*/
724 return mc_send_command(mc_io, &cmd);
728 * dpni_set_offload() - Set DPNI offload configuration.
729 * @mc_io: Pointer to MC portal's I/O object
730 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
731 * @token: Token of DPNI object
732 * @type: Type of DPNI offload
733 * @config: Offload configuration.
734 * For checksum offloads, non-zero value enables the offload
736 * Return: '0' on Success; Error code otherwise.
738 * @warning Allowed only when DPNI is disabled
741 int dpni_set_offload(struct fsl_mc_io *mc_io,
744 enum dpni_offload type,
747 struct mc_command cmd = { 0 };
748 struct dpni_cmd_set_offload *cmd_params;
750 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
753 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
754 cmd_params->dpni_offload = type;
755 cmd_params->config = cpu_to_le32(config);
757 return mc_send_command(mc_io, &cmd);
761 * dpni_get_offload() - Get DPNI offload configuration.
762 * @mc_io: Pointer to MC portal's I/O object
763 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
764 * @token: Token of DPNI object
765 * @type: Type of DPNI offload
766 * @config: Offload configuration.
767 * For checksum offloads, a value of 1 indicates that the
768 * offload is enabled.
770 * Return: '0' on Success; Error code otherwise.
772 * @warning Allowed only when DPNI is disabled
774 int dpni_get_offload(struct fsl_mc_io *mc_io,
777 enum dpni_offload type,
780 struct mc_command cmd = { 0 };
781 struct dpni_cmd_get_offload *cmd_params;
782 struct dpni_rsp_get_offload *rsp_params;
785 /* prepare command */
786 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
789 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
790 cmd_params->dpni_offload = type;
792 /* send command to mc*/
793 err = mc_send_command(mc_io, &cmd);
797 /* retrieve response parameters */
798 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
799 *config = le32_to_cpu(rsp_params->config);
805 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
806 * for enqueue operations
807 * @mc_io: Pointer to MC portal's I/O object
808 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
809 * @token: Token of DPNI object
810 * @qtype: Type of queue to receive QDID for
811 * @qdid: Returned virtual QDID value that should be used as an argument
812 * in all enqueue operations
814 * Return: '0' on Success; Error code otherwise.
816 int dpni_get_qdid(struct fsl_mc_io *mc_io,
819 enum dpni_queue_type qtype,
822 struct mc_command cmd = { 0 };
823 struct dpni_cmd_get_qdid *cmd_params;
824 struct dpni_rsp_get_qdid *rsp_params;
827 /* prepare command */
828 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
831 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
832 cmd_params->qtype = qtype;
834 /* send command to mc*/
835 err = mc_send_command(mc_io, &cmd);
839 /* retrieve response parameters */
840 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
841 *qdid = le16_to_cpu(rsp_params->qdid);
847 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
848 * @mc_io: Pointer to MC portal's I/O object
849 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
850 * @token: Token of DPNI object
851 * @data_offset: Tx data offset (from start of buffer)
853 * Return: '0' on Success; Error code otherwise.
855 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
858 uint16_t *data_offset)
860 struct mc_command cmd = { 0 };
861 struct dpni_rsp_get_tx_data_offset *rsp_params;
864 /* prepare command */
865 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
869 /* send command to mc*/
870 err = mc_send_command(mc_io, &cmd);
874 /* retrieve response parameters */
875 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
876 *data_offset = le16_to_cpu(rsp_params->data_offset);
882 * dpni_set_link_cfg() - set the link configuration.
883 * @mc_io: Pointer to MC portal's I/O object
884 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
885 * @token: Token of DPNI object
886 * @cfg: Link configuration
888 * Return: '0' on Success; Error code otherwise.
890 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
893 const struct dpni_link_cfg *cfg)
895 struct mc_command cmd = { 0 };
896 struct dpni_cmd_set_link_cfg *cmd_params;
898 /* prepare command */
899 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
902 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
903 cmd_params->rate = cpu_to_le32(cfg->rate);
904 cmd_params->options = cpu_to_le64(cfg->options);
905 cmd_params->advertising = cpu_to_le64(cfg->advertising);
907 /* send command to mc*/
908 return mc_send_command(mc_io, &cmd);
912 * dpni_get_link_state() - Return the link state (either up or down)
913 * @mc_io: Pointer to MC portal's I/O object
914 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
915 * @token: Token of DPNI object
916 * @state: Returned link state;
918 * Return: '0' on Success; Error code otherwise.
920 int dpni_get_link_state(struct fsl_mc_io *mc_io,
923 struct dpni_link_state *state)
925 struct mc_command cmd = { 0 };
926 struct dpni_rsp_get_link_state *rsp_params;
929 /* prepare command */
930 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
934 /* send command to mc*/
935 err = mc_send_command(mc_io, &cmd);
939 /* retrieve response parameters */
940 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
941 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
942 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
943 state->rate = le32_to_cpu(rsp_params->rate);
944 state->options = le64_to_cpu(rsp_params->options);
945 state->supported = le64_to_cpu(rsp_params->supported);
946 state->advertising = le64_to_cpu(rsp_params->advertising);
952 * dpni_set_max_frame_length() - Set the maximum received frame length.
953 * @mc_io: Pointer to MC portal's I/O object
954 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
955 * @token: Token of DPNI object
956 * @max_frame_length: Maximum received frame length (in bytes);
957 * frame is discarded if its length exceeds this value
959 * Return: '0' on Success; Error code otherwise.
961 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
964 uint16_t max_frame_length)
966 struct mc_command cmd = { 0 };
967 struct dpni_cmd_set_max_frame_length *cmd_params;
969 /* prepare command */
970 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
973 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
974 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
976 /* send command to mc*/
977 return mc_send_command(mc_io, &cmd);
981 * dpni_get_max_frame_length() - Get the maximum received frame length.
982 * @mc_io: Pointer to MC portal's I/O object
983 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
984 * @token: Token of DPNI object
985 * @max_frame_length: Maximum received frame length (in bytes);
986 * frame is discarded if its length exceeds this value
988 * Return: '0' on Success; Error code otherwise.
990 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
993 uint16_t *max_frame_length)
995 struct mc_command cmd = { 0 };
996 struct dpni_rsp_get_max_frame_length *rsp_params;
999 /* prepare command */
1000 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1004 /* send command to mc*/
1005 err = mc_send_command(mc_io, &cmd);
1009 /* retrieve response parameters */
1010 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1011 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1017 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1018 * @mc_io: Pointer to MC portal's I/O object
1019 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1020 * @token: Token of DPNI object
1021 * @en: Set to '1' to enable; '0' to disable
1023 * Return: '0' on Success; Error code otherwise.
1025 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1030 struct mc_command cmd = { 0 };
1031 struct dpni_cmd_set_multicast_promisc *cmd_params;
1033 /* prepare command */
1034 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1037 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1038 dpni_set_field(cmd_params->enable, ENABLE, en);
1040 /* send command to mc*/
1041 return mc_send_command(mc_io, &cmd);
1045 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1046 * @mc_io: Pointer to MC portal's I/O object
1047 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1048 * @token: Token of DPNI object
1049 * @en: Returns '1' if enabled; '0' otherwise
1051 * Return: '0' on Success; Error code otherwise.
1053 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1058 struct mc_command cmd = { 0 };
1059 struct dpni_rsp_get_multicast_promisc *rsp_params;
1062 /* prepare command */
1063 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1067 /* send command to mc*/
1068 err = mc_send_command(mc_io, &cmd);
1072 /* retrieve response parameters */
1073 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1074 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1080 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1081 * @mc_io: Pointer to MC portal's I/O object
1082 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1083 * @token: Token of DPNI object
1084 * @en: Set to '1' to enable; '0' to disable
1086 * Return: '0' on Success; Error code otherwise.
1088 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1093 struct mc_command cmd = { 0 };
1094 struct dpni_cmd_set_unicast_promisc *cmd_params;
1096 /* prepare command */
1097 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1100 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1101 dpni_set_field(cmd_params->enable, ENABLE, en);
1103 /* send command to mc*/
1104 return mc_send_command(mc_io, &cmd);
1108 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1109 * @mc_io: Pointer to MC portal's I/O object
1110 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1111 * @token: Token of DPNI object
1112 * @en: Returns '1' if enabled; '0' otherwise
1114 * Return: '0' on Success; Error code otherwise.
1116 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1121 struct mc_command cmd = { 0 };
1122 struct dpni_rsp_get_unicast_promisc *rsp_params;
1125 /* prepare command */
1126 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1130 /* send command to mc*/
1131 err = mc_send_command(mc_io, &cmd);
1135 /* retrieve response parameters */
1136 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1137 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1143 * dpni_set_primary_mac_addr() - Set the primary MAC address
1144 * @mc_io: Pointer to MC portal's I/O object
1145 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1146 * @token: Token of DPNI object
1147 * @mac_addr: MAC address to set as primary address
1149 * Return: '0' on Success; Error code otherwise.
1151 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1154 const uint8_t mac_addr[6])
1156 struct mc_command cmd = { 0 };
1157 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1160 /* prepare command */
1161 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1164 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1165 for (i = 0; i < 6; i++)
1166 cmd_params->mac_addr[i] = mac_addr[5 - i];
1168 /* send command to mc*/
1169 return mc_send_command(mc_io, &cmd);
1173 * dpni_get_primary_mac_addr() - Get the primary MAC address
1174 * @mc_io: Pointer to MC portal's I/O object
1175 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1176 * @token: Token of DPNI object
1177 * @mac_addr: Returned MAC address
1179 * Return: '0' on Success; Error code otherwise.
1181 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1184 uint8_t mac_addr[6])
1186 struct mc_command cmd = { 0 };
1187 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1190 /* prepare command */
1191 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1195 /* send command to mc*/
1196 err = mc_send_command(mc_io, &cmd);
1200 /* retrieve response parameters */
1201 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1202 for (i = 0; i < 6; i++)
1203 mac_addr[5 - i] = rsp_params->mac_addr[i];
1209 * dpni_add_mac_addr() - Add MAC address filter
1210 * @mc_io: Pointer to MC portal's I/O object
1211 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1212 * @token: Token of DPNI object
1213 * @mac_addr: MAC address to add
1215 * Return: '0' on Success; Error code otherwise.
1217 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1220 const uint8_t mac_addr[6])
1222 struct mc_command cmd = { 0 };
1223 struct dpni_cmd_add_mac_addr *cmd_params;
1226 /* prepare command */
1227 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1230 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1231 for (i = 0; i < 6; i++)
1232 cmd_params->mac_addr[i] = mac_addr[5 - i];
1234 /* send command to mc*/
1235 return mc_send_command(mc_io, &cmd);
1239 * dpni_remove_mac_addr() - Remove MAC address filter
1240 * @mc_io: Pointer to MC portal's I/O object
1241 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1242 * @token: Token of DPNI object
1243 * @mac_addr: MAC address to remove
1245 * Return: '0' on Success; Error code otherwise.
1247 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1250 const uint8_t mac_addr[6])
1252 struct mc_command cmd = { 0 };
1253 struct dpni_cmd_remove_mac_addr *cmd_params;
1256 /* prepare command */
1257 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1260 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1261 for (i = 0; i < 6; i++)
1262 cmd_params->mac_addr[i] = mac_addr[5 - i];
1264 /* send command to mc*/
1265 return mc_send_command(mc_io, &cmd);
1269 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1270 * @mc_io: Pointer to MC portal's I/O object
1271 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1272 * @token: Token of DPNI object
1273 * @unicast: Set to '1' to clear unicast addresses
1274 * @multicast: Set to '1' to clear multicast addresses
1276 * The primary MAC address is not cleared by this operation.
1278 * Return: '0' on Success; Error code otherwise.
1280 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1286 struct mc_command cmd = { 0 };
1287 struct dpni_cmd_clear_mac_filters *cmd_params;
1289 /* prepare command */
1290 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1293 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1294 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1295 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1297 /* send command to mc*/
1298 return mc_send_command(mc_io, &cmd);
1302 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1303 * port the DPNI is attached to
1304 * @mc_io: Pointer to MC portal's I/O object
1305 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1306 * @token: Token of DPNI object
1307 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1309 * The primary MAC address is not cleared by this operation.
1311 * Return: '0' on Success; Error code otherwise.
1313 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1316 uint8_t mac_addr[6])
1318 struct mc_command cmd = { 0 };
1319 struct dpni_rsp_get_port_mac_addr *rsp_params;
1322 /* prepare command */
1323 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1327 /* send command to mc*/
1328 err = mc_send_command(mc_io, &cmd);
1332 /* retrieve response parameters */
1333 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1334 for (i = 0; i < 6; i++)
1335 mac_addr[5 - i] = rsp_params->mac_addr[i];
1341 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1342 * @mc_io: Pointer to MC portal's I/O object
1343 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1344 * @token: Token of DPNI object
1345 * @en: Set to '1' to enable; '0' to disable
1347 * Return: '0' on Success; Error code otherwise.
1349 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1354 struct dpni_cmd_enable_vlan_filter *cmd_params;
1355 struct mc_command cmd = { 0 };
1357 /* prepare command */
1358 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1361 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1362 dpni_set_field(cmd_params->en, ENABLE, en);
1364 /* send command to mc*/
1365 return mc_send_command(mc_io, &cmd);
1369 * dpni_add_vlan_id() - Add VLAN ID filter
1370 * @mc_io: Pointer to MC portal's I/O object
1371 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1372 * @token: Token of DPNI object
1373 * @vlan_id: VLAN ID to add
1375 * Return: '0' on Success; Error code otherwise.
1377 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1382 struct dpni_cmd_vlan_id *cmd_params;
1383 struct mc_command cmd = { 0 };
1385 /* prepare command */
1386 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1389 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1390 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1392 /* send command to mc*/
1393 return mc_send_command(mc_io, &cmd);
1397 * dpni_remove_vlan_id() - Remove VLAN ID filter
1398 * @mc_io: Pointer to MC portal's I/O object
1399 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1400 * @token: Token of DPNI object
1401 * @vlan_id: VLAN ID to remove
1403 * Return: '0' on Success; Error code otherwise.
1405 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1410 struct dpni_cmd_vlan_id *cmd_params;
1411 struct mc_command cmd = { 0 };
1413 /* prepare command */
1414 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1417 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1418 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1420 /* send command to mc*/
1421 return mc_send_command(mc_io, &cmd);
1425 * dpni_clear_vlan_filters() - Clear all VLAN filters
1426 * @mc_io: Pointer to MC portal's I/O object
1427 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1428 * @token: Token of DPNI object
1430 * Return: '0' on Success; Error code otherwise.
1432 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1436 struct mc_command cmd = { 0 };
1438 /* prepare command */
1439 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1443 /* send command to mc*/
1444 return mc_send_command(mc_io, &cmd);
1448 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1449 * @mc_io: Pointer to MC portal's I/O object
1450 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1451 * @token: Token of DPNI object
1452 * @tc_id: Traffic class selection (0-7)
1453 * @cfg: Traffic class distribution configuration
1455 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1456 * first to prepare the key_cfg_iova parameter
1458 * Return: '0' on Success; error code otherwise.
1460 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1464 const struct dpni_rx_tc_dist_cfg *cfg)
1466 struct mc_command cmd = { 0 };
1467 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1469 /* prepare command */
1470 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1473 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1474 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1475 cmd_params->tc_id = tc_id;
1476 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1477 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1478 dpni_set_field(cmd_params->flags,
1481 dpni_set_field(cmd_params->flags,
1483 cfg->fs_cfg.miss_action);
1484 dpni_set_field(cmd_params->keep_hash_key,
1486 cfg->fs_cfg.keep_hash_key);
1487 dpni_set_field(cmd_params->keep_hash_key,
1489 cfg->fs_cfg.keep_entries);
1491 /* send command to mc*/
1492 return mc_send_command(mc_io, &cmd);
1496 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1497 * @mc_io: Pointer to MC portal's I/O object
1498 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1499 * @token: Token of DPNI object
1500 * @mode: Tx confirmation mode
1502 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1503 * selected at DPNI creation.
1504 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1505 * transmit confirmation (including the private confirmation queues), regardless
1506 * of previous settings; Note that in this case, Tx error frames are still
1507 * enqueued to the general transmit errors queue.
1508 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1509 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1510 * command will be ignored.
1512 * Return: '0' on Success; Error code otherwise.
1514 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1517 enum dpni_confirmation_mode mode)
1519 struct dpni_tx_confirmation_mode *cmd_params;
1520 struct mc_command cmd = { 0 };
1522 /* prepare command */
1523 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1526 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1527 cmd_params->confirmation_mode = mode;
1529 /* send command to mc*/
1530 return mc_send_command(mc_io, &cmd);
1534 * dpni_set_qos_table() - Set QoS mapping table
1535 * @mc_io: Pointer to MC portal's I/O object
1536 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1537 * @token: Token of DPNI object
1538 * @cfg: QoS table configuration
1540 * This function and all QoS-related functions require that
1541 *'max_tcs > 1' was set at DPNI creation.
1543 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1544 * prepare the key_cfg_iova parameter
1546 * Return: '0' on Success; Error code otherwise.
1548 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1551 const struct dpni_qos_tbl_cfg *cfg)
1553 struct dpni_cmd_set_qos_table *cmd_params;
1554 struct mc_command cmd = { 0 };
1556 /* prepare command */
1557 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1560 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1561 cmd_params->default_tc = cfg->default_tc;
1562 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1563 dpni_set_field(cmd_params->discard_on_miss,
1565 cfg->discard_on_miss);
1566 dpni_set_field(cmd_params->discard_on_miss,
1570 /* send command to mc*/
1571 return mc_send_command(mc_io, &cmd);
1575 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1576 * @mc_io: Pointer to MC portal's I/O object
1577 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1578 * @token: Token of DPNI object
1579 * @cfg: QoS rule to add
1580 * @tc_id: Traffic class selection (0-7)
1581 * @index: Location in the QoS table where to insert the entry.
1582 * Only relevant if MASKING is enabled for QoS classification on
1583 * this DPNI, it is ignored for exact match.
1585 * Return: '0' on Success; Error code otherwise.
1587 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1590 const struct dpni_rule_cfg *cfg,
1594 struct dpni_cmd_add_qos_entry *cmd_params;
1595 struct mc_command cmd = { 0 };
1597 /* prepare command */
1598 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1601 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1602 cmd_params->tc_id = tc_id;
1603 cmd_params->key_size = cfg->key_size;
1604 cmd_params->index = cpu_to_le16(index);
1605 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1606 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1608 /* send command to mc*/
1609 return mc_send_command(mc_io, &cmd);
1613 * dpni_remove_qos_entry() - Remove QoS mapping entry
1614 * @mc_io: Pointer to MC portal's I/O object
1615 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1616 * @token: Token of DPNI object
1617 * @cfg: QoS rule to remove
1619 * Return: '0' on Success; Error code otherwise.
1621 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1624 const struct dpni_rule_cfg *cfg)
1626 struct dpni_cmd_remove_qos_entry *cmd_params;
1627 struct mc_command cmd = { 0 };
1629 /* prepare command */
1630 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1633 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1634 cmd_params->key_size = cfg->key_size;
1635 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1636 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1638 /* send command to mc*/
1639 return mc_send_command(mc_io, &cmd);
1643 * dpni_clear_qos_table() - Clear all QoS mapping entries
1644 * @mc_io: Pointer to MC portal's I/O object
1645 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1646 * @token: Token of DPNI object
1648 * Following this function call, all frames are directed to
1649 * the default traffic class (0)
1651 * Return: '0' on Success; Error code otherwise.
1653 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1657 struct mc_command cmd = { 0 };
1659 /* prepare command */
1660 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1664 /* send command to mc*/
1665 return mc_send_command(mc_io, &cmd);
1669 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1670 * (to select a flow ID)
1671 * @mc_io: Pointer to MC portal's I/O object
1672 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1673 * @token: Token of DPNI object
1674 * @tc_id: Traffic class selection (0-7)
1675 * @index: Location in the QoS table where to insert the entry.
1676 * Only relevant if MASKING is enabled for QoS classification
1677 * on this DPNI, it is ignored for exact match.
1678 * @cfg: Flow steering rule to add
1679 * @action: Action to be taken as result of a classification hit
1681 * Return: '0' on Success; Error code otherwise.
1683 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1688 const struct dpni_rule_cfg *cfg,
1689 const struct dpni_fs_action_cfg *action)
1691 struct dpni_cmd_add_fs_entry *cmd_params;
1692 struct mc_command cmd = { 0 };
1694 /* prepare command */
1695 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1698 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1699 cmd_params->tc_id = tc_id;
1700 cmd_params->key_size = cfg->key_size;
1701 cmd_params->index = cpu_to_le16(index);
1702 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1703 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1704 cmd_params->options = cpu_to_le16(action->options);
1705 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1706 cmd_params->flc = cpu_to_le64(action->flc);
1708 /* send command to mc*/
1709 return mc_send_command(mc_io, &cmd);
1713 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1715 * @mc_io: Pointer to MC portal's I/O object
1716 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1717 * @token: Token of DPNI object
1718 * @tc_id: Traffic class selection (0-7)
1719 * @cfg: Flow steering rule to remove
1721 * Return: '0' on Success; Error code otherwise.
1723 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1727 const struct dpni_rule_cfg *cfg)
1729 struct dpni_cmd_remove_fs_entry *cmd_params;
1730 struct mc_command cmd = { 0 };
1732 /* prepare command */
1733 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1736 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1737 cmd_params->tc_id = tc_id;
1738 cmd_params->key_size = cfg->key_size;
1739 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1740 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1742 /* send command to mc*/
1743 return mc_send_command(mc_io, &cmd);
1747 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1749 * @mc_io: Pointer to MC portal's I/O object
1750 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1751 * @token: Token of DPNI object
1752 * @tc_id: Traffic class selection (0-7)
1754 * Return: '0' on Success; Error code otherwise.
1756 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1761 struct dpni_cmd_clear_fs_entries *cmd_params;
1762 struct mc_command cmd = { 0 };
1764 /* prepare command */
1765 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1768 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1769 cmd_params->tc_id = tc_id;
1771 /* send command to mc*/
1772 return mc_send_command(mc_io, &cmd);
1776 * dpni_set_congestion_notification() - Set traffic class congestion
1777 * notification configuration
1778 * @mc_io: Pointer to MC portal's I/O object
1779 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1780 * @token: Token of DPNI object
1781 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1782 * @tc_id: Traffic class selection (0-7)
1783 * @cfg: congestion notification configuration
1785 * Return: '0' on Success; error code otherwise.
1787 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1790 enum dpni_queue_type qtype,
1792 const struct dpni_congestion_notification_cfg *cfg)
1794 struct dpni_cmd_set_congestion_notification *cmd_params;
1795 struct mc_command cmd = { 0 };
1797 /* prepare command */
1798 cmd.header = mc_encode_cmd_header(
1799 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1802 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1803 cmd_params->qtype = qtype;
1804 cmd_params->tc = tc_id;
1805 cmd_params->congestion_point = cfg->cg_point;
1806 cmd_params->cgid = (uint8_t)cfg->cgid;
1807 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1808 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1809 cmd_params->dest_priority = cfg->dest_cfg.priority;
1810 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1811 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1812 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1813 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1814 dpni_set_field(cmd_params->type_units,
1816 cfg->dest_cfg.dest_type);
1817 dpni_set_field(cmd_params->type_units,
1821 /* send command to mc*/
1822 return mc_send_command(mc_io, &cmd);
1826 * dpni_get_congestion_notification() - Get traffic class congestion
1827 * notification configuration
1828 * @mc_io: Pointer to MC portal's I/O object
1829 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1830 * @token: Token of DPNI object
1831 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1832 * @tc_id: Traffic class selection (0-7)
1833 * @cfg: congestion notification configuration
1835 * Return: '0' on Success; error code otherwise.
1837 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1840 enum dpni_queue_type qtype,
1842 struct dpni_congestion_notification_cfg *cfg)
1844 struct dpni_rsp_get_congestion_notification *rsp_params;
1845 struct dpni_cmd_get_congestion_notification *cmd_params;
1846 struct mc_command cmd = { 0 };
1849 /* prepare command */
1850 cmd.header = mc_encode_cmd_header(
1851 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
1854 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
1855 cmd_params->qtype = qtype;
1856 cmd_params->tc = tc_id;
1857 cmd_params->congestion_point = cfg->cg_point;
1858 cmd_params->cgid = cfg->cgid;
1860 /* send command to mc*/
1861 err = mc_send_command(mc_io, &cmd);
1865 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
1866 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
1867 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
1868 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
1869 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
1870 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
1871 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
1872 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
1873 cfg->dest_cfg.priority = rsp_params->dest_priority;
1874 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
1881 * dpni_get_api_version() - Get Data Path Network Interface API version
1882 * @mc_io: Pointer to MC portal's I/O object
1883 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1884 * @major_ver: Major version of data path network interface API
1885 * @minor_ver: Minor version of data path network interface API
1887 * Return: '0' on Success; Error code otherwise.
1889 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1891 uint16_t *major_ver,
1892 uint16_t *minor_ver)
1894 struct dpni_rsp_get_api_version *rsp_params;
1895 struct mc_command cmd = { 0 };
1898 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1902 err = mc_send_command(mc_io, &cmd);
1906 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1907 *major_ver = le16_to_cpu(rsp_params->major);
1908 *minor_ver = le16_to_cpu(rsp_params->minor);
1914 * dpni_set_queue() - Set queue parameters
1915 * @mc_io: Pointer to MC portal's I/O object
1916 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1917 * @token: Token of DPNI object
1918 * @qtype: Type of queue - all queue types are supported, although
1919 * the command is ignored for Tx
1920 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1921 * @index: Selects the specific queue out of the set allocated for the
1922 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1923 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
1924 * configuration options are set on the queue
1925 * @queue: Queue structure
1927 * Return: '0' on Success; Error code otherwise.
1929 int dpni_set_queue(struct fsl_mc_io *mc_io,
1932 enum dpni_queue_type qtype,
1936 const struct dpni_queue *queue)
1938 struct mc_command cmd = { 0 };
1939 struct dpni_cmd_set_queue *cmd_params;
1941 /* prepare command */
1942 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1945 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1946 cmd_params->qtype = qtype;
1947 cmd_params->tc = tc;
1948 cmd_params->index = index;
1949 cmd_params->options = options;
1950 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1951 cmd_params->dest_prio = queue->destination.priority;
1952 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1953 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1954 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1955 queue->destination.hold_active);
1956 cmd_params->flc = cpu_to_le64(queue->flc.value);
1957 cmd_params->user_context = cpu_to_le64(queue->user_context);
1958 cmd_params->cgid = queue->cgid;
1960 /* send command to mc */
1961 return mc_send_command(mc_io, &cmd);
1965 * dpni_get_queue() - Get queue parameters
1966 * @mc_io: Pointer to MC portal's I/O object
1967 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1968 * @token: Token of DPNI object
1969 * @qtype: Type of queue - all queue types are supported
1970 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1971 * @index: Selects the specific queue out of the set allocated for the
1972 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1973 * @queue: Queue configuration structure
1974 * @qid: Queue identification
1976 * Return: '0' on Success; Error code otherwise.
1978 int dpni_get_queue(struct fsl_mc_io *mc_io,
1981 enum dpni_queue_type qtype,
1984 struct dpni_queue *queue,
1985 struct dpni_queue_id *qid)
1987 struct mc_command cmd = { 0 };
1988 struct dpni_cmd_get_queue *cmd_params;
1989 struct dpni_rsp_get_queue *rsp_params;
1992 /* prepare command */
1993 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1996 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1997 cmd_params->qtype = qtype;
1998 cmd_params->tc = tc;
1999 cmd_params->index = index;
2001 /* send command to mc */
2002 err = mc_send_command(mc_io, &cmd);
2006 /* retrieve response parameters */
2007 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2008 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2009 queue->destination.priority = rsp_params->dest_prio;
2010 queue->destination.type = dpni_get_field(rsp_params->flags,
2012 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2014 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2016 queue->flc.value = le64_to_cpu(rsp_params->flc);
2017 queue->user_context = le64_to_cpu(rsp_params->user_context);
2018 qid->fqid = le32_to_cpu(rsp_params->fqid);
2019 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2020 if (dpni_get_field(rsp_params->flags, CGID_VALID))
2021 queue->cgid = rsp_params->cgid;
2029 * dpni_get_statistics() - Get DPNI statistics
2030 * @mc_io: Pointer to MC portal's I/O object
2031 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2032 * @token: Token of DPNI object
2033 * @page: Selects the statistics page to retrieve, see
2034 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 3.
2035 * @param: Custom parameter for some pages used to select
2036 * a certain statistic source, for example the TC.
2037 * @stat: Structure containing the statistics
2039 * Return: '0' on Success; Error code otherwise.
2041 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2046 union dpni_statistics *stat)
2048 struct mc_command cmd = { 0 };
2049 struct dpni_cmd_get_statistics *cmd_params;
2050 struct dpni_rsp_get_statistics *rsp_params;
2053 /* prepare command */
2054 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2057 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2058 cmd_params->page_number = page;
2059 cmd_params->param = param;
2061 /* send command to mc */
2062 err = mc_send_command(mc_io, &cmd);
2066 /* retrieve response parameters */
2067 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2068 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2069 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2075 * dpni_reset_statistics() - Clears DPNI statistics
2076 * @mc_io: Pointer to MC portal's I/O object
2077 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2078 * @token: Token of DPNI object
2080 * Return: '0' on Success; Error code otherwise.
2082 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2086 struct mc_command cmd = { 0 };
2088 /* prepare command */
2089 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2093 /* send command to mc*/
2094 return mc_send_command(mc_io, &cmd);
2098 * dpni_set_taildrop() - Set taildrop per queue or TC
2100 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2101 * congestion notification or early drop (WRED) configuration previously applied
2104 * @mc_io: Pointer to MC portal's I/O object
2105 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2106 * @token: Token of DPNI object
2107 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in
2108 * combination with DPNI_QUEUE_RX.
2109 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2110 * @tc: Traffic class to apply this taildrop to
2111 * @q_index: Index of the queue if the DPNI supports multiple queues for
2112 * traffic distribution.
2113 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
2114 * @taildrop: Taildrop structure
2116 * Return: '0' on Success; Error code otherwise.
2118 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2121 enum dpni_congestion_point cg_point,
2122 enum dpni_queue_type qtype,
2125 struct dpni_taildrop *taildrop)
2127 struct mc_command cmd = { 0 };
2128 struct dpni_cmd_set_taildrop *cmd_params;
2130 /* prepare command */
2131 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2134 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2135 cmd_params->congestion_point = cg_point;
2136 cmd_params->qtype = qtype;
2137 cmd_params->tc = tc;
2138 cmd_params->index = index;
2139 cmd_params->units = taildrop->units;
2140 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2141 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2142 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2143 dpni_set_field(cmd_params->oal_hi,
2145 taildrop->oal >> DPNI_OAL_LO_SIZE);
2147 /* send command to mc */
2148 return mc_send_command(mc_io, &cmd);
2152 * dpni_get_taildrop() - Get taildrop information
2153 * @mc_io: Pointer to MC portal's I/O object
2154 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2155 * @token: Token of DPNI object
2156 * @cg_point: Congestion point
2157 * @q_type: Queue type on which the taildrop is configured.
2158 * Only Rx queues are supported for now
2159 * @tc: Traffic class to apply this taildrop to
2160 * @q_index: Index of the queue if the DPNI supports multiple queues for
2161 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2162 * @taildrop: Taildrop structure
2164 * Return: '0' on Success; Error code otherwise.
2166 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2169 enum dpni_congestion_point cg_point,
2170 enum dpni_queue_type qtype,
2173 struct dpni_taildrop *taildrop)
2175 struct mc_command cmd = { 0 };
2176 struct dpni_cmd_get_taildrop *cmd_params;
2177 struct dpni_rsp_get_taildrop *rsp_params;
2178 uint8_t oal_lo, oal_hi;
2181 /* prepare command */
2182 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2185 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2186 cmd_params->congestion_point = cg_point;
2187 cmd_params->qtype = qtype;
2188 cmd_params->tc = tc;
2189 cmd_params->index = index;
2191 /* send command to mc */
2192 err = mc_send_command(mc_io, &cmd);
2196 /* retrieve response parameters */
2197 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2198 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2199 taildrop->units = rsp_params->units;
2200 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2201 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2202 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2203 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2205 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2206 if (taildrop->oal >= 0x0800)
2207 taildrop->oal |= 0xF000;
2213 * dpni_set_opr() - Set Order Restoration configuration.
2214 * @mc_io: Pointer to MC portal's I/O object
2215 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2216 * @token: Token of DPNI object
2217 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2218 * @index: Selects the specific queue out of the set allocated
2219 * for the same TC. Value must be in range 0 to
2221 * @options: Configuration mode options
2222 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2223 * @cfg: Configuration options for the OPR
2225 * Return: '0' on Success; Error code otherwise.
2227 int dpni_set_opr(struct fsl_mc_io *mc_io,
2233 struct opr_cfg *cfg)
2235 struct dpni_cmd_set_opr *cmd_params;
2236 struct mc_command cmd = { 0 };
2238 /* prepare command */
2239 cmd.header = mc_encode_cmd_header(
2243 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2244 cmd_params->tc_id = tc;
2245 cmd_params->index = index;
2246 cmd_params->options = options;
2247 cmd_params->oloe = cfg->oloe;
2248 cmd_params->oeane = cfg->oeane;
2249 cmd_params->olws = cfg->olws;
2250 cmd_params->oa = cfg->oa;
2251 cmd_params->oprrws = cfg->oprrws;
2253 /* send command to mc*/
2254 return mc_send_command(mc_io, &cmd);
2258 * dpni_get_opr() - Retrieve Order Restoration config and query.
2259 * @mc_io: Pointer to MC portal's I/O object
2260 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2261 * @token: Token of DPNI object
2262 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2263 * @index: Selects the specific queue out of the set allocated
2264 * for the same TC. Value must be in range 0 to
2266 * @cfg: Returned OPR configuration
2267 * @qry: Returned OPR query
2269 * Return: '0' on Success; Error code otherwise.
2271 int dpni_get_opr(struct fsl_mc_io *mc_io,
2276 struct opr_cfg *cfg,
2277 struct opr_qry *qry)
2279 struct dpni_rsp_get_opr *rsp_params;
2280 struct dpni_cmd_get_opr *cmd_params;
2281 struct mc_command cmd = { 0 };
2284 /* prepare command */
2285 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2288 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2289 cmd_params->index = index;
2290 cmd_params->tc_id = tc;
2292 /* send command to mc*/
2293 err = mc_send_command(mc_io, &cmd);
2297 /* retrieve response parameters */
2298 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2299 cfg->oloe = rsp_params->oloe;
2300 cfg->oeane = rsp_params->oeane;
2301 cfg->olws = rsp_params->olws;
2302 cfg->oa = rsp_params->oa;
2303 cfg->oprrws = rsp_params->oprrws;
2304 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2305 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2306 qry->nesn = le16_to_cpu(rsp_params->nesn);
2307 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2308 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2309 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2310 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2311 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2312 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2313 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2314 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2315 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2321 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2322 * @mc_io: Pointer to MC portal's I/O object
2323 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2324 * @token: Token of DPNI object
2325 * @cfg: Distribution configuration
2326 * If the FS is already enabled with a previous call the classification
2327 * key will be changed but all the table rules are kept. If the
2328 * existing rules do not match the key the results will not be
2329 * predictable. It is the user responsibility to keep key integrity
2330 * If cfg.enable is set to 1 the command will create a flow steering table
2331 * and will classify packets according to this table. The packets
2332 * that miss all the table rules will be classified according to
2333 * settings made in dpni_set_rx_hash_dist()
2334 * If cfg.enable is set to 0 the command will clear flow steering table. The
2335 * packets will be classified according to settings made in
2336 * dpni_set_rx_hash_dist()
2338 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2339 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2341 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2342 struct mc_command cmd = { 0 };
2344 /* prepare command */
2345 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2348 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2349 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2350 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2351 cmd_params->tc = cfg->tc;
2352 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2353 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2355 /* send command to mc*/
2356 return mc_send_command(mc_io, &cmd);
2360 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2361 * @mc_io: Pointer to MC portal's I/O object
2362 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2363 * @token: Token of DPNI object
2364 * @cfg: Distribution configuration
2365 * If cfg.enable is set to 1 the packets will be classified using a hash
2366 * function based on the key received in cfg.key_cfg_iova parameter
2367 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2368 * dpni_set_rx_dist_default_queue() call
2370 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2371 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2373 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2374 struct mc_command cmd = { 0 };
2376 /* prepare command */
2377 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2380 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2381 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2382 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2383 cmd_params->tc_id = cfg->tc;
2384 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2386 /* send command to mc*/
2387 return mc_send_command(mc_io, &cmd);
2391 * dpni_add_custom_tpid() - Configures a distinct Ethertype value
2392 * (or TPID value) to indicate VLAN tag in addition to the common
2393 * TPID values 0x8100 and 0x88A8
2394 * @mc_io: Pointer to MC portal's I/O object
2395 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2396 * @token: Token of DPNI object
2397 * @tpid: New value for TPID
2399 * Only two custom values are accepted. If the function is called for the third
2400 * time it will return error.
2401 * To replace an existing value use dpni_remove_custom_tpid() to remove
2402 * a previous TPID and after that use again the function.
2404 * Return: '0' on Success; Error code otherwise.
2406 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2407 uint16_t token, uint16_t tpid)
2409 struct dpni_cmd_add_custom_tpid *cmd_params;
2410 struct mc_command cmd = { 0 };
2412 /* prepare command */
2413 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
2416 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
2417 cmd_params->tpid = cpu_to_le16(tpid);
2419 /* send command to mc*/
2420 return mc_send_command(mc_io, &cmd);
2424 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
2425 * previously with dpni_add_custom_tpid()
2426 * @mc_io: Pointer to MC portal's I/O object
2427 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2428 * @token: Token of DPNI object
2429 * @tpid: New value for TPID
2431 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
2434 * Return: '0' on Success; Error code otherwise.
2436 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2437 uint16_t token, uint16_t tpid)
2439 struct dpni_cmd_remove_custom_tpid *cmd_params;
2440 struct mc_command cmd = { 0 };
2442 /* prepare command */
2443 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
2446 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
2447 cmd_params->tpid = cpu_to_le16(tpid);
2449 /* send command to mc*/
2450 return mc_send_command(mc_io, &cmd);
2454 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured
2455 * to detect 802.1q frames
2456 * @mc_io: Pointer to MC portal's I/O object
2457 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2458 * @token: Token of DPNI object
2459 * @tpid: TPID values. Only nonzero members of the structure are valid.
2461 * Return: '0' on Success; Error code otherwise.
2463 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2464 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
2466 struct dpni_rsp_get_custom_tpid *rsp_params;
2467 struct mc_command cmd = { 0 };
2470 /* prepare command */
2471 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
2475 /* send command to mc*/
2476 err = mc_send_command(mc_io, &cmd);
2480 /* read command response */
2481 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
2482 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
2483 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);