1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2019 NXP
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 cmd_params->pool_options = cfg->pool_options;
204 for (i = 0; i < cmd_params->num_dpbp; i++) {
205 cmd_params->pool[i].dpbp_id =
206 cpu_to_le16(cfg->pools[i].dpbp_id);
207 cmd_params->pool[i].priority_mask =
208 cfg->pools[i].priority_mask;
209 cmd_params->buffer_size[i] =
210 cpu_to_le16(cfg->pools[i].buffer_size);
211 cmd_params->backup_pool_mask |=
212 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
215 /* send command to mc*/
216 return mc_send_command(mc_io, &cmd);
220 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
221 * @mc_io: Pointer to MC portal's I/O object
222 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
223 * @token: Token of DPNI object
225 * Return: '0' on Success; Error code otherwise.
227 int dpni_enable(struct fsl_mc_io *mc_io,
231 struct mc_command cmd = { 0 };
233 /* prepare command */
234 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
238 /* send command to mc*/
239 return mc_send_command(mc_io, &cmd);
243 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
244 * @mc_io: Pointer to MC portal's I/O object
245 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
246 * @token: Token of DPNI object
248 * Return: '0' on Success; Error code otherwise.
250 int dpni_disable(struct fsl_mc_io *mc_io,
254 struct mc_command cmd = { 0 };
256 /* prepare command */
257 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
261 /* send command to mc*/
262 return mc_send_command(mc_io, &cmd);
266 * dpni_is_enabled() - Check if the DPNI is enabled.
267 * @mc_io: Pointer to MC portal's I/O object
268 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
269 * @token: Token of DPNI object
270 * @en: Returns '1' if object is enabled; '0' otherwise
272 * Return: '0' on Success; Error code otherwise.
274 int dpni_is_enabled(struct fsl_mc_io *mc_io,
279 struct mc_command cmd = { 0 };
280 struct dpni_rsp_is_enabled *rsp_params;
283 /* prepare command */
284 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
288 /* send command to mc*/
289 err = mc_send_command(mc_io, &cmd);
293 /* retrieve response parameters */
294 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
295 *en = dpni_get_field(rsp_params->enabled, ENABLE);
301 * dpni_reset() - Reset the DPNI, returns the object to initial state.
302 * @mc_io: Pointer to MC portal's I/O object
303 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
304 * @token: Token of DPNI object
306 * Return: '0' on Success; Error code otherwise.
308 int dpni_reset(struct fsl_mc_io *mc_io,
312 struct mc_command cmd = { 0 };
314 /* prepare command */
315 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
319 /* send command to mc*/
320 return mc_send_command(mc_io, &cmd);
324 * dpni_set_irq_enable() - Set overall interrupt state.
325 * @mc_io: Pointer to MC portal's I/O object
326 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
327 * @token: Token of DPNI object
328 * @irq_index: The interrupt index to configure
329 * @en: Interrupt state: - enable = 1, disable = 0
331 * Allows GPP software to control when interrupts are generated.
332 * Each interrupt can have up to 32 causes. The enable/disable control's the
333 * overall interrupt state. if the interrupt is disabled no causes will cause
336 * Return: '0' on Success; Error code otherwise.
338 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
344 struct mc_command cmd = { 0 };
345 struct dpni_cmd_set_irq_enable *cmd_params;
347 /* prepare command */
348 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
351 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
352 dpni_set_field(cmd_params->enable, ENABLE, en);
353 cmd_params->irq_index = irq_index;
355 /* send command to mc*/
356 return mc_send_command(mc_io, &cmd);
360 * dpni_get_irq_enable() - Get overall interrupt state
361 * @mc_io: Pointer to MC portal's I/O object
362 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
363 * @token: Token of DPNI object
364 * @irq_index: The interrupt index to configure
365 * @en: Returned interrupt state - enable = 1, disable = 0
367 * Return: '0' on Success; Error code otherwise.
369 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
375 struct mc_command cmd = { 0 };
376 struct dpni_cmd_get_irq_enable *cmd_params;
377 struct dpni_rsp_get_irq_enable *rsp_params;
381 /* prepare command */
382 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
385 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
386 cmd_params->irq_index = irq_index;
388 /* send command to mc*/
389 err = mc_send_command(mc_io, &cmd);
393 /* retrieve response parameters */
394 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
395 *en = dpni_get_field(rsp_params->enabled, ENABLE);
401 * dpni_set_irq_mask() - Set interrupt mask.
402 * @mc_io: Pointer to MC portal's I/O object
403 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
404 * @token: Token of DPNI object
405 * @irq_index: The interrupt index to configure
406 * @mask: Event mask to trigger interrupt;
409 * 1 = consider event for asserting IRQ
411 * Every interrupt can have up to 32 causes and the interrupt model supports
412 * masking/unmasking each cause independently
414 * Return: '0' on Success; Error code otherwise.
416 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
422 struct mc_command cmd = { 0 };
423 struct dpni_cmd_set_irq_mask *cmd_params;
425 /* prepare command */
426 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
429 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
430 cmd_params->mask = cpu_to_le32(mask);
431 cmd_params->irq_index = irq_index;
433 /* send command to mc*/
434 return mc_send_command(mc_io, &cmd);
438 * dpni_get_irq_mask() - Get interrupt mask.
439 * @mc_io: Pointer to MC portal's I/O object
440 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
441 * @token: Token of DPNI object
442 * @irq_index: The interrupt index to configure
443 * @mask: Returned event mask to trigger interrupt
445 * Every interrupt can have up to 32 causes and the interrupt model supports
446 * masking/unmasking each cause independently
448 * Return: '0' on Success; Error code otherwise.
450 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
456 struct mc_command cmd = { 0 };
457 struct dpni_cmd_get_irq_mask *cmd_params;
458 struct dpni_rsp_get_irq_mask *rsp_params;
461 /* prepare command */
462 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
465 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
466 cmd_params->irq_index = irq_index;
468 /* send command to mc*/
469 err = mc_send_command(mc_io, &cmd);
473 /* retrieve response parameters */
474 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
475 *mask = le32_to_cpu(rsp_params->mask);
481 * dpni_get_irq_status() - Get the current status of any pending interrupts.
482 * @mc_io: Pointer to MC portal's I/O object
483 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
484 * @token: Token of DPNI object
485 * @irq_index: The interrupt index to configure
486 * @status: Returned interrupts status - one bit per cause:
487 * 0 = no interrupt pending
488 * 1 = interrupt pending
490 * Return: '0' on Success; Error code otherwise.
492 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
498 struct mc_command cmd = { 0 };
499 struct dpni_cmd_get_irq_status *cmd_params;
500 struct dpni_rsp_get_irq_status *rsp_params;
503 /* prepare command */
504 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
507 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
508 cmd_params->status = cpu_to_le32(*status);
509 cmd_params->irq_index = irq_index;
511 /* send command to mc*/
512 err = mc_send_command(mc_io, &cmd);
516 /* retrieve response parameters */
517 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
518 *status = le32_to_cpu(rsp_params->status);
524 * dpni_clear_irq_status() - Clear a pending interrupt's status
525 * @mc_io: Pointer to MC portal's I/O object
526 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
527 * @token: Token of DPNI object
528 * @irq_index: The interrupt index to configure
529 * @status: bits to clear (W1C) - one bit per cause:
531 * 1 = clear status bit
533 * Return: '0' on Success; Error code otherwise.
535 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
541 struct mc_command cmd = { 0 };
542 struct dpni_cmd_clear_irq_status *cmd_params;
544 /* prepare command */
545 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
548 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
549 cmd_params->irq_index = irq_index;
550 cmd_params->status = cpu_to_le32(status);
552 /* send command to mc*/
553 return mc_send_command(mc_io, &cmd);
557 * dpni_get_attributes() - Retrieve DPNI attributes.
558 * @mc_io: Pointer to MC portal's I/O object
559 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
560 * @token: Token of DPNI object
561 * @attr: Object's attributes
563 * Return: '0' on Success; Error code otherwise.
565 int dpni_get_attributes(struct fsl_mc_io *mc_io,
568 struct dpni_attr *attr)
570 struct mc_command cmd = { 0 };
571 struct dpni_rsp_get_attr *rsp_params;
575 /* prepare command */
576 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
580 /* send command to mc*/
581 err = mc_send_command(mc_io, &cmd);
585 /* retrieve response parameters */
586 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
587 attr->options = le32_to_cpu(rsp_params->options);
588 attr->num_queues = rsp_params->num_queues;
589 attr->num_rx_tcs = rsp_params->num_rx_tcs;
590 attr->num_tx_tcs = rsp_params->num_tx_tcs;
591 attr->mac_filter_entries = rsp_params->mac_filter_entries;
592 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
593 attr->qos_entries = rsp_params->qos_entries;
594 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
595 attr->qos_key_size = rsp_params->qos_key_size;
596 attr->fs_key_size = rsp_params->fs_key_size;
597 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
598 attr->num_cgs = rsp_params->num_cgs;
604 * dpni_set_errors_behavior() - Set errors behavior
605 * @mc_io: Pointer to MC portal's I/O object
606 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
607 * @token: Token of DPNI object
608 * @cfg: Errors configuration
610 * This function may be called numerous times with different
613 * Return: '0' on Success; Error code otherwise.
615 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
618 struct dpni_error_cfg *cfg)
620 struct mc_command cmd = { 0 };
621 struct dpni_cmd_set_errors_behavior *cmd_params;
623 /* prepare command */
624 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
627 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
628 cmd_params->errors = cpu_to_le32(cfg->errors);
629 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
630 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
632 /* send command to mc*/
633 return mc_send_command(mc_io, &cmd);
637 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
638 * @mc_io: Pointer to MC portal's I/O object
639 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
640 * @token: Token of DPNI object
641 * @qtype: Type of queue to retrieve configuration for
642 * @layout: Returns buffer layout attributes
644 * Return: '0' on Success; Error code otherwise.
646 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
649 enum dpni_queue_type qtype,
650 struct dpni_buffer_layout *layout)
652 struct mc_command cmd = { 0 };
653 struct dpni_cmd_get_buffer_layout *cmd_params;
654 struct dpni_rsp_get_buffer_layout *rsp_params;
657 /* prepare command */
658 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
661 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
662 cmd_params->qtype = qtype;
664 /* send command to mc*/
665 err = mc_send_command(mc_io, &cmd);
669 /* retrieve response parameters */
670 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
671 layout->pass_timestamp =
672 (int)dpni_get_field(rsp_params->flags, PASS_TS);
673 layout->pass_parser_result =
674 (int)dpni_get_field(rsp_params->flags, PASS_PR);
675 layout->pass_frame_status =
676 (int)dpni_get_field(rsp_params->flags, PASS_FS);
677 layout->pass_sw_opaque =
678 (int)dpni_get_field(rsp_params->flags, PASS_SWO);
679 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
680 layout->data_align = le16_to_cpu(rsp_params->data_align);
681 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
682 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
688 * dpni_set_buffer_layout() - Set buffer layout configuration.
689 * @mc_io: Pointer to MC portal's I/O object
690 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
691 * @token: Token of DPNI object
692 * @qtype: Type of queue this configuration applies to
693 * @layout: Buffer layout configuration
695 * Return: '0' on Success; Error code otherwise.
697 * @warning Allowed only when DPNI is disabled
699 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
702 enum dpni_queue_type qtype,
703 const struct dpni_buffer_layout *layout)
705 struct mc_command cmd = { 0 };
706 struct dpni_cmd_set_buffer_layout *cmd_params;
708 /* prepare command */
709 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
712 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
713 cmd_params->qtype = qtype;
714 cmd_params->options = cpu_to_le16((uint16_t)layout->options);
715 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
716 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
717 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
718 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
719 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
720 cmd_params->data_align = cpu_to_le16(layout->data_align);
721 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
722 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
724 /* send command to mc*/
725 return mc_send_command(mc_io, &cmd);
729 * dpni_set_offload() - Set DPNI offload configuration.
730 * @mc_io: Pointer to MC portal's I/O object
731 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
732 * @token: Token of DPNI object
733 * @type: Type of DPNI offload
734 * @config: Offload configuration.
735 * For checksum offloads, non-zero value enables the offload
737 * Return: '0' on Success; Error code otherwise.
739 * @warning Allowed only when DPNI is disabled
742 int dpni_set_offload(struct fsl_mc_io *mc_io,
745 enum dpni_offload type,
748 struct mc_command cmd = { 0 };
749 struct dpni_cmd_set_offload *cmd_params;
751 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
754 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
755 cmd_params->dpni_offload = type;
756 cmd_params->config = cpu_to_le32(config);
758 return mc_send_command(mc_io, &cmd);
762 * dpni_get_offload() - Get DPNI offload configuration.
763 * @mc_io: Pointer to MC portal's I/O object
764 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
765 * @token: Token of DPNI object
766 * @type: Type of DPNI offload
767 * @config: Offload configuration.
768 * For checksum offloads, a value of 1 indicates that the
769 * offload is enabled.
771 * Return: '0' on Success; Error code otherwise.
773 * @warning Allowed only when DPNI is disabled
775 int dpni_get_offload(struct fsl_mc_io *mc_io,
778 enum dpni_offload type,
781 struct mc_command cmd = { 0 };
782 struct dpni_cmd_get_offload *cmd_params;
783 struct dpni_rsp_get_offload *rsp_params;
786 /* prepare command */
787 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
790 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
791 cmd_params->dpni_offload = type;
793 /* send command to mc*/
794 err = mc_send_command(mc_io, &cmd);
798 /* retrieve response parameters */
799 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
800 *config = le32_to_cpu(rsp_params->config);
806 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
807 * for enqueue operations
808 * @mc_io: Pointer to MC portal's I/O object
809 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
810 * @token: Token of DPNI object
811 * @qtype: Type of queue to receive QDID for
812 * @qdid: Returned virtual QDID value that should be used as an argument
813 * in all enqueue operations
815 * Return: '0' on Success; Error code otherwise.
817 int dpni_get_qdid(struct fsl_mc_io *mc_io,
820 enum dpni_queue_type qtype,
823 struct mc_command cmd = { 0 };
824 struct dpni_cmd_get_qdid *cmd_params;
825 struct dpni_rsp_get_qdid *rsp_params;
828 /* prepare command */
829 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
832 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
833 cmd_params->qtype = qtype;
835 /* send command to mc*/
836 err = mc_send_command(mc_io, &cmd);
840 /* retrieve response parameters */
841 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
842 *qdid = le16_to_cpu(rsp_params->qdid);
848 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
849 * @mc_io: Pointer to MC portal's I/O object
850 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
851 * @token: Token of DPNI object
852 * @data_offset: Tx data offset (from start of buffer)
854 * Return: '0' on Success; Error code otherwise.
856 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
859 uint16_t *data_offset)
861 struct mc_command cmd = { 0 };
862 struct dpni_rsp_get_tx_data_offset *rsp_params;
865 /* prepare command */
866 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
870 /* send command to mc*/
871 err = mc_send_command(mc_io, &cmd);
875 /* retrieve response parameters */
876 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
877 *data_offset = le16_to_cpu(rsp_params->data_offset);
883 * dpni_set_link_cfg() - set the link configuration.
884 * @mc_io: Pointer to MC portal's I/O object
885 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
886 * @token: Token of DPNI object
887 * @cfg: Link configuration
889 * Return: '0' on Success; Error code otherwise.
891 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
894 const struct dpni_link_cfg *cfg)
896 struct mc_command cmd = { 0 };
897 struct dpni_cmd_set_link_cfg *cmd_params;
899 /* prepare command */
900 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
903 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
904 cmd_params->rate = cpu_to_le32(cfg->rate);
905 cmd_params->options = cpu_to_le64(cfg->options);
906 cmd_params->advertising = cpu_to_le64(cfg->advertising);
908 /* send command to mc*/
909 return mc_send_command(mc_io, &cmd);
913 * dpni_get_link_state() - Return the link state (either up or down)
914 * @mc_io: Pointer to MC portal's I/O object
915 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
916 * @token: Token of DPNI object
917 * @state: Returned link state;
919 * Return: '0' on Success; Error code otherwise.
921 int dpni_get_link_state(struct fsl_mc_io *mc_io,
924 struct dpni_link_state *state)
926 struct mc_command cmd = { 0 };
927 struct dpni_rsp_get_link_state *rsp_params;
930 /* prepare command */
931 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
935 /* send command to mc*/
936 err = mc_send_command(mc_io, &cmd);
940 /* retrieve response parameters */
941 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
942 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
943 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
944 state->rate = le32_to_cpu(rsp_params->rate);
945 state->options = le64_to_cpu(rsp_params->options);
946 state->supported = le64_to_cpu(rsp_params->supported);
947 state->advertising = le64_to_cpu(rsp_params->advertising);
953 * dpni_set_max_frame_length() - Set the maximum received frame length.
954 * @mc_io: Pointer to MC portal's I/O object
955 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
956 * @token: Token of DPNI object
957 * @max_frame_length: Maximum received frame length (in bytes);
958 * frame is discarded if its length exceeds this value
960 * Return: '0' on Success; Error code otherwise.
962 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
965 uint16_t max_frame_length)
967 struct mc_command cmd = { 0 };
968 struct dpni_cmd_set_max_frame_length *cmd_params;
970 /* prepare command */
971 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
974 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
975 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
977 /* send command to mc*/
978 return mc_send_command(mc_io, &cmd);
982 * dpni_get_max_frame_length() - Get the maximum received frame length.
983 * @mc_io: Pointer to MC portal's I/O object
984 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
985 * @token: Token of DPNI object
986 * @max_frame_length: Maximum received frame length (in bytes);
987 * frame is discarded if its length exceeds this value
989 * Return: '0' on Success; Error code otherwise.
991 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
994 uint16_t *max_frame_length)
996 struct mc_command cmd = { 0 };
997 struct dpni_rsp_get_max_frame_length *rsp_params;
1000 /* prepare command */
1001 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1005 /* send command to mc*/
1006 err = mc_send_command(mc_io, &cmd);
1010 /* retrieve response parameters */
1011 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1012 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1018 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1019 * @mc_io: Pointer to MC portal's I/O object
1020 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1021 * @token: Token of DPNI object
1022 * @en: Set to '1' to enable; '0' to disable
1024 * Return: '0' on Success; Error code otherwise.
1026 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1031 struct mc_command cmd = { 0 };
1032 struct dpni_cmd_set_multicast_promisc *cmd_params;
1034 /* prepare command */
1035 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1038 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1039 dpni_set_field(cmd_params->enable, ENABLE, en);
1041 /* send command to mc*/
1042 return mc_send_command(mc_io, &cmd);
1046 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1047 * @mc_io: Pointer to MC portal's I/O object
1048 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1049 * @token: Token of DPNI object
1050 * @en: Returns '1' if enabled; '0' otherwise
1052 * Return: '0' on Success; Error code otherwise.
1054 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1059 struct mc_command cmd = { 0 };
1060 struct dpni_rsp_get_multicast_promisc *rsp_params;
1063 /* prepare command */
1064 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1068 /* send command to mc*/
1069 err = mc_send_command(mc_io, &cmd);
1073 /* retrieve response parameters */
1074 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1075 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1081 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1082 * @mc_io: Pointer to MC portal's I/O object
1083 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1084 * @token: Token of DPNI object
1085 * @en: Set to '1' to enable; '0' to disable
1087 * Return: '0' on Success; Error code otherwise.
1089 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1094 struct mc_command cmd = { 0 };
1095 struct dpni_cmd_set_unicast_promisc *cmd_params;
1097 /* prepare command */
1098 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1101 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1102 dpni_set_field(cmd_params->enable, ENABLE, en);
1104 /* send command to mc*/
1105 return mc_send_command(mc_io, &cmd);
1109 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1110 * @mc_io: Pointer to MC portal's I/O object
1111 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1112 * @token: Token of DPNI object
1113 * @en: Returns '1' if enabled; '0' otherwise
1115 * Return: '0' on Success; Error code otherwise.
1117 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1122 struct mc_command cmd = { 0 };
1123 struct dpni_rsp_get_unicast_promisc *rsp_params;
1126 /* prepare command */
1127 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1131 /* send command to mc*/
1132 err = mc_send_command(mc_io, &cmd);
1136 /* retrieve response parameters */
1137 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1138 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1144 * dpni_set_primary_mac_addr() - Set the primary MAC address
1145 * @mc_io: Pointer to MC portal's I/O object
1146 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1147 * @token: Token of DPNI object
1148 * @mac_addr: MAC address to set as primary address
1150 * Return: '0' on Success; Error code otherwise.
1152 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1155 const uint8_t mac_addr[6])
1157 struct mc_command cmd = { 0 };
1158 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1161 /* prepare command */
1162 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1165 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1166 for (i = 0; i < 6; i++)
1167 cmd_params->mac_addr[i] = mac_addr[5 - i];
1169 /* send command to mc*/
1170 return mc_send_command(mc_io, &cmd);
1174 * dpni_get_primary_mac_addr() - Get the primary MAC address
1175 * @mc_io: Pointer to MC portal's I/O object
1176 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1177 * @token: Token of DPNI object
1178 * @mac_addr: Returned MAC address
1180 * Return: '0' on Success; Error code otherwise.
1182 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1185 uint8_t mac_addr[6])
1187 struct mc_command cmd = { 0 };
1188 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1191 /* prepare command */
1192 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1196 /* send command to mc*/
1197 err = mc_send_command(mc_io, &cmd);
1201 /* retrieve response parameters */
1202 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1203 for (i = 0; i < 6; i++)
1204 mac_addr[5 - i] = rsp_params->mac_addr[i];
1210 * dpni_add_mac_addr() - Add MAC address filter
1211 * @mc_io: Pointer to MC portal's I/O object
1212 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1213 * @token: Token of DPNI object
1214 * @mac_addr: MAC address to add
1215 * @flags : 0 - tc_id and flow_id will be ignored.
1216 * Pkt with this mac_id will be passed to the next
1217 * classification stages
1218 * DPNI_MAC_SET_QUEUE_ACTION
1219 * Pkt with this mac will be forward directly to
1220 * queue defined by the tc_id and flow_id
1221 * @tc_id : Traffic class selection (0-7)
1222 * @flow_id : Selects the specific queue out of the set allocated for the
1223 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1224 * Return: '0' on Success; Error code otherwise.
1226 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1229 const uint8_t mac_addr[6],
1234 struct mc_command cmd = { 0 };
1235 struct dpni_cmd_add_mac_addr *cmd_params;
1238 /* prepare command */
1239 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1242 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1243 cmd_params->flags = flags;
1244 cmd_params->tc_id = tc_id;
1245 cmd_params->fq_id = flow_id;
1247 for (i = 0; i < 6; i++)
1248 cmd_params->mac_addr[i] = mac_addr[5 - i];
1250 /* send command to mc*/
1251 return mc_send_command(mc_io, &cmd);
1255 * dpni_remove_mac_addr() - Remove MAC address filter
1256 * @mc_io: Pointer to MC portal's I/O object
1257 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1258 * @token: Token of DPNI object
1259 * @mac_addr: MAC address to remove
1261 * Return: '0' on Success; Error code otherwise.
1263 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1266 const uint8_t mac_addr[6])
1268 struct mc_command cmd = { 0 };
1269 struct dpni_cmd_remove_mac_addr *cmd_params;
1272 /* prepare command */
1273 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1276 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1277 for (i = 0; i < 6; i++)
1278 cmd_params->mac_addr[i] = mac_addr[5 - i];
1280 /* send command to mc*/
1281 return mc_send_command(mc_io, &cmd);
1285 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1286 * @mc_io: Pointer to MC portal's I/O object
1287 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1288 * @token: Token of DPNI object
1289 * @unicast: Set to '1' to clear unicast addresses
1290 * @multicast: Set to '1' to clear multicast addresses
1292 * The primary MAC address is not cleared by this operation.
1294 * Return: '0' on Success; Error code otherwise.
1296 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1302 struct mc_command cmd = { 0 };
1303 struct dpni_cmd_clear_mac_filters *cmd_params;
1305 /* prepare command */
1306 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1309 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1310 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1311 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1313 /* send command to mc*/
1314 return mc_send_command(mc_io, &cmd);
1318 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1319 * port the DPNI is attached to
1320 * @mc_io: Pointer to MC portal's I/O object
1321 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1322 * @token: Token of DPNI object
1323 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1325 * The primary MAC address is not cleared by this operation.
1327 * Return: '0' on Success; Error code otherwise.
1329 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1332 uint8_t mac_addr[6])
1334 struct mc_command cmd = { 0 };
1335 struct dpni_rsp_get_port_mac_addr *rsp_params;
1338 /* prepare command */
1339 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1343 /* send command to mc*/
1344 err = mc_send_command(mc_io, &cmd);
1348 /* retrieve response parameters */
1349 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1350 for (i = 0; i < 6; i++)
1351 mac_addr[5 - i] = rsp_params->mac_addr[i];
1357 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1358 * @mc_io: Pointer to MC portal's I/O object
1359 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1360 * @token: Token of DPNI object
1361 * @en: Set to '1' to enable; '0' to disable
1363 * Return: '0' on Success; Error code otherwise.
1365 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1370 struct dpni_cmd_enable_vlan_filter *cmd_params;
1371 struct mc_command cmd = { 0 };
1373 /* prepare command */
1374 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1377 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1378 dpni_set_field(cmd_params->en, ENABLE, en);
1380 /* send command to mc*/
1381 return mc_send_command(mc_io, &cmd);
1385 * dpni_add_vlan_id() - Add VLAN ID filter
1386 * @mc_io: Pointer to MC portal's I/O object
1387 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1388 * @token: Token of DPNI object
1389 * @vlan_id: VLAN ID to add
1390 * @flags: 0 - tc_id and flow_id will be ignored.
1391 * Pkt with this vlan_id will be passed to the next
1392 * classification stages
1393 * DPNI_VLAN_SET_QUEUE_ACTION
1394 * Pkt with this vlan_id will be forward directly to
1395 * queue defined by the tc_id and flow_id
1397 * @tc_id: Traffic class selection (0-7)
1398 * @flow_id: Selects the specific queue out of the set allocated for the
1399 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1401 * Return: '0' on Success; Error code otherwise.
1403 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1411 struct dpni_cmd_vlan_id *cmd_params;
1412 struct mc_command cmd = { 0 };
1414 /* prepare command */
1415 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1418 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1419 cmd_params->flags = flags;
1420 cmd_params->tc_id = tc_id;
1421 cmd_params->flow_id = flow_id;
1422 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1424 /* send command to mc*/
1425 return mc_send_command(mc_io, &cmd);
1429 * dpni_remove_vlan_id() - Remove VLAN ID filter
1430 * @mc_io: Pointer to MC portal's I/O object
1431 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1432 * @token: Token of DPNI object
1433 * @vlan_id: VLAN ID to remove
1435 * Return: '0' on Success; Error code otherwise.
1437 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1442 struct dpni_cmd_vlan_id *cmd_params;
1443 struct mc_command cmd = { 0 };
1445 /* prepare command */
1446 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1449 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1450 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1452 /* send command to mc*/
1453 return mc_send_command(mc_io, &cmd);
1457 * dpni_clear_vlan_filters() - Clear all VLAN filters
1458 * @mc_io: Pointer to MC portal's I/O object
1459 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1460 * @token: Token of DPNI object
1462 * Return: '0' on Success; Error code otherwise.
1464 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1468 struct mc_command cmd = { 0 };
1470 /* prepare command */
1471 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1475 /* send command to mc*/
1476 return mc_send_command(mc_io, &cmd);
1480 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1481 * @mc_io: Pointer to MC portal's I/O object
1482 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1483 * @token: Token of DPNI object
1484 * @tc_id: Traffic class selection (0-7)
1485 * @cfg: Traffic class distribution configuration
1487 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1488 * first to prepare the key_cfg_iova parameter
1490 * Return: '0' on Success; error code otherwise.
1492 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1496 const struct dpni_rx_tc_dist_cfg *cfg)
1498 struct mc_command cmd = { 0 };
1499 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1501 /* prepare command */
1502 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1505 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1506 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1507 cmd_params->tc_id = tc_id;
1508 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1509 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1510 dpni_set_field(cmd_params->flags,
1513 dpni_set_field(cmd_params->flags,
1515 cfg->fs_cfg.miss_action);
1516 dpni_set_field(cmd_params->keep_hash_key,
1518 cfg->fs_cfg.keep_hash_key);
1519 dpni_set_field(cmd_params->keep_hash_key,
1521 cfg->fs_cfg.keep_entries);
1523 /* send command to mc*/
1524 return mc_send_command(mc_io, &cmd);
1528 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1529 * @mc_io: Pointer to MC portal's I/O object
1530 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1531 * @token: Token of DPNI object
1532 * @mode: Tx confirmation mode
1534 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1535 * selected at DPNI creation.
1536 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1537 * transmit confirmation (including the private confirmation queues), regardless
1538 * of previous settings; Note that in this case, Tx error frames are still
1539 * enqueued to the general transmit errors queue.
1540 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1541 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1542 * command will be ignored.
1544 * Return: '0' on Success; Error code otherwise.
1546 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1549 enum dpni_confirmation_mode mode)
1551 struct dpni_tx_confirmation_mode *cmd_params;
1552 struct mc_command cmd = { 0 };
1554 /* prepare command */
1555 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1558 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1559 cmd_params->confirmation_mode = mode;
1561 /* send command to mc*/
1562 return mc_send_command(mc_io, &cmd);
1566 * dpni_set_qos_table() - Set QoS mapping table
1567 * @mc_io: Pointer to MC portal's I/O object
1568 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1569 * @token: Token of DPNI object
1570 * @cfg: QoS table configuration
1572 * This function and all QoS-related functions require that
1573 *'max_tcs > 1' was set at DPNI creation.
1575 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1576 * prepare the key_cfg_iova parameter
1578 * Return: '0' on Success; Error code otherwise.
1580 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1583 const struct dpni_qos_tbl_cfg *cfg)
1585 struct dpni_cmd_set_qos_table *cmd_params;
1586 struct mc_command cmd = { 0 };
1588 /* prepare command */
1589 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1592 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1593 cmd_params->default_tc = cfg->default_tc;
1594 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1595 dpni_set_field(cmd_params->discard_on_miss,
1597 cfg->discard_on_miss);
1598 dpni_set_field(cmd_params->discard_on_miss,
1602 /* send command to mc*/
1603 return mc_send_command(mc_io, &cmd);
1607 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1608 * @mc_io: Pointer to MC portal's I/O object
1609 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1610 * @token: Token of DPNI object
1611 * @cfg: QoS rule to add
1612 * @tc_id: Traffic class selection (0-7)
1613 * @index: Location in the QoS table where to insert the entry.
1614 * Only relevant if MASKING is enabled for QoS classification on
1615 * this DPNI, it is ignored for exact match.
1617 * Return: '0' on Success; Error code otherwise.
1619 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1622 const struct dpni_rule_cfg *cfg,
1628 struct dpni_cmd_add_qos_entry *cmd_params;
1629 struct mc_command cmd = { 0 };
1631 /* prepare command */
1632 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1635 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1636 cmd_params->flags = flags;
1637 cmd_params->flow_id = flow_id;
1638 cmd_params->tc_id = tc_id;
1639 cmd_params->key_size = cfg->key_size;
1640 cmd_params->index = cpu_to_le16(index);
1641 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1642 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1644 /* send command to mc*/
1645 return mc_send_command(mc_io, &cmd);
1649 * dpni_remove_qos_entry() - Remove QoS mapping entry
1650 * @mc_io: Pointer to MC portal's I/O object
1651 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1652 * @token: Token of DPNI object
1653 * @cfg: QoS rule to remove
1655 * Return: '0' on Success; Error code otherwise.
1657 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1660 const struct dpni_rule_cfg *cfg)
1662 struct dpni_cmd_remove_qos_entry *cmd_params;
1663 struct mc_command cmd = { 0 };
1665 /* prepare command */
1666 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1669 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1670 cmd_params->key_size = cfg->key_size;
1671 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1672 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1674 /* send command to mc*/
1675 return mc_send_command(mc_io, &cmd);
1679 * dpni_clear_qos_table() - Clear all QoS mapping entries
1680 * @mc_io: Pointer to MC portal's I/O object
1681 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1682 * @token: Token of DPNI object
1684 * Following this function call, all frames are directed to
1685 * the default traffic class (0)
1687 * Return: '0' on Success; Error code otherwise.
1689 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1693 struct mc_command cmd = { 0 };
1695 /* prepare command */
1696 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1700 /* send command to mc*/
1701 return mc_send_command(mc_io, &cmd);
1705 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1706 * (to select a flow ID)
1707 * @mc_io: Pointer to MC portal's I/O object
1708 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1709 * @token: Token of DPNI object
1710 * @tc_id: Traffic class selection (0-7)
1711 * @index: Location in the QoS table where to insert the entry.
1712 * Only relevant if MASKING is enabled for QoS classification
1713 * on this DPNI, it is ignored for exact match.
1714 * @cfg: Flow steering rule to add
1715 * @action: Action to be taken as result of a classification hit
1717 * Return: '0' on Success; Error code otherwise.
1719 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1724 const struct dpni_rule_cfg *cfg,
1725 const struct dpni_fs_action_cfg *action)
1727 struct dpni_cmd_add_fs_entry *cmd_params;
1728 struct mc_command cmd = { 0 };
1730 /* prepare command */
1731 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1734 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1735 cmd_params->tc_id = tc_id;
1736 cmd_params->key_size = cfg->key_size;
1737 cmd_params->index = cpu_to_le16(index);
1738 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1739 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1740 cmd_params->options = cpu_to_le16(action->options);
1741 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1742 cmd_params->flc = cpu_to_le64(action->flc);
1744 /* send command to mc*/
1745 return mc_send_command(mc_io, &cmd);
1749 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1751 * @mc_io: Pointer to MC portal's I/O object
1752 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1753 * @token: Token of DPNI object
1754 * @tc_id: Traffic class selection (0-7)
1755 * @cfg: Flow steering rule to remove
1757 * Return: '0' on Success; Error code otherwise.
1759 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1763 const struct dpni_rule_cfg *cfg)
1765 struct dpni_cmd_remove_fs_entry *cmd_params;
1766 struct mc_command cmd = { 0 };
1768 /* prepare command */
1769 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1772 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1773 cmd_params->tc_id = tc_id;
1774 cmd_params->key_size = cfg->key_size;
1775 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1776 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1778 /* send command to mc*/
1779 return mc_send_command(mc_io, &cmd);
1783 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1785 * @mc_io: Pointer to MC portal's I/O object
1786 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1787 * @token: Token of DPNI object
1788 * @tc_id: Traffic class selection (0-7)
1790 * Return: '0' on Success; Error code otherwise.
1792 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1797 struct dpni_cmd_clear_fs_entries *cmd_params;
1798 struct mc_command cmd = { 0 };
1800 /* prepare command */
1801 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1804 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1805 cmd_params->tc_id = tc_id;
1807 /* send command to mc*/
1808 return mc_send_command(mc_io, &cmd);
1812 * dpni_set_congestion_notification() - Set traffic class congestion
1813 * notification configuration
1814 * @mc_io: Pointer to MC portal's I/O object
1815 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1816 * @token: Token of DPNI object
1817 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1818 * @tc_id: Traffic class selection (0-7)
1819 * @cfg: congestion notification configuration
1821 * Return: '0' on Success; error code otherwise.
1823 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1826 enum dpni_queue_type qtype,
1828 const struct dpni_congestion_notification_cfg *cfg)
1830 struct dpni_cmd_set_congestion_notification *cmd_params;
1831 struct mc_command cmd = { 0 };
1833 /* prepare command */
1834 cmd.header = mc_encode_cmd_header(
1835 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1838 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1839 cmd_params->qtype = qtype;
1840 cmd_params->tc = tc_id;
1841 cmd_params->congestion_point = cfg->cg_point;
1842 cmd_params->cgid = (uint8_t)cfg->cgid;
1843 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1844 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1845 cmd_params->dest_priority = cfg->dest_cfg.priority;
1846 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1847 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1848 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1849 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1850 dpni_set_field(cmd_params->type_units,
1852 cfg->dest_cfg.dest_type);
1853 dpni_set_field(cmd_params->type_units,
1857 /* send command to mc*/
1858 return mc_send_command(mc_io, &cmd);
1862 * dpni_get_congestion_notification() - Get traffic class congestion
1863 * notification configuration
1864 * @mc_io: Pointer to MC portal's I/O object
1865 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1866 * @token: Token of DPNI object
1867 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1868 * @tc_id: Traffic class selection (0-7)
1869 * @cfg: congestion notification configuration
1871 * Return: '0' on Success; error code otherwise.
1873 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1876 enum dpni_queue_type qtype,
1878 struct dpni_congestion_notification_cfg *cfg)
1880 struct dpni_rsp_get_congestion_notification *rsp_params;
1881 struct dpni_cmd_get_congestion_notification *cmd_params;
1882 struct mc_command cmd = { 0 };
1885 /* prepare command */
1886 cmd.header = mc_encode_cmd_header(
1887 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
1890 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
1891 cmd_params->qtype = qtype;
1892 cmd_params->tc = tc_id;
1893 cmd_params->congestion_point = cfg->cg_point;
1894 cmd_params->cgid = cfg->cgid;
1896 /* send command to mc*/
1897 err = mc_send_command(mc_io, &cmd);
1901 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
1902 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
1903 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
1904 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
1905 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
1906 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
1907 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
1908 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
1909 cfg->dest_cfg.priority = rsp_params->dest_priority;
1910 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
1917 * dpni_get_api_version() - Get Data Path Network Interface API version
1918 * @mc_io: Pointer to MC portal's I/O object
1919 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1920 * @major_ver: Major version of data path network interface API
1921 * @minor_ver: Minor version of data path network interface API
1923 * Return: '0' on Success; Error code otherwise.
1925 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1927 uint16_t *major_ver,
1928 uint16_t *minor_ver)
1930 struct dpni_rsp_get_api_version *rsp_params;
1931 struct mc_command cmd = { 0 };
1934 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1938 err = mc_send_command(mc_io, &cmd);
1942 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1943 *major_ver = le16_to_cpu(rsp_params->major);
1944 *minor_ver = le16_to_cpu(rsp_params->minor);
1950 * dpni_set_queue() - Set queue parameters
1951 * @mc_io: Pointer to MC portal's I/O object
1952 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1953 * @token: Token of DPNI object
1954 * @qtype: Type of queue - all queue types are supported, although
1955 * the command is ignored for Tx
1956 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1957 * @index: Selects the specific queue out of the set allocated for the
1958 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1959 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
1960 * configuration options are set on the queue
1961 * @queue: Queue structure
1963 * Return: '0' on Success; Error code otherwise.
1965 int dpni_set_queue(struct fsl_mc_io *mc_io,
1968 enum dpni_queue_type qtype,
1972 const struct dpni_queue *queue)
1974 struct mc_command cmd = { 0 };
1975 struct dpni_cmd_set_queue *cmd_params;
1977 /* prepare command */
1978 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1981 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1982 cmd_params->qtype = qtype;
1983 cmd_params->tc = tc;
1984 cmd_params->index = index;
1985 cmd_params->options = options;
1986 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1987 cmd_params->dest_prio = queue->destination.priority;
1988 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1989 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1990 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1991 queue->destination.hold_active);
1992 cmd_params->flc = cpu_to_le64(queue->flc.value);
1993 cmd_params->user_context = cpu_to_le64(queue->user_context);
1994 cmd_params->cgid = queue->cgid;
1996 /* send command to mc */
1997 return mc_send_command(mc_io, &cmd);
2001 * dpni_get_queue() - Get queue parameters
2002 * @mc_io: Pointer to MC portal's I/O object
2003 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2004 * @token: Token of DPNI object
2005 * @qtype: Type of queue - all queue types are supported
2006 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2007 * @index: Selects the specific queue out of the set allocated for the
2008 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2009 * @queue: Queue configuration structure
2010 * @qid: Queue identification
2012 * Return: '0' on Success; Error code otherwise.
2014 int dpni_get_queue(struct fsl_mc_io *mc_io,
2017 enum dpni_queue_type qtype,
2020 struct dpni_queue *queue,
2021 struct dpni_queue_id *qid)
2023 struct mc_command cmd = { 0 };
2024 struct dpni_cmd_get_queue *cmd_params;
2025 struct dpni_rsp_get_queue *rsp_params;
2028 /* prepare command */
2029 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
2032 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
2033 cmd_params->qtype = qtype;
2034 cmd_params->tc = tc;
2035 cmd_params->index = index;
2037 /* send command to mc */
2038 err = mc_send_command(mc_io, &cmd);
2042 /* retrieve response parameters */
2043 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2044 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2045 queue->destination.priority = rsp_params->dest_prio;
2046 queue->destination.type = dpni_get_field(rsp_params->flags,
2048 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2050 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2052 queue->flc.value = le64_to_cpu(rsp_params->flc);
2053 queue->user_context = le64_to_cpu(rsp_params->user_context);
2054 qid->fqid = le32_to_cpu(rsp_params->fqid);
2055 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2056 if (dpni_get_field(rsp_params->flags, CGID_VALID))
2057 queue->cgid = rsp_params->cgid;
2065 * dpni_get_statistics() - Get DPNI statistics
2066 * @mc_io: Pointer to MC portal's I/O object
2067 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2068 * @token: Token of DPNI object
2069 * @page: Selects the statistics page to retrieve, see
2070 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
2071 * @param: Custom parameter for some pages used to select
2072 * a certain statistic source, for example the TC.
2073 * @stat: Structure containing the statistics
2075 * Return: '0' on Success; Error code otherwise.
2077 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2082 union dpni_statistics *stat)
2084 struct mc_command cmd = { 0 };
2085 struct dpni_cmd_get_statistics *cmd_params;
2086 struct dpni_rsp_get_statistics *rsp_params;
2089 /* prepare command */
2090 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2093 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2094 cmd_params->page_number = page;
2095 cmd_params->param = param;
2097 /* send command to mc */
2098 err = mc_send_command(mc_io, &cmd);
2102 /* retrieve response parameters */
2103 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2104 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2105 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2111 * dpni_reset_statistics() - Clears DPNI statistics
2112 * @mc_io: Pointer to MC portal's I/O object
2113 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2114 * @token: Token of DPNI object
2116 * Return: '0' on Success; Error code otherwise.
2118 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2122 struct mc_command cmd = { 0 };
2124 /* prepare command */
2125 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2129 /* send command to mc*/
2130 return mc_send_command(mc_io, &cmd);
2134 * dpni_set_taildrop() - Set taildrop per queue or TC
2136 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2137 * congestion notification or early drop (WRED) configuration previously applied
2140 * @mc_io: Pointer to MC portal's I/O object
2141 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2142 * @token: Token of DPNI object
2143 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in
2144 * combination with DPNI_QUEUE_RX.
2145 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2146 * @tc: Traffic class to apply this taildrop to
2147 * @q_index: Index of the queue if the DPNI supports multiple queues for
2148 * traffic distribution.
2149 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
2150 * @taildrop: Taildrop structure
2152 * Return: '0' on Success; Error code otherwise.
2154 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2157 enum dpni_congestion_point cg_point,
2158 enum dpni_queue_type qtype,
2161 struct dpni_taildrop *taildrop)
2163 struct mc_command cmd = { 0 };
2164 struct dpni_cmd_set_taildrop *cmd_params;
2166 /* prepare command */
2167 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2170 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2171 cmd_params->congestion_point = cg_point;
2172 cmd_params->qtype = qtype;
2173 cmd_params->tc = tc;
2174 cmd_params->index = index;
2175 cmd_params->units = taildrop->units;
2176 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2177 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2178 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2179 dpni_set_field(cmd_params->oal_hi,
2181 taildrop->oal >> DPNI_OAL_LO_SIZE);
2183 /* send command to mc */
2184 return mc_send_command(mc_io, &cmd);
2188 * dpni_get_taildrop() - Get taildrop information
2189 * @mc_io: Pointer to MC portal's I/O object
2190 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2191 * @token: Token of DPNI object
2192 * @cg_point: Congestion point
2193 * @q_type: Queue type on which the taildrop is configured.
2194 * Only Rx queues are supported for now
2195 * @tc: Traffic class to apply this taildrop to
2196 * @q_index: Index of the queue if the DPNI supports multiple queues for
2197 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2198 * @taildrop: Taildrop structure
2200 * Return: '0' on Success; Error code otherwise.
2202 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2205 enum dpni_congestion_point cg_point,
2206 enum dpni_queue_type qtype,
2209 struct dpni_taildrop *taildrop)
2211 struct mc_command cmd = { 0 };
2212 struct dpni_cmd_get_taildrop *cmd_params;
2213 struct dpni_rsp_get_taildrop *rsp_params;
2214 uint8_t oal_lo, oal_hi;
2217 /* prepare command */
2218 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2221 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2222 cmd_params->congestion_point = cg_point;
2223 cmd_params->qtype = qtype;
2224 cmd_params->tc = tc;
2225 cmd_params->index = index;
2227 /* send command to mc */
2228 err = mc_send_command(mc_io, &cmd);
2232 /* retrieve response parameters */
2233 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2234 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2235 taildrop->units = rsp_params->units;
2236 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2237 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2238 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2239 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2241 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2242 if (taildrop->oal >= 0x0800)
2243 taildrop->oal |= 0xF000;
2249 * dpni_set_opr() - Set Order Restoration configuration.
2250 * @mc_io: Pointer to MC portal's I/O object
2251 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2252 * @token: Token of DPNI object
2253 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2254 * @index: Selects the specific queue out of the set allocated
2255 * for the same TC. Value must be in range 0 to
2257 * @options: Configuration mode options
2258 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2259 * @cfg: Configuration options for the OPR
2261 * Return: '0' on Success; Error code otherwise.
2263 int dpni_set_opr(struct fsl_mc_io *mc_io,
2269 struct opr_cfg *cfg)
2271 struct dpni_cmd_set_opr *cmd_params;
2272 struct mc_command cmd = { 0 };
2274 /* prepare command */
2275 cmd.header = mc_encode_cmd_header(
2279 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2280 cmd_params->tc_id = tc;
2281 cmd_params->index = index;
2282 cmd_params->options = options;
2283 cmd_params->oloe = cfg->oloe;
2284 cmd_params->oeane = cfg->oeane;
2285 cmd_params->olws = cfg->olws;
2286 cmd_params->oa = cfg->oa;
2287 cmd_params->oprrws = cfg->oprrws;
2289 /* send command to mc*/
2290 return mc_send_command(mc_io, &cmd);
2294 * dpni_get_opr() - Retrieve Order Restoration config and query.
2295 * @mc_io: Pointer to MC portal's I/O object
2296 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2297 * @token: Token of DPNI object
2298 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2299 * @index: Selects the specific queue out of the set allocated
2300 * for the same TC. Value must be in range 0 to
2302 * @cfg: Returned OPR configuration
2303 * @qry: Returned OPR query
2305 * Return: '0' on Success; Error code otherwise.
2307 int dpni_get_opr(struct fsl_mc_io *mc_io,
2312 struct opr_cfg *cfg,
2313 struct opr_qry *qry)
2315 struct dpni_rsp_get_opr *rsp_params;
2316 struct dpni_cmd_get_opr *cmd_params;
2317 struct mc_command cmd = { 0 };
2320 /* prepare command */
2321 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2324 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2325 cmd_params->index = index;
2326 cmd_params->tc_id = tc;
2328 /* send command to mc*/
2329 err = mc_send_command(mc_io, &cmd);
2333 /* retrieve response parameters */
2334 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2335 cfg->oloe = rsp_params->oloe;
2336 cfg->oeane = rsp_params->oeane;
2337 cfg->olws = rsp_params->olws;
2338 cfg->oa = rsp_params->oa;
2339 cfg->oprrws = rsp_params->oprrws;
2340 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2341 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2342 qry->nesn = le16_to_cpu(rsp_params->nesn);
2343 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2344 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2345 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2346 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2347 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2348 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2349 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2350 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2351 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2357 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2358 * @mc_io: Pointer to MC portal's I/O object
2359 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2360 * @token: Token of DPNI object
2361 * @cfg: Distribution configuration
2362 * If the FS is already enabled with a previous call the classification
2363 * key will be changed but all the table rules are kept. If the
2364 * existing rules do not match the key the results will not be
2365 * predictable. It is the user responsibility to keep key integrity
2366 * If cfg.enable is set to 1 the command will create a flow steering table
2367 * and will classify packets according to this table. The packets
2368 * that miss all the table rules will be classified according to
2369 * settings made in dpni_set_rx_hash_dist()
2370 * If cfg.enable is set to 0 the command will clear flow steering table. The
2371 * packets will be classified according to settings made in
2372 * dpni_set_rx_hash_dist()
2374 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2375 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2377 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2378 struct mc_command cmd = { 0 };
2380 /* prepare command */
2381 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2384 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2385 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2386 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2387 cmd_params->tc = cfg->tc;
2388 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2389 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2391 /* send command to mc*/
2392 return mc_send_command(mc_io, &cmd);
2396 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2397 * @mc_io: Pointer to MC portal's I/O object
2398 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2399 * @token: Token of DPNI object
2400 * @cfg: Distribution configuration
2401 * If cfg.enable is set to 1 the packets will be classified using a hash
2402 * function based on the key received in cfg.key_cfg_iova parameter
2403 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2404 * dpni_set_rx_dist_default_queue() call
2406 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2407 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2409 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2410 struct mc_command cmd = { 0 };
2412 /* prepare command */
2413 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2416 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2417 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2418 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2419 cmd_params->tc_id = cfg->tc;
2420 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2422 /* send command to mc*/
2423 return mc_send_command(mc_io, &cmd);
2427 * dpni_add_custom_tpid() - Configures a distinct Ethertype value
2428 * (or TPID value) to indicate VLAN tag in addition to the common
2429 * TPID values 0x8100 and 0x88A8
2430 * @mc_io: Pointer to MC portal's I/O object
2431 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2432 * @token: Token of DPNI object
2433 * @tpid: New value for TPID
2435 * Only two custom values are accepted. If the function is called for the third
2436 * time it will return error.
2437 * To replace an existing value use dpni_remove_custom_tpid() to remove
2438 * a previous TPID and after that use again the function.
2440 * Return: '0' on Success; Error code otherwise.
2442 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2443 uint16_t token, uint16_t tpid)
2445 struct dpni_cmd_add_custom_tpid *cmd_params;
2446 struct mc_command cmd = { 0 };
2448 /* prepare command */
2449 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
2452 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
2453 cmd_params->tpid = cpu_to_le16(tpid);
2455 /* send command to mc*/
2456 return mc_send_command(mc_io, &cmd);
2460 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
2461 * previously with dpni_add_custom_tpid()
2462 * @mc_io: Pointer to MC portal's I/O object
2463 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2464 * @token: Token of DPNI object
2465 * @tpid: New value for TPID
2467 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
2470 * Return: '0' on Success; Error code otherwise.
2472 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2473 uint16_t token, uint16_t tpid)
2475 struct dpni_cmd_remove_custom_tpid *cmd_params;
2476 struct mc_command cmd = { 0 };
2478 /* prepare command */
2479 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
2482 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
2483 cmd_params->tpid = cpu_to_le16(tpid);
2485 /* send command to mc*/
2486 return mc_send_command(mc_io, &cmd);
2490 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured
2491 * to detect 802.1q frames
2492 * @mc_io: Pointer to MC portal's I/O object
2493 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2494 * @token: Token of DPNI object
2495 * @tpid: TPID values. Only nonzero members of the structure are valid.
2497 * Return: '0' on Success; Error code otherwise.
2499 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2500 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
2502 struct dpni_rsp_get_custom_tpid *rsp_params;
2503 struct mc_command cmd = { 0 };
2506 /* prepare command */
2507 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
2511 /* send command to mc*/
2512 err = mc_send_command(mc_io, &cmd);
2516 /* read command response */
2517 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
2518 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
2519 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
2524 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
2527 struct dpni_load_ss_cfg *cfg)
2529 struct dpni_load_sw_sequence *cmd_params;
2530 struct mc_command cmd = { 0 };
2532 /* prepare command */
2533 cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE,
2536 cmd_params = (struct dpni_load_sw_sequence *)cmd.params;
2537 cmd_params->dest = cfg->dest;
2538 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2539 cmd_params->ss_size = cpu_to_le16(cfg->ss_size);
2540 cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova);
2542 /* send command to mc*/
2543 return mc_send_command(mc_io, &cmd);
2546 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
2549 struct dpni_enable_ss_cfg *cfg)
2551 struct dpni_enable_sw_sequence *cmd_params;
2552 struct mc_command cmd = { 0 };
2554 /* prepare command */
2555 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE,
2558 cmd_params = (struct dpni_enable_sw_sequence *)cmd.params;
2559 cmd_params->dest = cfg->dest;
2560 cmd_params->set_start = cfg->set_start;
2561 cmd_params->hxs = cpu_to_le16(cfg->hxs);
2562 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2563 cmd_params->param_offset = cfg->param_offset;
2564 cmd_params->param_size = cfg->param_size;
2565 cmd_params->param_iova = cpu_to_le64(cfg->param_iova);
2567 /* send command to mc*/
2568 return mc_send_command(mc_io, &cmd);
2572 * dpni_get_sw_sequence_layout() - Get the soft sequence layout
2573 * @mc_io: Pointer to MC portal's I/O object
2574 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2575 * @token: Token of DPNI object
2576 * @src: Source of the layout (WRIOP Rx or Tx)
2577 * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory
2579 * warning: After calling this function, call dpni_extract_sw_sequence_layout()
2580 * to get the layout.
2582 * Return: '0' on Success; error code otherwise.
2584 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
2587 enum dpni_soft_sequence_dest src,
2588 uint64_t ss_layout_iova)
2590 struct dpni_get_sw_sequence_layout *cmd_params;
2591 struct mc_command cmd = { 0 };
2593 /* prepare command */
2594 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT,
2598 cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params;
2599 cmd_params->src = src;
2600 cmd_params->layout_iova = cpu_to_le64(ss_layout_iova);
2602 /* send command to mc*/
2603 return mc_send_command(mc_io, &cmd);
2607 * dpni_extract_sw_sequence_layout() - extract the software sequence layout
2608 * @layout: software sequence layout
2609 * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it
2612 * This function has to be called after dpni_get_sw_sequence_layout
2615 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
2616 const uint8_t *sw_sequence_layout_buf)
2618 const struct dpni_sw_sequence_layout_entry *ext_params;
2620 uint16_t ss_size, ss_offset;
2622 ext_params = (const struct dpni_sw_sequence_layout_entry *)
2623 sw_sequence_layout_buf;
2625 for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) {
2626 ss_offset = le16_to_cpu(ext_params[i].ss_offset);
2627 ss_size = le16_to_cpu(ext_params[i].ss_size);
2629 if (ss_offset == 0 && ss_size == 0) {
2634 layout->ss[i].ss_offset = ss_offset;
2635 layout->ss[i].ss_size = ss_size;
2636 layout->ss[i].param_offset = ext_params[i].param_offset;
2637 layout->ss[i].param_size = ext_params[i].param_size;