1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2020 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_tx_shaping() - Set the transmit shaping
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 * @tx_cr_shaper: TX committed rate shaping configuration
958 * @tx_er_shaper: TX excess rate shaping configuration
959 * @coupled: Committed and excess rate shapers are coupled
961 * Return: '0' on Success; Error code otherwise.
963 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
966 const struct dpni_tx_shaping_cfg *tx_cr_shaper,
967 const struct dpni_tx_shaping_cfg *tx_er_shaper,
970 struct dpni_cmd_set_tx_shaping *cmd_params;
971 struct mc_command cmd = { 0 };
973 /* prepare command */
974 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
977 cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
978 cmd_params->tx_cr_max_burst_size =
979 cpu_to_le16(tx_cr_shaper->max_burst_size);
980 cmd_params->tx_er_max_burst_size =
981 cpu_to_le16(tx_er_shaper->max_burst_size);
982 cmd_params->tx_cr_rate_limit =
983 cpu_to_le32(tx_cr_shaper->rate_limit);
984 cmd_params->tx_er_rate_limit =
985 cpu_to_le32(tx_er_shaper->rate_limit);
986 dpni_set_field(cmd_params->coupled, COUPLED, coupled);
988 /* send command to mc*/
989 return mc_send_command(mc_io, &cmd);
993 * dpni_set_max_frame_length() - Set the maximum received frame length.
994 * @mc_io: Pointer to MC portal's I/O object
995 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
996 * @token: Token of DPNI object
997 * @max_frame_length: Maximum received frame length (in bytes);
998 * frame is discarded if its length exceeds this value
1000 * Return: '0' on Success; Error code otherwise.
1002 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
1005 uint16_t max_frame_length)
1007 struct mc_command cmd = { 0 };
1008 struct dpni_cmd_set_max_frame_length *cmd_params;
1010 /* prepare command */
1011 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
1014 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
1015 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
1017 /* send command to mc*/
1018 return mc_send_command(mc_io, &cmd);
1022 * dpni_get_max_frame_length() - Get the maximum received frame length.
1023 * @mc_io: Pointer to MC portal's I/O object
1024 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1025 * @token: Token of DPNI object
1026 * @max_frame_length: Maximum received frame length (in bytes);
1027 * frame is discarded if its length exceeds this value
1029 * Return: '0' on Success; Error code otherwise.
1031 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
1034 uint16_t *max_frame_length)
1036 struct mc_command cmd = { 0 };
1037 struct dpni_rsp_get_max_frame_length *rsp_params;
1040 /* prepare command */
1041 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1045 /* send command to mc*/
1046 err = mc_send_command(mc_io, &cmd);
1050 /* retrieve response parameters */
1051 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1052 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1058 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1059 * @mc_io: Pointer to MC portal's I/O object
1060 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1061 * @token: Token of DPNI object
1062 * @en: Set to '1' to enable; '0' to disable
1064 * Return: '0' on Success; Error code otherwise.
1066 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1071 struct mc_command cmd = { 0 };
1072 struct dpni_cmd_set_multicast_promisc *cmd_params;
1074 /* prepare command */
1075 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1078 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1079 dpni_set_field(cmd_params->enable, ENABLE, en);
1081 /* send command to mc*/
1082 return mc_send_command(mc_io, &cmd);
1086 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1087 * @mc_io: Pointer to MC portal's I/O object
1088 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1089 * @token: Token of DPNI object
1090 * @en: Returns '1' if enabled; '0' otherwise
1092 * Return: '0' on Success; Error code otherwise.
1094 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1099 struct mc_command cmd = { 0 };
1100 struct dpni_rsp_get_multicast_promisc *rsp_params;
1103 /* prepare command */
1104 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1108 /* send command to mc*/
1109 err = mc_send_command(mc_io, &cmd);
1113 /* retrieve response parameters */
1114 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1115 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1121 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1122 * @mc_io: Pointer to MC portal's I/O object
1123 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1124 * @token: Token of DPNI object
1125 * @en: Set to '1' to enable; '0' to disable
1127 * Return: '0' on Success; Error code otherwise.
1129 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1134 struct mc_command cmd = { 0 };
1135 struct dpni_cmd_set_unicast_promisc *cmd_params;
1137 /* prepare command */
1138 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1141 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1142 dpni_set_field(cmd_params->enable, ENABLE, en);
1144 /* send command to mc*/
1145 return mc_send_command(mc_io, &cmd);
1149 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1150 * @mc_io: Pointer to MC portal's I/O object
1151 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1152 * @token: Token of DPNI object
1153 * @en: Returns '1' if enabled; '0' otherwise
1155 * Return: '0' on Success; Error code otherwise.
1157 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1162 struct mc_command cmd = { 0 };
1163 struct dpni_rsp_get_unicast_promisc *rsp_params;
1166 /* prepare command */
1167 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1171 /* send command to mc*/
1172 err = mc_send_command(mc_io, &cmd);
1176 /* retrieve response parameters */
1177 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1178 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1184 * dpni_set_primary_mac_addr() - Set the primary MAC address
1185 * @mc_io: Pointer to MC portal's I/O object
1186 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1187 * @token: Token of DPNI object
1188 * @mac_addr: MAC address to set as primary address
1190 * Return: '0' on Success; Error code otherwise.
1192 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1195 const uint8_t mac_addr[6])
1197 struct mc_command cmd = { 0 };
1198 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1201 /* prepare command */
1202 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1205 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1206 for (i = 0; i < 6; i++)
1207 cmd_params->mac_addr[i] = mac_addr[5 - i];
1209 /* send command to mc*/
1210 return mc_send_command(mc_io, &cmd);
1214 * dpni_get_primary_mac_addr() - Get the primary MAC address
1215 * @mc_io: Pointer to MC portal's I/O object
1216 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1217 * @token: Token of DPNI object
1218 * @mac_addr: Returned MAC address
1220 * Return: '0' on Success; Error code otherwise.
1222 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1225 uint8_t mac_addr[6])
1227 struct mc_command cmd = { 0 };
1228 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1231 /* prepare command */
1232 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1236 /* send command to mc*/
1237 err = mc_send_command(mc_io, &cmd);
1241 /* retrieve response parameters */
1242 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1243 for (i = 0; i < 6; i++)
1244 mac_addr[5 - i] = rsp_params->mac_addr[i];
1250 * dpni_add_mac_addr() - Add MAC address filter
1251 * @mc_io: Pointer to MC portal's I/O object
1252 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1253 * @token: Token of DPNI object
1254 * @mac_addr: MAC address to add
1255 * @flags : 0 - tc_id and flow_id will be ignored.
1256 * Pkt with this mac_id will be passed to the next
1257 * classification stages
1258 * DPNI_MAC_SET_QUEUE_ACTION
1259 * Pkt with this mac will be forward directly to
1260 * queue defined by the tc_id and flow_id
1261 * @tc_id : Traffic class selection (0-7)
1262 * @flow_id : Selects the specific queue out of the set allocated for the
1263 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1264 * Return: '0' on Success; Error code otherwise.
1266 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1269 const uint8_t mac_addr[6],
1274 struct mc_command cmd = { 0 };
1275 struct dpni_cmd_add_mac_addr *cmd_params;
1278 /* prepare command */
1279 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1282 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1283 cmd_params->flags = flags;
1284 cmd_params->tc_id = tc_id;
1285 cmd_params->fq_id = flow_id;
1287 for (i = 0; i < 6; i++)
1288 cmd_params->mac_addr[i] = mac_addr[5 - i];
1290 /* send command to mc*/
1291 return mc_send_command(mc_io, &cmd);
1295 * dpni_remove_mac_addr() - Remove MAC address filter
1296 * @mc_io: Pointer to MC portal's I/O object
1297 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1298 * @token: Token of DPNI object
1299 * @mac_addr: MAC address to remove
1301 * Return: '0' on Success; Error code otherwise.
1303 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1306 const uint8_t mac_addr[6])
1308 struct mc_command cmd = { 0 };
1309 struct dpni_cmd_remove_mac_addr *cmd_params;
1312 /* prepare command */
1313 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1316 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1317 for (i = 0; i < 6; i++)
1318 cmd_params->mac_addr[i] = mac_addr[5 - i];
1320 /* send command to mc*/
1321 return mc_send_command(mc_io, &cmd);
1325 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1326 * @mc_io: Pointer to MC portal's I/O object
1327 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1328 * @token: Token of DPNI object
1329 * @unicast: Set to '1' to clear unicast addresses
1330 * @multicast: Set to '1' to clear multicast addresses
1332 * The primary MAC address is not cleared by this operation.
1334 * Return: '0' on Success; Error code otherwise.
1336 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1342 struct mc_command cmd = { 0 };
1343 struct dpni_cmd_clear_mac_filters *cmd_params;
1345 /* prepare command */
1346 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1349 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1350 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1351 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1353 /* send command to mc*/
1354 return mc_send_command(mc_io, &cmd);
1358 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1359 * port the DPNI is attached to
1360 * @mc_io: Pointer to MC portal's I/O object
1361 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1362 * @token: Token of DPNI object
1363 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1365 * The primary MAC address is not cleared by this operation.
1367 * Return: '0' on Success; Error code otherwise.
1369 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1372 uint8_t mac_addr[6])
1374 struct mc_command cmd = { 0 };
1375 struct dpni_rsp_get_port_mac_addr *rsp_params;
1378 /* prepare command */
1379 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1383 /* send command to mc*/
1384 err = mc_send_command(mc_io, &cmd);
1388 /* retrieve response parameters */
1389 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1390 for (i = 0; i < 6; i++)
1391 mac_addr[5 - i] = rsp_params->mac_addr[i];
1397 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
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 * @en: Set to '1' to enable; '0' to disable
1403 * Return: '0' on Success; Error code otherwise.
1405 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1410 struct dpni_cmd_enable_vlan_filter *cmd_params;
1411 struct mc_command cmd = { 0 };
1413 /* prepare command */
1414 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1417 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1418 dpni_set_field(cmd_params->en, ENABLE, en);
1420 /* send command to mc*/
1421 return mc_send_command(mc_io, &cmd);
1425 * dpni_add_vlan_id() - Add VLAN ID filter
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
1429 * @vlan_id: VLAN ID to add
1430 * @flags: 0 - tc_id and flow_id will be ignored.
1431 * Pkt with this vlan_id will be passed to the next
1432 * classification stages
1433 * DPNI_VLAN_SET_QUEUE_ACTION
1434 * Pkt with this vlan_id will be forward directly to
1435 * queue defined by the tc_id and flow_id
1437 * @tc_id: Traffic class selection (0-7)
1438 * @flow_id: Selects the specific queue out of the set allocated for the
1439 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1441 * Return: '0' on Success; Error code otherwise.
1443 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1451 struct dpni_cmd_vlan_id *cmd_params;
1452 struct mc_command cmd = { 0 };
1454 /* prepare command */
1455 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1458 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1459 cmd_params->flags = flags;
1460 cmd_params->tc_id = tc_id;
1461 cmd_params->flow_id = flow_id;
1462 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1464 /* send command to mc*/
1465 return mc_send_command(mc_io, &cmd);
1469 * dpni_remove_vlan_id() - Remove VLAN ID filter
1470 * @mc_io: Pointer to MC portal's I/O object
1471 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1472 * @token: Token of DPNI object
1473 * @vlan_id: VLAN ID to remove
1475 * Return: '0' on Success; Error code otherwise.
1477 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1482 struct dpni_cmd_vlan_id *cmd_params;
1483 struct mc_command cmd = { 0 };
1485 /* prepare command */
1486 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1489 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1490 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1492 /* send command to mc*/
1493 return mc_send_command(mc_io, &cmd);
1497 * dpni_clear_vlan_filters() - Clear all VLAN filters
1498 * @mc_io: Pointer to MC portal's I/O object
1499 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1500 * @token: Token of DPNI object
1502 * Return: '0' on Success; Error code otherwise.
1504 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1508 struct mc_command cmd = { 0 };
1510 /* prepare command */
1511 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1515 /* send command to mc*/
1516 return mc_send_command(mc_io, &cmd);
1520 * dpni_set_tx_priorities() - Set transmission TC priority configuration
1521 * @mc_io: Pointer to MC portal's I/O object
1522 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1523 * @token: Token of DPNI object
1524 * @cfg: Transmission selection configuration
1526 * warning: Allowed only when DPNI is disabled
1528 * Return: '0' on Success; Error code otherwise.
1530 int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
1533 const struct dpni_tx_priorities_cfg *cfg)
1535 struct dpni_cmd_set_tx_priorities *cmd_params;
1536 struct mc_command cmd = { 0 };
1539 /* prepare command */
1540 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES,
1543 cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params;
1544 dpni_set_field(cmd_params->flags,
1546 cfg->separate_groups);
1547 cmd_params->prio_group_A = cfg->prio_group_A;
1548 cmd_params->prio_group_B = cfg->prio_group_B;
1550 for (i = 0; i + 1 < DPNI_MAX_TC; i = i + 2) {
1551 dpni_set_field(cmd_params->modes[i / 2],
1553 cfg->tc_sched[i].mode);
1554 dpni_set_field(cmd_params->modes[i / 2],
1556 cfg->tc_sched[i + 1].mode);
1559 for (i = 0; i < DPNI_MAX_TC; i++) {
1560 cmd_params->delta_bandwidth[i] =
1561 cpu_to_le16(cfg->tc_sched[i].delta_bandwidth);
1564 /* send command to mc*/
1565 return mc_send_command(mc_io, &cmd);
1569 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1570 * @mc_io: Pointer to MC portal's I/O object
1571 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1572 * @token: Token of DPNI object
1573 * @tc_id: Traffic class selection (0-7)
1574 * @cfg: Traffic class distribution configuration
1576 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1577 * first to prepare the key_cfg_iova parameter
1579 * Return: '0' on Success; error code otherwise.
1581 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1585 const struct dpni_rx_tc_dist_cfg *cfg)
1587 struct mc_command cmd = { 0 };
1588 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1590 /* prepare command */
1591 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1594 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1595 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1596 cmd_params->tc_id = tc_id;
1597 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1598 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1599 dpni_set_field(cmd_params->flags,
1602 dpni_set_field(cmd_params->flags,
1604 cfg->fs_cfg.miss_action);
1605 dpni_set_field(cmd_params->keep_hash_key,
1607 cfg->fs_cfg.keep_hash_key);
1608 dpni_set_field(cmd_params->keep_hash_key,
1610 cfg->fs_cfg.keep_entries);
1612 /* send command to mc*/
1613 return mc_send_command(mc_io, &cmd);
1617 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1618 * @mc_io: Pointer to MC portal's I/O object
1619 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1620 * @token: Token of DPNI object
1621 * @mode: Tx confirmation mode
1623 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1624 * selected at DPNI creation.
1625 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1626 * transmit confirmation (including the private confirmation queues), regardless
1627 * of previous settings; Note that in this case, Tx error frames are still
1628 * enqueued to the general transmit errors queue.
1629 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1630 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1631 * command will be ignored.
1633 * Return: '0' on Success; Error code otherwise.
1635 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1638 enum dpni_confirmation_mode mode)
1640 struct dpni_tx_confirmation_mode *cmd_params;
1641 struct mc_command cmd = { 0 };
1643 /* prepare command */
1644 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1647 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1648 cmd_params->confirmation_mode = mode;
1650 /* send command to mc*/
1651 return mc_send_command(mc_io, &cmd);
1655 * dpni_set_qos_table() - Set QoS mapping table
1656 * @mc_io: Pointer to MC portal's I/O object
1657 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1658 * @token: Token of DPNI object
1659 * @cfg: QoS table configuration
1661 * This function and all QoS-related functions require that
1662 *'max_tcs > 1' was set at DPNI creation.
1664 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1665 * prepare the key_cfg_iova parameter
1667 * Return: '0' on Success; Error code otherwise.
1669 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1672 const struct dpni_qos_tbl_cfg *cfg)
1674 struct dpni_cmd_set_qos_table *cmd_params;
1675 struct mc_command cmd = { 0 };
1677 /* prepare command */
1678 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1681 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1682 cmd_params->default_tc = cfg->default_tc;
1683 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1684 dpni_set_field(cmd_params->discard_on_miss,
1686 cfg->discard_on_miss);
1687 dpni_set_field(cmd_params->discard_on_miss,
1691 /* send command to mc*/
1692 return mc_send_command(mc_io, &cmd);
1696 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1697 * @mc_io: Pointer to MC portal's I/O object
1698 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1699 * @token: Token of DPNI object
1700 * @cfg: QoS rule to add
1701 * @tc_id: Traffic class selection (0-7)
1702 * @index: Location in the QoS table where to insert the entry.
1703 * Only relevant if MASKING is enabled for QoS classification on
1704 * this DPNI, it is ignored for exact match.
1706 * Return: '0' on Success; Error code otherwise.
1708 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1711 const struct dpni_rule_cfg *cfg,
1717 struct dpni_cmd_add_qos_entry *cmd_params;
1718 struct mc_command cmd = { 0 };
1720 /* prepare command */
1721 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1724 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1725 cmd_params->flags = flags;
1726 cmd_params->flow_id = flow_id;
1727 cmd_params->tc_id = tc_id;
1728 cmd_params->key_size = cfg->key_size;
1729 cmd_params->index = cpu_to_le16(index);
1730 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1731 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1733 /* send command to mc*/
1734 return mc_send_command(mc_io, &cmd);
1738 * dpni_remove_qos_entry() - Remove QoS mapping entry
1739 * @mc_io: Pointer to MC portal's I/O object
1740 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1741 * @token: Token of DPNI object
1742 * @cfg: QoS rule to remove
1744 * Return: '0' on Success; Error code otherwise.
1746 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1749 const struct dpni_rule_cfg *cfg)
1751 struct dpni_cmd_remove_qos_entry *cmd_params;
1752 struct mc_command cmd = { 0 };
1754 /* prepare command */
1755 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1758 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1759 cmd_params->key_size = cfg->key_size;
1760 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1761 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1763 /* send command to mc*/
1764 return mc_send_command(mc_io, &cmd);
1768 * dpni_clear_qos_table() - Clear all QoS mapping entries
1769 * @mc_io: Pointer to MC portal's I/O object
1770 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1771 * @token: Token of DPNI object
1773 * Following this function call, all frames are directed to
1774 * the default traffic class (0)
1776 * Return: '0' on Success; Error code otherwise.
1778 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1782 struct mc_command cmd = { 0 };
1784 /* prepare command */
1785 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1789 /* send command to mc*/
1790 return mc_send_command(mc_io, &cmd);
1794 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1795 * (to select a flow ID)
1796 * @mc_io: Pointer to MC portal's I/O object
1797 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1798 * @token: Token of DPNI object
1799 * @tc_id: Traffic class selection (0-7)
1800 * @index: Location in the QoS table where to insert the entry.
1801 * Only relevant if MASKING is enabled for QoS classification
1802 * on this DPNI, it is ignored for exact match.
1803 * @cfg: Flow steering rule to add
1804 * @action: Action to be taken as result of a classification hit
1806 * Return: '0' on Success; Error code otherwise.
1808 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1813 const struct dpni_rule_cfg *cfg,
1814 const struct dpni_fs_action_cfg *action)
1816 struct dpni_cmd_add_fs_entry *cmd_params;
1817 struct mc_command cmd = { 0 };
1819 /* prepare command */
1820 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1823 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1824 cmd_params->tc_id = tc_id;
1825 cmd_params->key_size = cfg->key_size;
1826 cmd_params->index = cpu_to_le16(index);
1827 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1828 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1829 cmd_params->options = cpu_to_le16(action->options);
1830 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1831 cmd_params->flc = cpu_to_le64(action->flc);
1833 /* send command to mc*/
1834 return mc_send_command(mc_io, &cmd);
1838 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1840 * @mc_io: Pointer to MC portal's I/O object
1841 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1842 * @token: Token of DPNI object
1843 * @tc_id: Traffic class selection (0-7)
1844 * @cfg: Flow steering rule to remove
1846 * Return: '0' on Success; Error code otherwise.
1848 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1852 const struct dpni_rule_cfg *cfg)
1854 struct dpni_cmd_remove_fs_entry *cmd_params;
1855 struct mc_command cmd = { 0 };
1857 /* prepare command */
1858 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1861 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1862 cmd_params->tc_id = tc_id;
1863 cmd_params->key_size = cfg->key_size;
1864 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1865 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1867 /* send command to mc*/
1868 return mc_send_command(mc_io, &cmd);
1872 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1874 * @mc_io: Pointer to MC portal's I/O object
1875 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1876 * @token: Token of DPNI object
1877 * @tc_id: Traffic class selection (0-7)
1879 * Return: '0' on Success; Error code otherwise.
1881 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1886 struct dpni_cmd_clear_fs_entries *cmd_params;
1887 struct mc_command cmd = { 0 };
1889 /* prepare command */
1890 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1893 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1894 cmd_params->tc_id = tc_id;
1896 /* send command to mc*/
1897 return mc_send_command(mc_io, &cmd);
1901 * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
1902 * @mc_io: Pointer to MC portal's I/O object
1903 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1904 * @token: Token of DPNI object
1905 * @tc_id: Traffic class selection (0-7)
1906 * @cfg: Traffic class policing configuration
1908 * Return: '0' on Success; error code otherwise.
1910 int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
1914 const struct dpni_rx_tc_policing_cfg *cfg)
1916 struct dpni_cmd_set_rx_tc_policing *cmd_params;
1917 struct mc_command cmd = { 0 };
1919 /* prepare command */
1920 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING,
1923 cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params;
1924 dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color);
1925 dpni_set_field(cmd_params->mode_color, MODE, cfg->mode);
1926 dpni_set_field(cmd_params->units, UNITS, cfg->units);
1927 cmd_params->options = cpu_to_le32(cfg->options);
1928 cmd_params->cir = cpu_to_le32(cfg->cir);
1929 cmd_params->cbs = cpu_to_le32(cfg->cbs);
1930 cmd_params->eir = cpu_to_le32(cfg->eir);
1931 cmd_params->ebs = cpu_to_le32(cfg->ebs);
1932 cmd_params->tc_id = tc_id;
1934 /* send command to mc*/
1935 return mc_send_command(mc_io, &cmd);
1939 * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration
1940 * @mc_io: Pointer to MC portal's I/O object
1941 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1942 * @token: Token of DPNI object
1943 * @tc_id: Traffic class selection (0-7)
1944 * @cfg: Traffic class policing configuration
1946 * Return: '0' on Success; error code otherwise.
1948 int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io,
1952 struct dpni_rx_tc_policing_cfg *cfg)
1954 struct dpni_rsp_get_rx_tc_policing *rsp_params;
1955 struct dpni_cmd_get_rx_tc_policing *cmd_params;
1956 struct mc_command cmd = { 0 };
1959 /* prepare command */
1960 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_TC_POLICING,
1963 cmd_params = (struct dpni_cmd_get_rx_tc_policing *)cmd.params;
1964 cmd_params->tc_id = tc_id;
1967 /* send command to mc*/
1968 err = mc_send_command(mc_io, &cmd);
1972 rsp_params = (struct dpni_rsp_get_rx_tc_policing *)cmd.params;
1973 cfg->options = le32_to_cpu(rsp_params->options);
1974 cfg->cir = le32_to_cpu(rsp_params->cir);
1975 cfg->cbs = le32_to_cpu(rsp_params->cbs);
1976 cfg->eir = le32_to_cpu(rsp_params->eir);
1977 cfg->ebs = le32_to_cpu(rsp_params->ebs);
1978 cfg->units = dpni_get_field(rsp_params->units, UNITS);
1979 cfg->mode = dpni_get_field(rsp_params->mode_color, MODE);
1980 cfg->default_color = dpni_get_field(rsp_params->mode_color, COLOR);
1986 * dpni_prepare_early_drop() - prepare an early drop.
1987 * @cfg: Early-drop configuration
1988 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
1990 * This function has to be called before dpni_set_rx_tc_early_drop or
1991 * dpni_set_tx_tc_early_drop
1994 void dpni_prepare_early_drop(const struct dpni_early_drop_cfg *cfg,
1995 uint8_t *early_drop_buf)
1997 struct dpni_early_drop *ext_params;
1999 ext_params = (struct dpni_early_drop *)early_drop_buf;
2001 dpni_set_field(ext_params->flags, DROP_ENABLE, cfg->enable);
2002 dpni_set_field(ext_params->flags, DROP_UNITS, cfg->units);
2003 ext_params->green_drop_probability = cfg->green.drop_probability;
2004 ext_params->green_max_threshold = cpu_to_le64(cfg->green.max_threshold);
2005 ext_params->green_min_threshold = cpu_to_le64(cfg->green.min_threshold);
2006 ext_params->yellow_drop_probability = cfg->yellow.drop_probability;
2007 ext_params->yellow_max_threshold =
2008 cpu_to_le64(cfg->yellow.max_threshold);
2009 ext_params->yellow_min_threshold =
2010 cpu_to_le64(cfg->yellow.min_threshold);
2011 ext_params->red_drop_probability = cfg->red.drop_probability;
2012 ext_params->red_max_threshold = cpu_to_le64(cfg->red.max_threshold);
2013 ext_params->red_min_threshold = cpu_to_le64(cfg->red.min_threshold);
2017 * dpni_extract_early_drop() - extract the early drop configuration.
2018 * @cfg: Early-drop configuration
2019 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2021 * This function has to be called after dpni_get_rx_tc_early_drop or
2022 * dpni_get_tx_tc_early_drop
2025 void dpni_extract_early_drop(struct dpni_early_drop_cfg *cfg,
2026 const uint8_t *early_drop_buf)
2028 const struct dpni_early_drop *ext_params;
2030 ext_params = (const struct dpni_early_drop *)early_drop_buf;
2032 cfg->enable = dpni_get_field(ext_params->flags, DROP_ENABLE);
2033 cfg->units = dpni_get_field(ext_params->flags, DROP_UNITS);
2034 cfg->green.drop_probability = ext_params->green_drop_probability;
2035 cfg->green.max_threshold = le64_to_cpu(ext_params->green_max_threshold);
2036 cfg->green.min_threshold = le64_to_cpu(ext_params->green_min_threshold);
2037 cfg->yellow.drop_probability = ext_params->yellow_drop_probability;
2038 cfg->yellow.max_threshold =
2039 le64_to_cpu(ext_params->yellow_max_threshold);
2040 cfg->yellow.min_threshold =
2041 le64_to_cpu(ext_params->yellow_min_threshold);
2042 cfg->red.drop_probability = ext_params->red_drop_probability;
2043 cfg->red.max_threshold = le64_to_cpu(ext_params->red_max_threshold);
2044 cfg->red.min_threshold = le64_to_cpu(ext_params->red_min_threshold);
2048 * dpni_set_early_drop() - Set traffic class early-drop configuration
2049 * @mc_io: Pointer to MC portal's I/O object
2050 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2051 * @token: Token of DPNI object
2052 * @qtype: Type of queue - only Rx and Tx types are supported
2053 * @tc_id: Traffic class selection (0-7)
2054 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory filled
2055 * with the early-drop configuration by calling dpni_prepare_early_drop()
2057 * warning: Before calling this function, call dpni_prepare_early_drop() to
2058 * prepare the early_drop_iova parameter
2060 * Return: '0' on Success; error code otherwise.
2062 int dpni_set_early_drop(struct fsl_mc_io *mc_io,
2065 enum dpni_queue_type qtype,
2067 uint64_t early_drop_iova)
2069 struct dpni_cmd_early_drop *cmd_params;
2070 struct mc_command cmd = { 0 };
2072 /* prepare command */
2073 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_EARLY_DROP,
2076 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2077 cmd_params->qtype = qtype;
2078 cmd_params->tc = tc_id;
2079 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2081 /* send command to mc*/
2082 return mc_send_command(mc_io, &cmd);
2086 * dpni_get_early_drop() - Get Rx traffic class early-drop configuration
2087 * @mc_io: Pointer to MC portal's I/O object
2088 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2089 * @token: Token of DPNI object
2090 * @qtype: Type of queue - only Rx and Tx types are supported
2091 * @tc_id: Traffic class selection (0-7)
2092 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory
2094 * warning: After calling this function, call dpni_extract_early_drop() to
2095 * get the early drop configuration
2097 * Return: '0' on Success; error code otherwise.
2099 int dpni_get_early_drop(struct fsl_mc_io *mc_io,
2102 enum dpni_queue_type qtype,
2104 uint64_t early_drop_iova)
2106 struct dpni_cmd_early_drop *cmd_params;
2107 struct mc_command cmd = { 0 };
2109 /* prepare command */
2110 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_EARLY_DROP,
2113 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2114 cmd_params->qtype = qtype;
2115 cmd_params->tc = tc_id;
2116 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2118 /* send command to mc*/
2119 return mc_send_command(mc_io, &cmd);
2123 * dpni_set_congestion_notification() - Set traffic class congestion
2124 * notification configuration
2125 * @mc_io: Pointer to MC portal's I/O object
2126 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2127 * @token: Token of DPNI object
2128 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2129 * @tc_id: Traffic class selection (0-7)
2130 * @cfg: congestion notification configuration
2132 * Return: '0' on Success; error code otherwise.
2134 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
2137 enum dpni_queue_type qtype,
2139 const struct dpni_congestion_notification_cfg *cfg)
2141 struct dpni_cmd_set_congestion_notification *cmd_params;
2142 struct mc_command cmd = { 0 };
2144 /* prepare command */
2145 cmd.header = mc_encode_cmd_header(
2146 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
2149 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
2150 cmd_params->qtype = qtype;
2151 cmd_params->tc = tc_id;
2152 cmd_params->congestion_point = cfg->cg_point;
2153 cmd_params->cgid = (uint8_t)cfg->cgid;
2154 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
2155 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
2156 cmd_params->dest_priority = cfg->dest_cfg.priority;
2157 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
2158 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
2159 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
2160 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
2161 dpni_set_field(cmd_params->type_units,
2163 cfg->dest_cfg.dest_type);
2164 dpni_set_field(cmd_params->type_units,
2168 /* send command to mc*/
2169 return mc_send_command(mc_io, &cmd);
2173 * dpni_get_congestion_notification() - Get traffic class congestion
2174 * notification configuration
2175 * @mc_io: Pointer to MC portal's I/O object
2176 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2177 * @token: Token of DPNI object
2178 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2179 * @tc_id: Traffic class selection (0-7)
2180 * @cfg: congestion notification configuration
2182 * Return: '0' on Success; error code otherwise.
2184 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
2187 enum dpni_queue_type qtype,
2189 struct dpni_congestion_notification_cfg *cfg)
2191 struct dpni_rsp_get_congestion_notification *rsp_params;
2192 struct dpni_cmd_get_congestion_notification *cmd_params;
2193 struct mc_command cmd = { 0 };
2196 /* prepare command */
2197 cmd.header = mc_encode_cmd_header(
2198 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
2201 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
2202 cmd_params->qtype = qtype;
2203 cmd_params->tc = tc_id;
2204 cmd_params->congestion_point = cfg->cg_point;
2205 cmd_params->cgid = cfg->cgid;
2207 /* send command to mc*/
2208 err = mc_send_command(mc_io, &cmd);
2212 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
2213 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
2214 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
2215 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
2216 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
2217 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
2218 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
2219 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
2220 cfg->dest_cfg.priority = rsp_params->dest_priority;
2221 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
2228 * dpni_get_api_version() - Get Data Path Network Interface API version
2229 * @mc_io: Pointer to MC portal's I/O object
2230 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2231 * @major_ver: Major version of data path network interface API
2232 * @minor_ver: Minor version of data path network interface API
2234 * Return: '0' on Success; Error code otherwise.
2236 int dpni_get_api_version(struct fsl_mc_io *mc_io,
2238 uint16_t *major_ver,
2239 uint16_t *minor_ver)
2241 struct dpni_rsp_get_api_version *rsp_params;
2242 struct mc_command cmd = { 0 };
2245 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
2249 err = mc_send_command(mc_io, &cmd);
2253 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
2254 *major_ver = le16_to_cpu(rsp_params->major);
2255 *minor_ver = le16_to_cpu(rsp_params->minor);
2261 * dpni_set_queue() - Set queue parameters
2262 * @mc_io: Pointer to MC portal's I/O object
2263 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2264 * @token: Token of DPNI object
2265 * @qtype: Type of queue - all queue types are supported, although
2266 * the command is ignored for Tx
2267 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2268 * @index: Selects the specific queue out of the set allocated for the
2269 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2270 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
2271 * configuration options are set on the queue
2272 * @queue: Queue structure
2274 * Return: '0' on Success; Error code otherwise.
2276 int dpni_set_queue(struct fsl_mc_io *mc_io,
2279 enum dpni_queue_type qtype,
2283 const struct dpni_queue *queue)
2285 struct mc_command cmd = { 0 };
2286 struct dpni_cmd_set_queue *cmd_params;
2288 /* prepare command */
2289 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
2292 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
2293 cmd_params->qtype = qtype;
2294 cmd_params->tc = tc;
2295 cmd_params->index = index;
2296 cmd_params->options = options;
2297 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
2298 cmd_params->dest_prio = queue->destination.priority;
2299 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
2300 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
2301 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
2302 queue->destination.hold_active);
2303 cmd_params->flc = cpu_to_le64(queue->flc.value);
2304 cmd_params->user_context = cpu_to_le64(queue->user_context);
2305 cmd_params->cgid = queue->cgid;
2307 /* send command to mc */
2308 return mc_send_command(mc_io, &cmd);
2312 * dpni_get_queue() - Get queue parameters
2313 * @mc_io: Pointer to MC portal's I/O object
2314 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2315 * @token: Token of DPNI object
2316 * @qtype: Type of queue - all queue types are supported
2317 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2318 * @index: Selects the specific queue out of the set allocated for the
2319 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2320 * @queue: Queue configuration structure
2321 * @qid: Queue identification
2323 * Return: '0' on Success; Error code otherwise.
2325 int dpni_get_queue(struct fsl_mc_io *mc_io,
2328 enum dpni_queue_type qtype,
2331 struct dpni_queue *queue,
2332 struct dpni_queue_id *qid)
2334 struct mc_command cmd = { 0 };
2335 struct dpni_cmd_get_queue *cmd_params;
2336 struct dpni_rsp_get_queue *rsp_params;
2339 /* prepare command */
2340 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
2343 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
2344 cmd_params->qtype = qtype;
2345 cmd_params->tc = tc;
2346 cmd_params->index = index;
2348 /* send command to mc */
2349 err = mc_send_command(mc_io, &cmd);
2353 /* retrieve response parameters */
2354 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2355 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2356 queue->destination.priority = rsp_params->dest_prio;
2357 queue->destination.type = dpni_get_field(rsp_params->flags,
2359 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2361 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2363 queue->flc.value = le64_to_cpu(rsp_params->flc);
2364 queue->user_context = le64_to_cpu(rsp_params->user_context);
2365 qid->fqid = le32_to_cpu(rsp_params->fqid);
2366 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2367 if (dpni_get_field(rsp_params->flags, CGID_VALID))
2368 queue->cgid = rsp_params->cgid;
2376 * dpni_get_statistics() - Get DPNI statistics
2377 * @mc_io: Pointer to MC portal's I/O object
2378 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2379 * @token: Token of DPNI object
2380 * @page: Selects the statistics page to retrieve, see
2381 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
2382 * @param: Custom parameter for some pages used to select
2383 * a certain statistic source, for example the TC.
2384 * @stat: Structure containing the statistics
2386 * Return: '0' on Success; Error code otherwise.
2388 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2393 union dpni_statistics *stat)
2395 struct mc_command cmd = { 0 };
2396 struct dpni_cmd_get_statistics *cmd_params;
2397 struct dpni_rsp_get_statistics *rsp_params;
2400 /* prepare command */
2401 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2404 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2405 cmd_params->page_number = page;
2406 cmd_params->param = param;
2408 /* send command to mc */
2409 err = mc_send_command(mc_io, &cmd);
2413 /* retrieve response parameters */
2414 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2415 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2416 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2422 * dpni_reset_statistics() - Clears DPNI statistics
2423 * @mc_io: Pointer to MC portal's I/O object
2424 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2425 * @token: Token of DPNI object
2427 * Return: '0' on Success; Error code otherwise.
2429 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2433 struct mc_command cmd = { 0 };
2435 /* prepare command */
2436 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2440 /* send command to mc*/
2441 return mc_send_command(mc_io, &cmd);
2445 * dpni_set_taildrop() - Set taildrop per queue or TC
2447 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2448 * congestion notification or early drop (WRED) configuration previously applied
2451 * @mc_io: Pointer to MC portal's I/O object
2452 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2453 * @token: Token of DPNI object
2454 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in
2455 * combination with DPNI_QUEUE_RX.
2456 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2457 * @tc: Traffic class to apply this taildrop to
2458 * @q_index: Index of the queue if the DPNI supports multiple queues for
2459 * traffic distribution.
2460 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
2461 * @taildrop: Taildrop structure
2463 * Return: '0' on Success; Error code otherwise.
2465 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2468 enum dpni_congestion_point cg_point,
2469 enum dpni_queue_type qtype,
2472 struct dpni_taildrop *taildrop)
2474 struct mc_command cmd = { 0 };
2475 struct dpni_cmd_set_taildrop *cmd_params;
2477 /* prepare command */
2478 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2481 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2482 cmd_params->congestion_point = cg_point;
2483 cmd_params->qtype = qtype;
2484 cmd_params->tc = tc;
2485 cmd_params->index = index;
2486 cmd_params->units = taildrop->units;
2487 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2488 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2489 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2490 dpni_set_field(cmd_params->oal_hi,
2492 taildrop->oal >> DPNI_OAL_LO_SIZE);
2494 /* send command to mc */
2495 return mc_send_command(mc_io, &cmd);
2499 * dpni_get_taildrop() - Get taildrop information
2500 * @mc_io: Pointer to MC portal's I/O object
2501 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2502 * @token: Token of DPNI object
2503 * @cg_point: Congestion point
2504 * @q_type: Queue type on which the taildrop is configured.
2505 * Only Rx queues are supported for now
2506 * @tc: Traffic class to apply this taildrop to
2507 * @q_index: Index of the queue if the DPNI supports multiple queues for
2508 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2509 * @taildrop: Taildrop structure
2511 * Return: '0' on Success; Error code otherwise.
2513 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2516 enum dpni_congestion_point cg_point,
2517 enum dpni_queue_type qtype,
2520 struct dpni_taildrop *taildrop)
2522 struct mc_command cmd = { 0 };
2523 struct dpni_cmd_get_taildrop *cmd_params;
2524 struct dpni_rsp_get_taildrop *rsp_params;
2525 uint8_t oal_lo, oal_hi;
2528 /* prepare command */
2529 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2532 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2533 cmd_params->congestion_point = cg_point;
2534 cmd_params->qtype = qtype;
2535 cmd_params->tc = tc;
2536 cmd_params->index = index;
2538 /* send command to mc */
2539 err = mc_send_command(mc_io, &cmd);
2543 /* retrieve response parameters */
2544 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2545 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2546 taildrop->units = rsp_params->units;
2547 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2548 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2549 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2550 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2552 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2553 if (taildrop->oal >= 0x0800)
2554 taildrop->oal |= 0xF000;
2560 * dpni_set_opr() - Set Order Restoration configuration.
2561 * @mc_io: Pointer to MC portal's I/O object
2562 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2563 * @token: Token of DPNI object
2564 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2565 * @index: Selects the specific queue out of the set allocated
2566 * for the same TC. Value must be in range 0 to
2568 * @options: Configuration mode options
2569 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2570 * @cfg: Configuration options for the OPR
2572 * Return: '0' on Success; Error code otherwise.
2574 int dpni_set_opr(struct fsl_mc_io *mc_io,
2580 struct opr_cfg *cfg)
2582 struct dpni_cmd_set_opr *cmd_params;
2583 struct mc_command cmd = { 0 };
2585 /* prepare command */
2586 cmd.header = mc_encode_cmd_header(
2590 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2591 cmd_params->tc_id = tc;
2592 cmd_params->index = index;
2593 cmd_params->options = options;
2594 cmd_params->oloe = cfg->oloe;
2595 cmd_params->oeane = cfg->oeane;
2596 cmd_params->olws = cfg->olws;
2597 cmd_params->oa = cfg->oa;
2598 cmd_params->oprrws = cfg->oprrws;
2600 /* send command to mc*/
2601 return mc_send_command(mc_io, &cmd);
2605 * dpni_get_opr() - Retrieve Order Restoration config and query.
2606 * @mc_io: Pointer to MC portal's I/O object
2607 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2608 * @token: Token of DPNI object
2609 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2610 * @index: Selects the specific queue out of the set allocated
2611 * for the same TC. Value must be in range 0 to
2613 * @cfg: Returned OPR configuration
2614 * @qry: Returned OPR query
2616 * Return: '0' on Success; Error code otherwise.
2618 int dpni_get_opr(struct fsl_mc_io *mc_io,
2623 struct opr_cfg *cfg,
2624 struct opr_qry *qry)
2626 struct dpni_rsp_get_opr *rsp_params;
2627 struct dpni_cmd_get_opr *cmd_params;
2628 struct mc_command cmd = { 0 };
2631 /* prepare command */
2632 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2635 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2636 cmd_params->index = index;
2637 cmd_params->tc_id = tc;
2639 /* send command to mc*/
2640 err = mc_send_command(mc_io, &cmd);
2644 /* retrieve response parameters */
2645 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2646 cfg->oloe = rsp_params->oloe;
2647 cfg->oeane = rsp_params->oeane;
2648 cfg->olws = rsp_params->olws;
2649 cfg->oa = rsp_params->oa;
2650 cfg->oprrws = rsp_params->oprrws;
2651 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2652 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2653 qry->nesn = le16_to_cpu(rsp_params->nesn);
2654 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2655 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2656 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2657 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2658 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2659 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2660 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2661 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2662 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2668 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2669 * @mc_io: Pointer to MC portal's I/O object
2670 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2671 * @token: Token of DPNI object
2672 * @cfg: Distribution configuration
2673 * If the FS is already enabled with a previous call the classification
2674 * key will be changed but all the table rules are kept. If the
2675 * existing rules do not match the key the results will not be
2676 * predictable. It is the user responsibility to keep key integrity
2677 * If cfg.enable is set to 1 the command will create a flow steering table
2678 * and will classify packets according to this table. The packets
2679 * that miss all the table rules will be classified according to
2680 * settings made in dpni_set_rx_hash_dist()
2681 * If cfg.enable is set to 0 the command will clear flow steering table. The
2682 * packets will be classified according to settings made in
2683 * dpni_set_rx_hash_dist()
2685 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2686 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2688 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2689 struct mc_command cmd = { 0 };
2691 /* prepare command */
2692 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2695 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2696 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2697 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2698 cmd_params->tc = cfg->tc;
2699 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2700 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2702 /* send command to mc*/
2703 return mc_send_command(mc_io, &cmd);
2707 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2708 * @mc_io: Pointer to MC portal's I/O object
2709 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2710 * @token: Token of DPNI object
2711 * @cfg: Distribution configuration
2712 * If cfg.enable is set to 1 the packets will be classified using a hash
2713 * function based on the key received in cfg.key_cfg_iova parameter
2714 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2715 * dpni_set_rx_dist_default_queue() call
2717 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2718 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2720 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2721 struct mc_command cmd = { 0 };
2723 /* prepare command */
2724 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2727 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2728 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2729 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2730 cmd_params->tc_id = cfg->tc;
2731 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2733 /* send command to mc*/
2734 return mc_send_command(mc_io, &cmd);
2738 * dpni_add_custom_tpid() - Configures a distinct Ethertype value
2739 * (or TPID value) to indicate VLAN tag in addition to the common
2740 * TPID values 0x8100 and 0x88A8
2741 * @mc_io: Pointer to MC portal's I/O object
2742 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2743 * @token: Token of DPNI object
2744 * @tpid: New value for TPID
2746 * Only two custom values are accepted. If the function is called for the third
2747 * time it will return error.
2748 * To replace an existing value use dpni_remove_custom_tpid() to remove
2749 * a previous TPID and after that use again the function.
2751 * Return: '0' on Success; Error code otherwise.
2753 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2754 uint16_t token, uint16_t tpid)
2756 struct dpni_cmd_add_custom_tpid *cmd_params;
2757 struct mc_command cmd = { 0 };
2759 /* prepare command */
2760 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
2763 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
2764 cmd_params->tpid = cpu_to_le16(tpid);
2766 /* send command to mc*/
2767 return mc_send_command(mc_io, &cmd);
2771 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
2772 * previously with dpni_add_custom_tpid()
2773 * @mc_io: Pointer to MC portal's I/O object
2774 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2775 * @token: Token of DPNI object
2776 * @tpid: New value for TPID
2778 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
2781 * Return: '0' on Success; Error code otherwise.
2783 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2784 uint16_t token, uint16_t tpid)
2786 struct dpni_cmd_remove_custom_tpid *cmd_params;
2787 struct mc_command cmd = { 0 };
2789 /* prepare command */
2790 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
2793 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
2794 cmd_params->tpid = cpu_to_le16(tpid);
2796 /* send command to mc*/
2797 return mc_send_command(mc_io, &cmd);
2801 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured
2802 * to detect 802.1q frames
2803 * @mc_io: Pointer to MC portal's I/O object
2804 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2805 * @token: Token of DPNI object
2806 * @tpid: TPID values. Only nonzero members of the structure are valid.
2808 * Return: '0' on Success; Error code otherwise.
2810 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2811 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
2813 struct dpni_rsp_get_custom_tpid *rsp_params;
2814 struct mc_command cmd = { 0 };
2817 /* prepare command */
2818 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
2822 /* send command to mc*/
2823 err = mc_send_command(mc_io, &cmd);
2827 /* read command response */
2828 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
2829 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
2830 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
2835 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
2838 struct dpni_load_ss_cfg *cfg)
2840 struct dpni_load_sw_sequence *cmd_params;
2841 struct mc_command cmd = { 0 };
2843 /* prepare command */
2844 cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE,
2847 cmd_params = (struct dpni_load_sw_sequence *)cmd.params;
2848 cmd_params->dest = cfg->dest;
2849 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2850 cmd_params->ss_size = cpu_to_le16(cfg->ss_size);
2851 cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova);
2853 /* send command to mc*/
2854 return mc_send_command(mc_io, &cmd);
2857 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
2860 struct dpni_enable_ss_cfg *cfg)
2862 struct dpni_enable_sw_sequence *cmd_params;
2863 struct mc_command cmd = { 0 };
2865 /* prepare command */
2866 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE,
2869 cmd_params = (struct dpni_enable_sw_sequence *)cmd.params;
2870 cmd_params->dest = cfg->dest;
2871 cmd_params->set_start = cfg->set_start;
2872 cmd_params->hxs = cpu_to_le16(cfg->hxs);
2873 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2874 cmd_params->param_offset = cfg->param_offset;
2875 cmd_params->param_size = cfg->param_size;
2876 cmd_params->param_iova = cpu_to_le64(cfg->param_iova);
2878 /* send command to mc*/
2879 return mc_send_command(mc_io, &cmd);
2883 * dpni_get_sw_sequence_layout() - Get the soft sequence layout
2884 * @mc_io: Pointer to MC portal's I/O object
2885 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2886 * @token: Token of DPNI object
2887 * @src: Source of the layout (WRIOP Rx or Tx)
2888 * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory
2890 * warning: After calling this function, call dpni_extract_sw_sequence_layout()
2891 * to get the layout.
2893 * Return: '0' on Success; error code otherwise.
2895 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
2898 enum dpni_soft_sequence_dest src,
2899 uint64_t ss_layout_iova)
2901 struct dpni_get_sw_sequence_layout *cmd_params;
2902 struct mc_command cmd = { 0 };
2904 /* prepare command */
2905 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT,
2909 cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params;
2910 cmd_params->src = src;
2911 cmd_params->layout_iova = cpu_to_le64(ss_layout_iova);
2913 /* send command to mc*/
2914 return mc_send_command(mc_io, &cmd);
2918 * dpni_extract_sw_sequence_layout() - extract the software sequence layout
2919 * @layout: software sequence layout
2920 * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it
2923 * This function has to be called after dpni_get_sw_sequence_layout
2926 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
2927 const uint8_t *sw_sequence_layout_buf)
2929 const struct dpni_sw_sequence_layout_entry *ext_params;
2931 uint16_t ss_size, ss_offset;
2933 ext_params = (const struct dpni_sw_sequence_layout_entry *)
2934 sw_sequence_layout_buf;
2936 for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) {
2937 ss_offset = le16_to_cpu(ext_params[i].ss_offset);
2938 ss_size = le16_to_cpu(ext_params[i].ss_size);
2940 if (ss_offset == 0 && ss_size == 0) {
2945 layout->ss[i].ss_offset = ss_offset;
2946 layout->ss[i].ss_size = ss_size;
2947 layout->ss[i].param_offset = ext_params[i].param_offset;
2948 layout->ss[i].param_size = ext_params[i].param_size;