1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2021 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;
129 cmd_params->num_opr = cfg->num_opr;
130 cmd_params->dist_key_size = cfg->dist_key_size;
131 cmd_params->num_channels = cfg->num_channels;
133 /* send command to mc*/
134 err = mc_send_command(mc_io, &cmd);
138 /* retrieve response parameters */
139 *obj_id = mc_cmd_read_object_id(&cmd);
145 * dpni_destroy() - Destroy the DPNI object and release all its resources.
146 * @mc_io: Pointer to MC portal's I/O object
147 * @dprc_token: Parent container token; '0' for default container
148 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
149 * @object_id: The object id; it must be a valid id within the container that
150 * created this object;
152 * The function accepts the authentication token of the parent container that
153 * created the object (not the one that currently owns the object). The object
154 * is searched within parent using the provided 'object_id'.
155 * All tokens to the object must be closed before calling destroy.
157 * Return: '0' on Success; error code otherwise.
159 int dpni_destroy(struct fsl_mc_io *mc_io,
164 struct dpni_cmd_destroy *cmd_params;
165 struct mc_command cmd = { 0 };
167 /* prepare command */
168 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
171 /* set object id to destroy */
172 cmd_params = (struct dpni_cmd_destroy *)cmd.params;
173 cmd_params->dpsw_id = cpu_to_le32(object_id);
175 /* send command to mc*/
176 return mc_send_command(mc_io, &cmd);
180 * dpni_set_pools() - Set buffer pools configuration
181 * @mc_io: Pointer to MC portal's I/O object
182 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
183 * @token: Token of DPNI object
184 * @cfg: Buffer pools configuration
186 * mandatory for DPNI operation
187 * warning:Allowed only when DPNI is disabled
189 * Return: '0' on Success; Error code otherwise.
191 int dpni_set_pools(struct fsl_mc_io *mc_io,
194 const struct dpni_pools_cfg *cfg)
196 struct mc_command cmd = { 0 };
197 struct dpni_cmd_set_pools *cmd_params;
200 /* prepare command */
201 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
204 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
205 cmd_params->num_dpbp = cfg->num_dpbp;
206 cmd_params->pool_options = cfg->pool_options;
207 for (i = 0; i < DPNI_MAX_DPBP; i++) {
208 cmd_params->pool[i].dpbp_id =
209 cpu_to_le16(cfg->pools[i].dpbp_id);
210 cmd_params->pool[i].priority_mask =
211 cfg->pools[i].priority_mask;
212 cmd_params->buffer_size[i] =
213 cpu_to_le16(cfg->pools[i].buffer_size);
214 cmd_params->backup_pool_mask |=
215 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
218 /* send command to mc*/
219 return mc_send_command(mc_io, &cmd);
223 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
224 * @mc_io: Pointer to MC portal's I/O object
225 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
226 * @token: Token of DPNI object
228 * Return: '0' on Success; Error code otherwise.
230 int dpni_enable(struct fsl_mc_io *mc_io,
234 struct mc_command cmd = { 0 };
236 /* prepare command */
237 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
241 /* send command to mc*/
242 return mc_send_command(mc_io, &cmd);
246 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
247 * @mc_io: Pointer to MC portal's I/O object
248 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
249 * @token: Token of DPNI object
251 * Return: '0' on Success; Error code otherwise.
253 int dpni_disable(struct fsl_mc_io *mc_io,
257 struct mc_command cmd = { 0 };
259 /* prepare command */
260 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
264 /* send command to mc*/
265 return mc_send_command(mc_io, &cmd);
269 * dpni_is_enabled() - Check if the DPNI is enabled.
270 * @mc_io: Pointer to MC portal's I/O object
271 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
272 * @token: Token of DPNI object
273 * @en: Returns '1' if object is enabled; '0' otherwise
275 * Return: '0' on Success; Error code otherwise.
277 int dpni_is_enabled(struct fsl_mc_io *mc_io,
282 struct mc_command cmd = { 0 };
283 struct dpni_rsp_is_enabled *rsp_params;
286 /* prepare command */
287 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
291 /* send command to mc*/
292 err = mc_send_command(mc_io, &cmd);
296 /* retrieve response parameters */
297 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
298 *en = dpni_get_field(rsp_params->enabled, ENABLE);
304 * dpni_reset() - Reset the DPNI, returns the object to initial state.
305 * @mc_io: Pointer to MC portal's I/O object
306 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
307 * @token: Token of DPNI object
309 * Return: '0' on Success; Error code otherwise.
311 int dpni_reset(struct fsl_mc_io *mc_io,
315 struct mc_command cmd = { 0 };
317 /* prepare command */
318 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
322 /* send command to mc*/
323 return mc_send_command(mc_io, &cmd);
327 * dpni_set_irq_enable() - Set overall interrupt state.
328 * @mc_io: Pointer to MC portal's I/O object
329 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
330 * @token: Token of DPNI object
331 * @irq_index: The interrupt index to configure
332 * @en: Interrupt state: - enable = 1, disable = 0
334 * Allows GPP software to control when interrupts are generated.
335 * Each interrupt can have up to 32 causes. The enable/disable control's the
336 * overall interrupt state. if the interrupt is disabled no causes will cause
339 * Return: '0' on Success; Error code otherwise.
341 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
347 struct mc_command cmd = { 0 };
348 struct dpni_cmd_set_irq_enable *cmd_params;
350 /* prepare command */
351 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
354 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
355 dpni_set_field(cmd_params->enable, ENABLE, en);
356 cmd_params->irq_index = irq_index;
358 /* send command to mc*/
359 return mc_send_command(mc_io, &cmd);
363 * dpni_get_irq_enable() - Get overall interrupt state
364 * @mc_io: Pointer to MC portal's I/O object
365 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
366 * @token: Token of DPNI object
367 * @irq_index: The interrupt index to configure
368 * @en: Returned interrupt state - enable = 1, disable = 0
370 * Return: '0' on Success; Error code otherwise.
372 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
378 struct mc_command cmd = { 0 };
379 struct dpni_cmd_get_irq_enable *cmd_params;
380 struct dpni_rsp_get_irq_enable *rsp_params;
384 /* prepare command */
385 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
388 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
389 cmd_params->irq_index = irq_index;
391 /* send command to mc*/
392 err = mc_send_command(mc_io, &cmd);
396 /* retrieve response parameters */
397 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
398 *en = dpni_get_field(rsp_params->enabled, ENABLE);
404 * dpni_set_irq_mask() - Set interrupt mask.
405 * @mc_io: Pointer to MC portal's I/O object
406 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
407 * @token: Token of DPNI object
408 * @irq_index: The interrupt index to configure
409 * @mask: Event mask to trigger interrupt;
412 * 1 = consider event for asserting IRQ
414 * Every interrupt can have up to 32 causes and the interrupt model supports
415 * masking/unmasking each cause independently
417 * Return: '0' on Success; Error code otherwise.
419 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
425 struct mc_command cmd = { 0 };
426 struct dpni_cmd_set_irq_mask *cmd_params;
428 /* prepare command */
429 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
432 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
433 cmd_params->mask = cpu_to_le32(mask);
434 cmd_params->irq_index = irq_index;
436 /* send command to mc*/
437 return mc_send_command(mc_io, &cmd);
441 * dpni_get_irq_mask() - Get interrupt mask.
442 * @mc_io: Pointer to MC portal's I/O object
443 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
444 * @token: Token of DPNI object
445 * @irq_index: The interrupt index to configure
446 * @mask: Returned event mask to trigger interrupt
448 * Every interrupt can have up to 32 causes and the interrupt model supports
449 * masking/unmasking each cause independently
451 * Return: '0' on Success; Error code otherwise.
453 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
459 struct mc_command cmd = { 0 };
460 struct dpni_cmd_get_irq_mask *cmd_params;
461 struct dpni_rsp_get_irq_mask *rsp_params;
464 /* prepare command */
465 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
468 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
469 cmd_params->irq_index = irq_index;
471 /* send command to mc*/
472 err = mc_send_command(mc_io, &cmd);
476 /* retrieve response parameters */
477 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
478 *mask = le32_to_cpu(rsp_params->mask);
484 * dpni_get_irq_status() - Get the current status of any pending interrupts.
485 * @mc_io: Pointer to MC portal's I/O object
486 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
487 * @token: Token of DPNI object
488 * @irq_index: The interrupt index to configure
489 * @status: Returned interrupts status - one bit per cause:
490 * 0 = no interrupt pending
491 * 1 = interrupt pending
493 * Return: '0' on Success; Error code otherwise.
495 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
501 struct mc_command cmd = { 0 };
502 struct dpni_cmd_get_irq_status *cmd_params;
503 struct dpni_rsp_get_irq_status *rsp_params;
506 /* prepare command */
507 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
510 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
511 cmd_params->status = cpu_to_le32(*status);
512 cmd_params->irq_index = irq_index;
514 /* send command to mc*/
515 err = mc_send_command(mc_io, &cmd);
519 /* retrieve response parameters */
520 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
521 *status = le32_to_cpu(rsp_params->status);
527 * dpni_clear_irq_status() - Clear a pending interrupt's status
528 * @mc_io: Pointer to MC portal's I/O object
529 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
530 * @token: Token of DPNI object
531 * @irq_index: The interrupt index to configure
532 * @status: bits to clear (W1C) - one bit per cause:
534 * 1 = clear status bit
536 * Return: '0' on Success; Error code otherwise.
538 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
544 struct mc_command cmd = { 0 };
545 struct dpni_cmd_clear_irq_status *cmd_params;
547 /* prepare command */
548 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
551 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
552 cmd_params->irq_index = irq_index;
553 cmd_params->status = cpu_to_le32(status);
555 /* send command to mc*/
556 return mc_send_command(mc_io, &cmd);
560 * dpni_get_attributes() - Retrieve DPNI attributes.
561 * @mc_io: Pointer to MC portal's I/O object
562 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
563 * @token: Token of DPNI object
564 * @attr: Object's attributes
566 * Return: '0' on Success; Error code otherwise.
568 int dpni_get_attributes(struct fsl_mc_io *mc_io,
571 struct dpni_attr *attr)
573 struct mc_command cmd = { 0 };
574 struct dpni_rsp_get_attr *rsp_params;
578 /* prepare command */
579 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
583 /* send command to mc*/
584 err = mc_send_command(mc_io, &cmd);
588 /* retrieve response parameters */
589 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
590 attr->options = le32_to_cpu(rsp_params->options);
591 attr->num_queues = rsp_params->num_queues;
592 attr->num_rx_tcs = rsp_params->num_rx_tcs;
593 attr->num_tx_tcs = rsp_params->num_tx_tcs;
594 attr->mac_filter_entries = rsp_params->mac_filter_entries;
595 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
596 attr->num_channels = rsp_params->num_channels;
597 attr->qos_entries = rsp_params->qos_entries;
598 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
599 attr->qos_key_size = rsp_params->qos_key_size;
600 attr->fs_key_size = rsp_params->fs_key_size;
601 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
602 attr->num_cgs = rsp_params->num_cgs;
608 * dpni_set_errors_behavior() - Set errors behavior
609 * @mc_io: Pointer to MC portal's I/O object
610 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
611 * @token: Token of DPNI object
612 * @cfg: Errors configuration
614 * This function may be called numerous times with different
617 * Return: '0' on Success; Error code otherwise.
619 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
622 struct dpni_error_cfg *cfg)
624 struct mc_command cmd = { 0 };
625 struct dpni_cmd_set_errors_behavior *cmd_params;
627 /* prepare command */
628 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
631 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
632 cmd_params->errors = cpu_to_le32(cfg->errors);
633 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
634 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
636 /* send command to mc*/
637 return mc_send_command(mc_io, &cmd);
641 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
642 * @mc_io: Pointer to MC portal's I/O object
643 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
644 * @token: Token of DPNI object
645 * @qtype: Type of queue to retrieve configuration for
646 * @layout: Returns buffer layout attributes
648 * Return: '0' on Success; Error code otherwise.
650 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
653 enum dpni_queue_type qtype,
654 struct dpni_buffer_layout *layout)
656 struct mc_command cmd = { 0 };
657 struct dpni_cmd_get_buffer_layout *cmd_params;
658 struct dpni_rsp_get_buffer_layout *rsp_params;
661 /* prepare command */
662 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
665 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
666 cmd_params->qtype = qtype;
668 /* send command to mc*/
669 err = mc_send_command(mc_io, &cmd);
673 /* retrieve response parameters */
674 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
675 layout->pass_timestamp =
676 (int)dpni_get_field(rsp_params->flags, PASS_TS);
677 layout->pass_parser_result =
678 (int)dpni_get_field(rsp_params->flags, PASS_PR);
679 layout->pass_frame_status =
680 (int)dpni_get_field(rsp_params->flags, PASS_FS);
681 layout->pass_sw_opaque =
682 (int)dpni_get_field(rsp_params->flags, PASS_SWO);
683 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
684 layout->data_align = le16_to_cpu(rsp_params->data_align);
685 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
686 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
692 * dpni_set_buffer_layout() - Set buffer layout configuration.
693 * @mc_io: Pointer to MC portal's I/O object
694 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
695 * @token: Token of DPNI object
696 * @qtype: Type of queue this configuration applies to
697 * @layout: Buffer layout configuration
699 * Return: '0' on Success; Error code otherwise.
701 * @warning Allowed only when DPNI is disabled
703 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
706 enum dpni_queue_type qtype,
707 const struct dpni_buffer_layout *layout)
709 struct mc_command cmd = { 0 };
710 struct dpni_cmd_set_buffer_layout *cmd_params;
712 /* prepare command */
713 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
716 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
717 cmd_params->qtype = qtype;
718 cmd_params->options = cpu_to_le16((uint16_t)layout->options);
719 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
720 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
721 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
722 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
723 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
724 cmd_params->data_align = cpu_to_le16(layout->data_align);
725 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
726 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
728 /* send command to mc*/
729 return mc_send_command(mc_io, &cmd);
733 * dpni_set_offload() - Set DPNI offload configuration.
734 * @mc_io: Pointer to MC portal's I/O object
735 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
736 * @token: Token of DPNI object
737 * @type: Type of DPNI offload
738 * @config: Offload configuration.
739 * For checksum offloads, non-zero value enables the offload
741 * Return: '0' on Success; Error code otherwise.
743 * @warning Allowed only when DPNI is disabled
746 int dpni_set_offload(struct fsl_mc_io *mc_io,
749 enum dpni_offload type,
752 struct mc_command cmd = { 0 };
753 struct dpni_cmd_set_offload *cmd_params;
755 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
758 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
759 cmd_params->dpni_offload = type;
760 cmd_params->config = cpu_to_le32(config);
762 return mc_send_command(mc_io, &cmd);
766 * dpni_get_offload() - Get DPNI offload configuration.
767 * @mc_io: Pointer to MC portal's I/O object
768 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
769 * @token: Token of DPNI object
770 * @type: Type of DPNI offload
771 * @config: Offload configuration.
772 * For checksum offloads, a value of 1 indicates that the
773 * offload is enabled.
775 * Return: '0' on Success; Error code otherwise.
777 * @warning Allowed only when DPNI is disabled
779 int dpni_get_offload(struct fsl_mc_io *mc_io,
782 enum dpni_offload type,
785 struct mc_command cmd = { 0 };
786 struct dpni_cmd_get_offload *cmd_params;
787 struct dpni_rsp_get_offload *rsp_params;
790 /* prepare command */
791 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
794 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
795 cmd_params->dpni_offload = type;
797 /* send command to mc*/
798 err = mc_send_command(mc_io, &cmd);
802 /* retrieve response parameters */
803 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
804 *config = le32_to_cpu(rsp_params->config);
810 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
811 * for enqueue operations
812 * @mc_io: Pointer to MC portal's I/O object
813 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
814 * @token: Token of DPNI object
815 * @qtype: Type of queue to receive QDID for
816 * @qdid: Returned virtual QDID value that should be used as an argument
817 * in all enqueue operations
819 * Return: '0' on Success; Error code otherwise.
821 * If dpni object is created using multiple Tc channels this function will return
822 * qdid value for the first channel
824 int dpni_get_qdid(struct fsl_mc_io *mc_io,
827 enum dpni_queue_type qtype,
830 struct mc_command cmd = { 0 };
831 struct dpni_cmd_get_qdid *cmd_params;
832 struct dpni_rsp_get_qdid *rsp_params;
835 /* prepare command */
836 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
839 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
840 cmd_params->qtype = qtype;
842 /* send command to mc*/
843 err = mc_send_command(mc_io, &cmd);
847 /* retrieve response parameters */
848 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
849 *qdid = le16_to_cpu(rsp_params->qdid);
855 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
856 * @mc_io: Pointer to MC portal's I/O object
857 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
858 * @token: Token of DPNI object
859 * @data_offset: Tx data offset (from start of buffer)
861 * Return: '0' on Success; Error code otherwise.
863 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
866 uint16_t *data_offset)
868 struct mc_command cmd = { 0 };
869 struct dpni_rsp_get_tx_data_offset *rsp_params;
872 /* prepare command */
873 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
877 /* send command to mc*/
878 err = mc_send_command(mc_io, &cmd);
882 /* retrieve response parameters */
883 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
884 *data_offset = le16_to_cpu(rsp_params->data_offset);
890 * dpni_set_link_cfg() - set the link configuration.
891 * @mc_io: Pointer to MC portal's I/O object
892 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
893 * @token: Token of DPNI object
894 * @cfg: Link configuration
896 * Return: '0' on Success; Error code otherwise.
898 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
901 const struct dpni_link_cfg *cfg)
903 struct mc_command cmd = { 0 };
904 struct dpni_cmd_set_link_cfg *cmd_params;
906 /* prepare command */
907 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
910 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
911 cmd_params->rate = cpu_to_le32(cfg->rate);
912 cmd_params->options = cpu_to_le64(cfg->options);
913 cmd_params->advertising = cpu_to_le64(cfg->advertising);
915 /* send command to mc*/
916 return mc_send_command(mc_io, &cmd);
920 * dpni_get_link_cfg() - return the link configuration configured by
921 * dpni_set_link_cfg().
922 * @mc_io: Pointer to MC portal's I/O object
923 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
924 * @token: Token of DPNI object
925 * @cfg: Link configuration from dpni object
927 * Return: '0' on Success; Error code otherwise.
929 int dpni_get_link_cfg(struct fsl_mc_io *mc_io,
932 struct dpni_link_cfg *cfg)
934 struct mc_command cmd = { 0 };
935 struct dpni_cmd_set_link_cfg *rsp_params;
938 /* prepare command */
939 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG,
943 /* send command to mc*/
944 err = mc_send_command(mc_io, &cmd);
948 /* retrieve response parameters */
949 rsp_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
950 cfg->advertising = le64_to_cpu(rsp_params->advertising);
951 cfg->options = le64_to_cpu(rsp_params->options);
952 cfg->rate = le32_to_cpu(rsp_params->rate);
958 * dpni_get_link_state() - Return the link state (either up or down)
959 * @mc_io: Pointer to MC portal's I/O object
960 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
961 * @token: Token of DPNI object
962 * @state: Returned link state;
964 * Return: '0' on Success; Error code otherwise.
966 int dpni_get_link_state(struct fsl_mc_io *mc_io,
969 struct dpni_link_state *state)
971 struct mc_command cmd = { 0 };
972 struct dpni_rsp_get_link_state *rsp_params;
975 /* prepare command */
976 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
980 /* send command to mc*/
981 err = mc_send_command(mc_io, &cmd);
985 /* retrieve response parameters */
986 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
987 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
988 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
989 state->rate = le32_to_cpu(rsp_params->rate);
990 state->options = le64_to_cpu(rsp_params->options);
991 state->supported = le64_to_cpu(rsp_params->supported);
992 state->advertising = le64_to_cpu(rsp_params->advertising);
998 * dpni_set_tx_shaping() - Set the transmit shaping
999 * @mc_io: Pointer to MC portal's I/O object
1000 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1001 * @token: Token of DPNI object
1002 * @tx_cr_shaper: TX committed rate shaping configuration
1003 * @tx_er_shaper: TX excess rate shaping configuration
1004 * @param: Special parameters
1005 * bit0: Committed and excess rates are coupled
1006 * bit1: 1 modify LNI shaper, 0 modify channel shaper
1007 * bit8-15: Tx channel to be shaped. Used only if bit1 is set to zero
1008 * bits16-26: OAL (Overhead accounting length 11bit value). Used only
1011 * Return: '0' on Success; Error code otherwise.
1013 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
1016 const struct dpni_tx_shaping_cfg *tx_cr_shaper,
1017 const struct dpni_tx_shaping_cfg *tx_er_shaper,
1020 struct dpni_cmd_set_tx_shaping *cmd_params;
1021 struct mc_command cmd = { 0 };
1022 int coupled, lni_shaper;
1026 /* prepare command */
1027 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
1030 cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
1031 cmd_params->tx_cr_max_burst_size =
1032 cpu_to_le16(tx_cr_shaper->max_burst_size);
1033 cmd_params->tx_er_max_burst_size =
1034 cpu_to_le16(tx_er_shaper->max_burst_size);
1035 cmd_params->tx_cr_rate_limit =
1036 cpu_to_le32(tx_cr_shaper->rate_limit);
1037 cmd_params->tx_er_rate_limit =
1038 cpu_to_le32(tx_er_shaper->rate_limit);
1040 coupled = !!(param & 0x01);
1041 dpni_set_field(cmd_params->options, COUPLED, coupled);
1043 lni_shaper = !!((param >> 1) & 0x01);
1044 dpni_set_field(cmd_params->options, LNI_SHAPER, lni_shaper);
1046 channel_id = (param >> 8) & 0xff;
1047 cmd_params->channel_id = channel_id;
1049 oal = (param >> 16) & 0x7FF;
1050 cmd_params->oal = cpu_to_le16(oal);
1052 /* send command to mc*/
1053 return mc_send_command(mc_io, &cmd);
1057 * dpni_set_max_frame_length() - Set the maximum received frame length.
1058 * @mc_io: Pointer to MC portal's I/O object
1059 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1060 * @token: Token of DPNI object
1061 * @max_frame_length: Maximum received frame length (in bytes);
1062 * frame is discarded if its length exceeds this value
1064 * Return: '0' on Success; Error code otherwise.
1066 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
1069 uint16_t max_frame_length)
1071 struct mc_command cmd = { 0 };
1072 struct dpni_cmd_set_max_frame_length *cmd_params;
1074 /* prepare command */
1075 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
1078 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
1079 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
1081 /* send command to mc*/
1082 return mc_send_command(mc_io, &cmd);
1086 * dpni_get_max_frame_length() - Get the maximum received frame length.
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 * @max_frame_length: Maximum received frame length (in bytes);
1091 * frame is discarded if its length exceeds this value
1093 * Return: '0' on Success; Error code otherwise.
1095 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
1098 uint16_t *max_frame_length)
1100 struct mc_command cmd = { 0 };
1101 struct dpni_rsp_get_max_frame_length *rsp_params;
1104 /* prepare command */
1105 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1109 /* send command to mc*/
1110 err = mc_send_command(mc_io, &cmd);
1114 /* retrieve response parameters */
1115 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1116 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1122 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1123 * @mc_io: Pointer to MC portal's I/O object
1124 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1125 * @token: Token of DPNI object
1126 * @en: Set to '1' to enable; '0' to disable
1128 * Return: '0' on Success; Error code otherwise.
1130 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1135 struct mc_command cmd = { 0 };
1136 struct dpni_cmd_set_multicast_promisc *cmd_params;
1138 /* prepare command */
1139 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1142 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1143 dpni_set_field(cmd_params->enable, ENABLE, en);
1145 /* send command to mc*/
1146 return mc_send_command(mc_io, &cmd);
1150 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1151 * @mc_io: Pointer to MC portal's I/O object
1152 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1153 * @token: Token of DPNI object
1154 * @en: Returns '1' if enabled; '0' otherwise
1156 * Return: '0' on Success; Error code otherwise.
1158 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1163 struct mc_command cmd = { 0 };
1164 struct dpni_rsp_get_multicast_promisc *rsp_params;
1167 /* prepare command */
1168 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1172 /* send command to mc*/
1173 err = mc_send_command(mc_io, &cmd);
1177 /* retrieve response parameters */
1178 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1179 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1185 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1186 * @mc_io: Pointer to MC portal's I/O object
1187 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1188 * @token: Token of DPNI object
1189 * @en: Set to '1' to enable; '0' to disable
1191 * Return: '0' on Success; Error code otherwise.
1193 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1198 struct mc_command cmd = { 0 };
1199 struct dpni_cmd_set_unicast_promisc *cmd_params;
1201 /* prepare command */
1202 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1205 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1206 dpni_set_field(cmd_params->enable, ENABLE, en);
1208 /* send command to mc*/
1209 return mc_send_command(mc_io, &cmd);
1213 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1214 * @mc_io: Pointer to MC portal's I/O object
1215 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1216 * @token: Token of DPNI object
1217 * @en: Returns '1' if enabled; '0' otherwise
1219 * Return: '0' on Success; Error code otherwise.
1221 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1226 struct mc_command cmd = { 0 };
1227 struct dpni_rsp_get_unicast_promisc *rsp_params;
1230 /* prepare command */
1231 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1235 /* send command to mc*/
1236 err = mc_send_command(mc_io, &cmd);
1240 /* retrieve response parameters */
1241 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1242 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1248 * dpni_set_primary_mac_addr() - Set the primary MAC address
1249 * @mc_io: Pointer to MC portal's I/O object
1250 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1251 * @token: Token of DPNI object
1252 * @mac_addr: MAC address to set as primary address
1254 * Return: '0' on Success; Error code otherwise.
1256 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1259 const uint8_t mac_addr[6])
1261 struct mc_command cmd = { 0 };
1262 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1265 /* prepare command */
1266 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1269 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1270 for (i = 0; i < 6; i++)
1271 cmd_params->mac_addr[i] = mac_addr[5 - i];
1273 /* send command to mc*/
1274 return mc_send_command(mc_io, &cmd);
1278 * dpni_get_primary_mac_addr() - Get the primary MAC address
1279 * @mc_io: Pointer to MC portal's I/O object
1280 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1281 * @token: Token of DPNI object
1282 * @mac_addr: Returned MAC address
1284 * Return: '0' on Success; Error code otherwise.
1286 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1289 uint8_t mac_addr[6])
1291 struct mc_command cmd = { 0 };
1292 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1295 /* prepare command */
1296 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1300 /* send command to mc*/
1301 err = mc_send_command(mc_io, &cmd);
1305 /* retrieve response parameters */
1306 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1307 for (i = 0; i < 6; i++)
1308 mac_addr[5 - i] = rsp_params->mac_addr[i];
1314 * dpni_add_mac_addr() - Add MAC address filter
1315 * @mc_io: Pointer to MC portal's I/O object
1316 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1317 * @token: Token of DPNI object
1318 * @mac_addr: MAC address to add
1319 * @flags : 0 - tc_id and flow_id will be ignored.
1320 * Pkt with this mac_id will be passed to the next
1321 * classification stages
1322 * DPNI_MAC_SET_QUEUE_ACTION
1323 * Pkt with this mac will be forward directly to
1324 * queue defined by the tc_id and flow_id
1325 * @tc_id : Traffic class selection (0-7)
1326 * @flow_id : Selects the specific queue out of the set allocated for the
1327 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1328 * Return: '0' on Success; Error code otherwise.
1330 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1333 const uint8_t mac_addr[6],
1338 struct mc_command cmd = { 0 };
1339 struct dpni_cmd_add_mac_addr *cmd_params;
1342 /* prepare command */
1343 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1346 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1347 cmd_params->flags = flags;
1348 cmd_params->tc_id = tc_id;
1349 cmd_params->fq_id = flow_id;
1351 for (i = 0; i < 6; i++)
1352 cmd_params->mac_addr[i] = mac_addr[5 - i];
1354 /* send command to mc*/
1355 return mc_send_command(mc_io, &cmd);
1359 * dpni_remove_mac_addr() - Remove MAC address filter
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 to remove
1365 * Return: '0' on Success; Error code otherwise.
1367 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1370 const uint8_t mac_addr[6])
1372 struct mc_command cmd = { 0 };
1373 struct dpni_cmd_remove_mac_addr *cmd_params;
1376 /* prepare command */
1377 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1380 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1381 for (i = 0; i < 6; i++)
1382 cmd_params->mac_addr[i] = mac_addr[5 - i];
1384 /* send command to mc*/
1385 return mc_send_command(mc_io, &cmd);
1389 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1390 * @mc_io: Pointer to MC portal's I/O object
1391 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1392 * @token: Token of DPNI object
1393 * @unicast: Set to '1' to clear unicast addresses
1394 * @multicast: Set to '1' to clear multicast addresses
1396 * The primary MAC address is not cleared by this operation.
1398 * Return: '0' on Success; Error code otherwise.
1400 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1406 struct mc_command cmd = { 0 };
1407 struct dpni_cmd_clear_mac_filters *cmd_params;
1409 /* prepare command */
1410 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1413 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1414 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1415 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1417 /* send command to mc*/
1418 return mc_send_command(mc_io, &cmd);
1422 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1423 * port the DPNI is attached to
1424 * @mc_io: Pointer to MC portal's I/O object
1425 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1426 * @token: Token of DPNI object
1427 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1429 * The primary MAC address is not cleared by this operation.
1431 * Return: '0' on Success; Error code otherwise.
1433 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1436 uint8_t mac_addr[6])
1438 struct mc_command cmd = { 0 };
1439 struct dpni_rsp_get_port_mac_addr *rsp_params;
1442 /* prepare command */
1443 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1447 /* send command to mc*/
1448 err = mc_send_command(mc_io, &cmd);
1452 /* retrieve response parameters */
1453 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1454 for (i = 0; i < 6; i++)
1455 mac_addr[5 - i] = rsp_params->mac_addr[i];
1461 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1462 * @mc_io: Pointer to MC portal's I/O object
1463 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1464 * @token: Token of DPNI object
1465 * @en: Set to '1' to enable; '0' to disable
1467 * Return: '0' on Success; Error code otherwise.
1469 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1474 struct dpni_cmd_enable_vlan_filter *cmd_params;
1475 struct mc_command cmd = { 0 };
1477 /* prepare command */
1478 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1481 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1482 dpni_set_field(cmd_params->en, ENABLE, en);
1484 /* send command to mc*/
1485 return mc_send_command(mc_io, &cmd);
1489 * dpni_add_vlan_id() - Add VLAN ID filter
1490 * @mc_io: Pointer to MC portal's I/O object
1491 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1492 * @token: Token of DPNI object
1493 * @vlan_id: VLAN ID to add
1494 * @flags: 0 - tc_id and flow_id will be ignored.
1495 * Pkt with this vlan_id will be passed to the next
1496 * classification stages
1497 * DPNI_VLAN_SET_QUEUE_ACTION
1498 * Pkt with this vlan_id will be forward directly to
1499 * queue defined by the tc_id and flow_id
1501 * @tc_id: Traffic class selection (0-7)
1502 * @flow_id: Selects the specific queue out of the set allocated for the
1503 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1505 * Return: '0' on Success; Error code otherwise.
1507 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1515 struct dpni_cmd_vlan_id *cmd_params;
1516 struct mc_command cmd = { 0 };
1518 /* prepare command */
1519 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1522 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1523 cmd_params->flags = flags;
1524 cmd_params->tc_id = tc_id;
1525 cmd_params->flow_id = flow_id;
1526 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1528 /* send command to mc*/
1529 return mc_send_command(mc_io, &cmd);
1533 * dpni_remove_vlan_id() - Remove VLAN ID filter
1534 * @mc_io: Pointer to MC portal's I/O object
1535 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1536 * @token: Token of DPNI object
1537 * @vlan_id: VLAN ID to remove
1539 * Return: '0' on Success; Error code otherwise.
1541 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1546 struct dpni_cmd_vlan_id *cmd_params;
1547 struct mc_command cmd = { 0 };
1549 /* prepare command */
1550 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1553 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1554 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1556 /* send command to mc*/
1557 return mc_send_command(mc_io, &cmd);
1561 * dpni_clear_vlan_filters() - Clear all VLAN filters
1562 * @mc_io: Pointer to MC portal's I/O object
1563 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1564 * @token: Token of DPNI object
1566 * Return: '0' on Success; Error code otherwise.
1568 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1572 struct mc_command cmd = { 0 };
1574 /* prepare command */
1575 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1579 /* send command to mc*/
1580 return mc_send_command(mc_io, &cmd);
1584 * dpni_set_tx_priorities() - Set transmission TC priority configuration
1585 * @mc_io: Pointer to MC portal's I/O object
1586 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1587 * @token: Token of DPNI object
1588 * @cfg: Transmission selection configuration
1590 * warning: Allowed only when DPNI is disabled
1592 * Return: '0' on Success; Error code otherwise.
1594 int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
1597 const struct dpni_tx_priorities_cfg *cfg)
1599 struct dpni_cmd_set_tx_priorities *cmd_params;
1600 struct mc_command cmd = { 0 };
1603 /* prepare command */
1604 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES,
1607 cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params;
1608 cmd_params->channel_idx = cfg->channel_idx;
1609 dpni_set_field(cmd_params->flags,
1611 cfg->separate_groups);
1612 cmd_params->prio_group_A = cfg->prio_group_A;
1613 cmd_params->prio_group_B = cfg->prio_group_B;
1615 for (i = 0; i + 1 < DPNI_MAX_TC; i = i + 2) {
1616 dpni_set_field(cmd_params->modes[i / 2],
1618 cfg->tc_sched[i].mode);
1619 dpni_set_field(cmd_params->modes[i / 2],
1621 cfg->tc_sched[i + 1].mode);
1624 for (i = 0; i < DPNI_MAX_TC; i++) {
1625 cmd_params->delta_bandwidth[i] =
1626 cpu_to_le16(cfg->tc_sched[i].delta_bandwidth);
1629 /* send command to mc*/
1630 return mc_send_command(mc_io, &cmd);
1634 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1635 * @mc_io: Pointer to MC portal's I/O object
1636 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1637 * @token: Token of DPNI object
1638 * @tc_id: Traffic class selection (0-7)
1639 * @cfg: Traffic class distribution configuration
1641 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1642 * first to prepare the key_cfg_iova parameter
1644 * Return: '0' on Success; error code otherwise.
1646 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1650 const struct dpni_rx_tc_dist_cfg *cfg)
1652 struct mc_command cmd = { 0 };
1653 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1655 /* prepare command */
1656 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1659 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1660 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1661 cmd_params->tc_id = tc_id;
1662 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1663 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1664 dpni_set_field(cmd_params->flags,
1667 dpni_set_field(cmd_params->flags,
1669 cfg->fs_cfg.miss_action);
1670 dpni_set_field(cmd_params->keep_hash_key,
1672 cfg->fs_cfg.keep_hash_key);
1673 dpni_set_field(cmd_params->keep_hash_key,
1675 cfg->fs_cfg.keep_entries);
1677 /* send command to mc*/
1678 return mc_send_command(mc_io, &cmd);
1682 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1683 * @mc_io: Pointer to MC portal's I/O object
1684 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1685 * @token: Token of DPNI object
1686 * @mode: Tx confirmation mode
1688 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1689 * selected at DPNI creation.
1690 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1691 * transmit confirmation (including the private confirmation queues), regardless
1692 * of previous settings; Note that in this case, Tx error frames are still
1693 * enqueued to the general transmit errors queue.
1694 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1695 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1696 * command will be ignored.
1698 * Return: '0' on Success; Error code otherwise.
1700 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1703 enum dpni_confirmation_mode mode)
1705 struct dpni_tx_confirmation_mode *cmd_params;
1706 struct mc_command cmd = { 0 };
1708 /* prepare command */
1709 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1712 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1713 cmd_params->confirmation_mode = mode;
1715 /* send command to mc*/
1716 return mc_send_command(mc_io, &cmd);
1720 * dpni_get_tx_confirmation_mode() - Get Tx confirmation mode
1721 * @mc_io: Pointer to MC portal's I/O object
1722 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1723 * @token: Token of DPNI object
1724 * @mode: Tx confirmation mode
1726 * Return: '0' on Success; Error code otherwise.
1728 int dpni_get_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1731 enum dpni_confirmation_mode *mode)
1733 struct dpni_tx_confirmation_mode *rsp_params;
1734 struct mc_command cmd = { 0 };
1737 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONFIRMATION_MODE,
1741 err = mc_send_command(mc_io, &cmd);
1745 rsp_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1746 *mode = rsp_params->confirmation_mode;
1752 * dpni_set_qos_table() - Set QoS mapping table
1753 * @mc_io: Pointer to MC portal's I/O object
1754 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1755 * @token: Token of DPNI object
1756 * @cfg: QoS table configuration
1758 * This function and all QoS-related functions require that
1759 *'max_tcs > 1' was set at DPNI creation.
1761 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1762 * prepare the key_cfg_iova parameter
1764 * Return: '0' on Success; Error code otherwise.
1766 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1769 const struct dpni_qos_tbl_cfg *cfg)
1771 struct dpni_cmd_set_qos_table *cmd_params;
1772 struct mc_command cmd = { 0 };
1774 /* prepare command */
1775 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1778 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1779 cmd_params->default_tc = cfg->default_tc;
1780 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1781 dpni_set_field(cmd_params->discard_on_miss,
1783 cfg->discard_on_miss);
1784 dpni_set_field(cmd_params->discard_on_miss,
1788 /* send command to mc*/
1789 return mc_send_command(mc_io, &cmd);
1793 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1794 * @mc_io: Pointer to MC portal's I/O object
1795 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1796 * @token: Token of DPNI object
1797 * @cfg: QoS rule to add
1798 * @tc_id: Traffic class selection (0-7)
1799 * @index: Location in the QoS table where to insert the entry.
1800 * Only relevant if MASKING is enabled for QoS classification on
1801 * this DPNI, it is ignored for exact match.
1803 * Return: '0' on Success; Error code otherwise.
1805 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1808 const struct dpni_rule_cfg *cfg,
1814 struct dpni_cmd_add_qos_entry *cmd_params;
1815 struct mc_command cmd = { 0 };
1817 /* prepare command */
1818 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1821 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1822 cmd_params->flags = flags;
1823 cmd_params->flow_id = flow_id;
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);
1830 /* send command to mc*/
1831 return mc_send_command(mc_io, &cmd);
1835 * dpni_remove_qos_entry() - Remove QoS mapping entry
1836 * @mc_io: Pointer to MC portal's I/O object
1837 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1838 * @token: Token of DPNI object
1839 * @cfg: QoS rule to remove
1841 * Return: '0' on Success; Error code otherwise.
1843 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1846 const struct dpni_rule_cfg *cfg)
1848 struct dpni_cmd_remove_qos_entry *cmd_params;
1849 struct mc_command cmd = { 0 };
1851 /* prepare command */
1852 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1855 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1856 cmd_params->key_size = cfg->key_size;
1857 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1858 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1860 /* send command to mc*/
1861 return mc_send_command(mc_io, &cmd);
1865 * dpni_clear_qos_table() - Clear all QoS mapping entries
1866 * @mc_io: Pointer to MC portal's I/O object
1867 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1868 * @token: Token of DPNI object
1870 * Following this function call, all frames are directed to
1871 * the default traffic class (0)
1873 * Return: '0' on Success; Error code otherwise.
1875 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1879 struct mc_command cmd = { 0 };
1881 /* prepare command */
1882 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1886 /* send command to mc*/
1887 return mc_send_command(mc_io, &cmd);
1891 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1892 * (to select a flow ID)
1893 * @mc_io: Pointer to MC portal's I/O object
1894 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1895 * @token: Token of DPNI object
1896 * @tc_id: Traffic class selection (0-7)
1897 * @index: Location in the QoS table where to insert the entry.
1898 * Only relevant if MASKING is enabled for QoS classification
1899 * on this DPNI, it is ignored for exact match.
1900 * @cfg: Flow steering rule to add
1901 * @action: Action to be taken as result of a classification hit
1903 * Return: '0' on Success; Error code otherwise.
1905 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1910 const struct dpni_rule_cfg *cfg,
1911 const struct dpni_fs_action_cfg *action)
1913 struct dpni_cmd_add_fs_entry *cmd_params;
1914 struct mc_command cmd = { 0 };
1916 /* prepare command */
1917 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1920 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1921 cmd_params->tc_id = tc_id;
1922 cmd_params->key_size = cfg->key_size;
1923 cmd_params->index = cpu_to_le16(index);
1924 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1925 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1926 cmd_params->options = cpu_to_le16(action->options);
1927 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1928 cmd_params->flc = cpu_to_le64(action->flc);
1929 cmd_params->redir_token = cpu_to_le16(action->redirect_obj_token);
1931 /* send command to mc*/
1932 return mc_send_command(mc_io, &cmd);
1936 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1938 * @mc_io: Pointer to MC portal's I/O object
1939 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1940 * @token: Token of DPNI object
1941 * @tc_id: Traffic class selection (0-7)
1942 * @cfg: Flow steering rule to remove
1944 * Return: '0' on Success; Error code otherwise.
1946 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1950 const struct dpni_rule_cfg *cfg)
1952 struct dpni_cmd_remove_fs_entry *cmd_params;
1953 struct mc_command cmd = { 0 };
1955 /* prepare command */
1956 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1959 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1960 cmd_params->tc_id = tc_id;
1961 cmd_params->key_size = cfg->key_size;
1962 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1963 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1965 /* send command to mc*/
1966 return mc_send_command(mc_io, &cmd);
1970 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1972 * @mc_io: Pointer to MC portal's I/O object
1973 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1974 * @token: Token of DPNI object
1975 * @tc_id: Traffic class selection (0-7)
1977 * Return: '0' on Success; Error code otherwise.
1979 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1984 struct dpni_cmd_clear_fs_entries *cmd_params;
1985 struct mc_command cmd = { 0 };
1987 /* prepare command */
1988 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1991 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1992 cmd_params->tc_id = tc_id;
1994 /* send command to mc*/
1995 return mc_send_command(mc_io, &cmd);
1999 * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
2000 * @mc_io: Pointer to MC portal's I/O object
2001 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2002 * @token: Token of DPNI object
2003 * @tc_id: Traffic class selection (0-7)
2004 * @cfg: Traffic class policing configuration
2006 * Return: '0' on Success; error code otherwise.
2008 int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
2012 const struct dpni_rx_tc_policing_cfg *cfg)
2014 struct dpni_cmd_set_rx_tc_policing *cmd_params;
2015 struct mc_command cmd = { 0 };
2017 /* prepare command */
2018 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING,
2021 cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params;
2022 dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color);
2023 dpni_set_field(cmd_params->mode_color, MODE, cfg->mode);
2024 dpni_set_field(cmd_params->units, UNITS, cfg->units);
2025 cmd_params->options = cpu_to_le32(cfg->options);
2026 cmd_params->cir = cpu_to_le32(cfg->cir);
2027 cmd_params->cbs = cpu_to_le32(cfg->cbs);
2028 cmd_params->eir = cpu_to_le32(cfg->eir);
2029 cmd_params->ebs = cpu_to_le32(cfg->ebs);
2030 cmd_params->tc_id = tc_id;
2032 /* send command to mc*/
2033 return mc_send_command(mc_io, &cmd);
2037 * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration
2038 * @mc_io: Pointer to MC portal's I/O object
2039 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2040 * @token: Token of DPNI object
2041 * @tc_id: Traffic class selection (0-7)
2042 * @cfg: Traffic class policing configuration
2044 * Return: '0' on Success; error code otherwise.
2046 int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io,
2050 struct dpni_rx_tc_policing_cfg *cfg)
2052 struct dpni_rsp_get_rx_tc_policing *rsp_params;
2053 struct dpni_cmd_get_rx_tc_policing *cmd_params;
2054 struct mc_command cmd = { 0 };
2057 /* prepare command */
2058 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_TC_POLICING,
2061 cmd_params = (struct dpni_cmd_get_rx_tc_policing *)cmd.params;
2062 cmd_params->tc_id = tc_id;
2065 /* send command to mc*/
2066 err = mc_send_command(mc_io, &cmd);
2070 rsp_params = (struct dpni_rsp_get_rx_tc_policing *)cmd.params;
2071 cfg->options = le32_to_cpu(rsp_params->options);
2072 cfg->cir = le32_to_cpu(rsp_params->cir);
2073 cfg->cbs = le32_to_cpu(rsp_params->cbs);
2074 cfg->eir = le32_to_cpu(rsp_params->eir);
2075 cfg->ebs = le32_to_cpu(rsp_params->ebs);
2076 cfg->units = dpni_get_field(rsp_params->units, UNITS);
2077 cfg->mode = dpni_get_field(rsp_params->mode_color, MODE);
2078 cfg->default_color = dpni_get_field(rsp_params->mode_color, COLOR);
2084 * dpni_prepare_early_drop() - prepare an early drop.
2085 * @cfg: Early-drop configuration
2086 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2088 * This function has to be called before dpni_set_rx_tc_early_drop or
2089 * dpni_set_tx_tc_early_drop
2092 void dpni_prepare_early_drop(const struct dpni_early_drop_cfg *cfg,
2093 uint8_t *early_drop_buf)
2095 struct dpni_early_drop *ext_params;
2097 ext_params = (struct dpni_early_drop *)early_drop_buf;
2099 dpni_set_field(ext_params->flags, DROP_ENABLE, cfg->enable);
2100 dpni_set_field(ext_params->flags, DROP_UNITS, cfg->units);
2101 ext_params->green_drop_probability = cfg->green.drop_probability;
2102 ext_params->green_max_threshold = cpu_to_le64(cfg->green.max_threshold);
2103 ext_params->green_min_threshold = cpu_to_le64(cfg->green.min_threshold);
2104 ext_params->yellow_drop_probability = cfg->yellow.drop_probability;
2105 ext_params->yellow_max_threshold =
2106 cpu_to_le64(cfg->yellow.max_threshold);
2107 ext_params->yellow_min_threshold =
2108 cpu_to_le64(cfg->yellow.min_threshold);
2109 ext_params->red_drop_probability = cfg->red.drop_probability;
2110 ext_params->red_max_threshold = cpu_to_le64(cfg->red.max_threshold);
2111 ext_params->red_min_threshold = cpu_to_le64(cfg->red.min_threshold);
2115 * dpni_extract_early_drop() - extract the early drop configuration.
2116 * @cfg: Early-drop configuration
2117 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2119 * This function has to be called after dpni_get_rx_tc_early_drop or
2120 * dpni_get_tx_tc_early_drop
2123 void dpni_extract_early_drop(struct dpni_early_drop_cfg *cfg,
2124 const uint8_t *early_drop_buf)
2126 const struct dpni_early_drop *ext_params;
2128 ext_params = (const struct dpni_early_drop *)early_drop_buf;
2130 cfg->enable = dpni_get_field(ext_params->flags, DROP_ENABLE);
2131 cfg->units = dpni_get_field(ext_params->flags, DROP_UNITS);
2132 cfg->green.drop_probability = ext_params->green_drop_probability;
2133 cfg->green.max_threshold = le64_to_cpu(ext_params->green_max_threshold);
2134 cfg->green.min_threshold = le64_to_cpu(ext_params->green_min_threshold);
2135 cfg->yellow.drop_probability = ext_params->yellow_drop_probability;
2136 cfg->yellow.max_threshold =
2137 le64_to_cpu(ext_params->yellow_max_threshold);
2138 cfg->yellow.min_threshold =
2139 le64_to_cpu(ext_params->yellow_min_threshold);
2140 cfg->red.drop_probability = ext_params->red_drop_probability;
2141 cfg->red.max_threshold = le64_to_cpu(ext_params->red_max_threshold);
2142 cfg->red.min_threshold = le64_to_cpu(ext_params->red_min_threshold);
2146 * dpni_set_early_drop() - Set traffic class early-drop configuration
2147 * @mc_io: Pointer to MC portal's I/O object
2148 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2149 * @token: Token of DPNI object
2150 * @qtype: Type of queue - only Rx and Tx types are supported
2151 * @param: Traffic class and channel ID.
2152 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2153 * ignored for the rest
2154 * LSB - traffic class
2155 * Use macro DPNI_BUILD_PARAM() to build correct value.
2156 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2157 * traffic class directly.
2158 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory filled
2159 * with the early-drop configuration by calling dpni_prepare_early_drop()
2161 * warning: Before calling this function, call dpni_prepare_early_drop() to
2162 * prepare the early_drop_iova parameter
2164 * Return: '0' on Success; error code otherwise.
2166 int dpni_set_early_drop(struct fsl_mc_io *mc_io,
2169 enum dpni_queue_type qtype,
2171 uint64_t early_drop_iova)
2173 struct dpni_cmd_early_drop *cmd_params;
2174 struct mc_command cmd = { 0 };
2176 /* prepare command */
2177 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_EARLY_DROP,
2180 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2181 cmd_params->qtype = qtype;
2182 cmd_params->tc = (uint8_t)(param & 0xff);
2183 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2184 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2186 /* send command to mc*/
2187 return mc_send_command(mc_io, &cmd);
2191 * dpni_get_early_drop() - Get Rx traffic class early-drop configuration
2192 * @mc_io: Pointer to MC portal's I/O object
2193 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2194 * @token: Token of DPNI object
2195 * @qtype: Type of queue - only Rx and Tx types are supported
2196 * @param: Traffic class and channel ID.
2197 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2198 * ignored for the rest
2199 * LSB - traffic class
2200 * Use macro DPNI_BUILD_PARAM() to build correct value.
2201 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2202 * traffic class directly.
2203 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory
2205 * warning: After calling this function, call dpni_extract_early_drop() to
2206 * get the early drop configuration
2208 * Return: '0' on Success; error code otherwise.
2210 int dpni_get_early_drop(struct fsl_mc_io *mc_io,
2213 enum dpni_queue_type qtype,
2215 uint64_t early_drop_iova)
2217 struct dpni_cmd_early_drop *cmd_params;
2218 struct mc_command cmd = { 0 };
2220 /* prepare command */
2221 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_EARLY_DROP,
2224 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2225 cmd_params->qtype = qtype;
2226 cmd_params->tc = (uint8_t)(param & 0xff);
2227 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2228 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2230 /* send command to mc*/
2231 return mc_send_command(mc_io, &cmd);
2235 * dpni_set_congestion_notification() - Set traffic class congestion
2236 * notification configuration
2237 * @mc_io: Pointer to MC portal's I/O object
2238 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2239 * @token: Token of DPNI object
2240 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2241 * @tc_id: Traffic class selection (0-7)
2242 * @cfg: congestion notification configuration
2244 * Return: '0' on Success; error code otherwise.
2246 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
2249 enum dpni_queue_type qtype,
2251 const struct dpni_congestion_notification_cfg *cfg)
2253 struct dpni_cmd_set_congestion_notification *cmd_params;
2254 struct mc_command cmd = { 0 };
2256 /* prepare command */
2257 cmd.header = mc_encode_cmd_header(
2258 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
2261 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
2262 cmd_params->qtype = qtype;
2263 cmd_params->tc = (uint8_t)(param & 0xff);
2264 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2265 cmd_params->congestion_point = cfg->cg_point;
2266 cmd_params->cgid = (uint8_t)cfg->cgid;
2267 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
2268 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
2269 cmd_params->dest_priority = cfg->dest_cfg.priority;
2270 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
2271 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
2272 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
2273 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
2274 dpni_set_field(cmd_params->type_units,
2276 cfg->dest_cfg.dest_type);
2277 dpni_set_field(cmd_params->type_units,
2281 /* send command to mc*/
2282 return mc_send_command(mc_io, &cmd);
2286 * dpni_get_congestion_notification() - Get traffic class congestion
2287 * notification configuration
2288 * @mc_io: Pointer to MC portal's I/O object
2289 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2290 * @token: Token of DPNI object
2291 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2292 * @param: Traffic class and channel. Bits[0-7] contain traaffic class,
2293 * byte[8-15] contains channel id
2294 * @cfg: congestion notification configuration
2296 * Return: '0' on Success; error code otherwise.
2298 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
2301 enum dpni_queue_type qtype,
2303 struct dpni_congestion_notification_cfg *cfg)
2305 struct dpni_rsp_get_congestion_notification *rsp_params;
2306 struct dpni_cmd_get_congestion_notification *cmd_params;
2307 struct mc_command cmd = { 0 };
2310 /* prepare command */
2311 cmd.header = mc_encode_cmd_header(
2312 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
2315 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
2316 cmd_params->qtype = qtype;
2317 cmd_params->tc = (uint8_t)(param & 0xff);
2318 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2319 cmd_params->congestion_point = cfg->cg_point;
2320 cmd_params->cgid = cfg->cgid;
2322 /* send command to mc*/
2323 err = mc_send_command(mc_io, &cmd);
2327 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
2328 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
2329 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
2330 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
2331 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
2332 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
2333 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
2334 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
2335 cfg->dest_cfg.priority = rsp_params->dest_priority;
2336 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
2343 * dpni_get_api_version() - Get Data Path Network Interface API version
2344 * @mc_io: Pointer to MC portal's I/O object
2345 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2346 * @major_ver: Major version of data path network interface API
2347 * @minor_ver: Minor version of data path network interface API
2349 * Return: '0' on Success; Error code otherwise.
2351 int dpni_get_api_version(struct fsl_mc_io *mc_io,
2353 uint16_t *major_ver,
2354 uint16_t *minor_ver)
2356 struct dpni_rsp_get_api_version *rsp_params;
2357 struct mc_command cmd = { 0 };
2360 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
2364 err = mc_send_command(mc_io, &cmd);
2368 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
2369 *major_ver = le16_to_cpu(rsp_params->major);
2370 *minor_ver = le16_to_cpu(rsp_params->minor);
2376 * dpni_set_queue() - Set queue parameters
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 * @qtype: Type of queue - all queue types are supported, although
2381 * the command is ignored for Tx
2382 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2383 * @index: Selects the specific queue out of the set allocated for the
2384 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2385 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
2386 * configuration options are set on the queue
2387 * @queue: Queue structure
2389 * Return: '0' on Success; Error code otherwise.
2391 int dpni_set_queue(struct fsl_mc_io *mc_io,
2394 enum dpni_queue_type qtype,
2398 const struct dpni_queue *queue)
2400 struct mc_command cmd = { 0 };
2401 struct dpni_cmd_set_queue *cmd_params;
2403 /* prepare command */
2404 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
2407 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
2408 cmd_params->qtype = qtype;
2409 cmd_params->tc = (uint8_t)(param & 0xff);
2410 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2411 cmd_params->index = index;
2412 cmd_params->options = options;
2413 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
2414 cmd_params->dest_prio = queue->destination.priority;
2415 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
2416 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
2417 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
2418 queue->destination.hold_active);
2419 cmd_params->flc = cpu_to_le64(queue->flc.value);
2420 cmd_params->user_context = cpu_to_le64(queue->user_context);
2421 cmd_params->cgid = queue->cgid;
2423 /* send command to mc */
2424 return mc_send_command(mc_io, &cmd);
2428 * dpni_get_queue() - Get queue parameters
2429 * @mc_io: Pointer to MC portal's I/O object
2430 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2431 * @token: Token of DPNI object
2432 * @qtype: Type of queue - all queue types are supported
2433 * @param: Traffic class and channel ID.
2434 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2435 * ignored for the rest
2436 * LSB - traffic class
2437 * Use macro DPNI_BUILD_PARAM() to build correct value.
2438 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2439 * traffic class directly.
2440 * @index: Selects the specific queue out of the set allocated for the
2441 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2442 * @queue: Queue configuration structure
2443 * @qid: Queue identification
2445 * Return: '0' on Success; Error code otherwise.
2447 int dpni_get_queue(struct fsl_mc_io *mc_io,
2450 enum dpni_queue_type qtype,
2453 struct dpni_queue *queue,
2454 struct dpni_queue_id *qid)
2456 struct mc_command cmd = { 0 };
2457 struct dpni_cmd_get_queue *cmd_params;
2458 struct dpni_rsp_get_queue *rsp_params;
2461 /* prepare command */
2462 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
2465 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
2466 cmd_params->qtype = qtype;
2467 cmd_params->tc = (uint8_t)(param & 0xff);
2468 cmd_params->index = index;
2469 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2471 /* send command to mc */
2472 err = mc_send_command(mc_io, &cmd);
2476 /* retrieve response parameters */
2477 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2478 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2479 queue->destination.priority = rsp_params->dest_prio;
2480 queue->destination.type = dpni_get_field(rsp_params->flags,
2482 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2484 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2486 queue->flc.value = le64_to_cpu(rsp_params->flc);
2487 queue->user_context = le64_to_cpu(rsp_params->user_context);
2488 qid->fqid = le32_to_cpu(rsp_params->fqid);
2489 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2490 if (dpni_get_field(rsp_params->flags, CGID_VALID))
2491 queue->cgid = rsp_params->cgid;
2499 * dpni_get_statistics() - Get DPNI statistics
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 * @page: Selects the statistics page to retrieve, see
2504 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
2505 * @param: Custom parameter for some pages used to select
2506 * a certain statistic source, for example the TC.
2507 * - page_0: not used
2508 * - page_1: not used
2509 * - page_2: not used
2510 * - page_3: high_byte - channel_id, low_byte - traffic class
2511 * - page_4: high_byte - queue_index have meaning only if dpni is
2512 * created using option DPNI_OPT_CUSTOM_CG, low_byte - traffic class
2513 * - page_5: not used
2514 * - page_6: not used
2515 * @stat: Structure containing the statistics
2517 * Return: '0' on Success; Error code otherwise.
2519 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2524 union dpni_statistics *stat)
2526 struct mc_command cmd = { 0 };
2527 struct dpni_cmd_get_statistics *cmd_params;
2528 struct dpni_rsp_get_statistics *rsp_params;
2531 /* prepare command */
2532 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2535 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2536 cmd_params->page_number = page;
2537 cmd_params->param = param;
2539 /* send command to mc */
2540 err = mc_send_command(mc_io, &cmd);
2544 /* retrieve response parameters */
2545 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2546 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2547 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2553 * dpni_reset_statistics() - Clears DPNI statistics
2554 * @mc_io: Pointer to MC portal's I/O object
2555 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2556 * @token: Token of DPNI object
2558 * Return: '0' on Success; Error code otherwise.
2560 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2564 struct mc_command cmd = { 0 };
2566 /* prepare command */
2567 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2571 /* send command to mc*/
2572 return mc_send_command(mc_io, &cmd);
2576 * dpni_set_taildrop() - Set taildrop per congestion group
2578 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2579 * congestion notification or early drop (WRED) configuration previously applied
2582 * @mc_io: Pointer to MC portal's I/O object
2583 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2584 * @token: Token of DPNI object
2585 * @cg_point: Congestion group identifier DPNI_CP_QUEUE is only supported in
2586 * combination with DPNI_QUEUE_RX.
2587 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2588 * @tc: Traffic class to apply this taildrop to
2589 * @index/cgid: Index of the queue if the DPNI supports multiple queues for
2590 * traffic distribution.
2591 * If CONGESTION_POINT is DPNI_CP_CONGESTION_GROUP then it
2592 * represent the cgid of the congestion point
2593 * @taildrop: Taildrop structure
2595 * Return: '0' on Success; Error code otherwise.
2597 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2600 enum dpni_congestion_point cg_point,
2601 enum dpni_queue_type qtype,
2604 struct dpni_taildrop *taildrop)
2606 struct mc_command cmd = { 0 };
2607 struct dpni_cmd_set_taildrop *cmd_params;
2609 /* prepare command */
2610 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2613 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2614 cmd_params->congestion_point = cg_point;
2615 cmd_params->qtype = qtype;
2616 cmd_params->tc = (uint8_t)(param & 0xff);
2617 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2618 cmd_params->index = index;
2619 cmd_params->units = taildrop->units;
2620 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2621 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2622 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2623 dpni_set_field(cmd_params->oal_hi,
2625 taildrop->oal >> DPNI_OAL_LO_SIZE);
2627 /* send command to mc */
2628 return mc_send_command(mc_io, &cmd);
2632 * dpni_get_taildrop() - Get taildrop information
2633 * @mc_io: Pointer to MC portal's I/O object
2634 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2635 * @token: Token of DPNI object
2636 * @cg_point: Congestion point
2637 * @q_type: Queue type on which the taildrop is configured.
2638 * Only Rx queues are supported for now
2639 * @tc: Traffic class to apply this taildrop to
2640 * @q_index: Index of the queue if the DPNI supports multiple queues for
2641 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2642 * @taildrop: Taildrop structure
2644 * Return: '0' on Success; Error code otherwise.
2646 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2649 enum dpni_congestion_point cg_point,
2650 enum dpni_queue_type qtype,
2653 struct dpni_taildrop *taildrop)
2655 struct mc_command cmd = { 0 };
2656 struct dpni_cmd_get_taildrop *cmd_params;
2657 struct dpni_rsp_get_taildrop *rsp_params;
2658 uint8_t oal_lo, oal_hi;
2661 /* prepare command */
2662 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2665 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2666 cmd_params->congestion_point = cg_point;
2667 cmd_params->qtype = qtype;
2668 cmd_params->tc = tc;
2669 cmd_params->index = index;
2671 /* send command to mc */
2672 err = mc_send_command(mc_io, &cmd);
2676 /* retrieve response parameters */
2677 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2678 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2679 taildrop->units = rsp_params->units;
2680 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2681 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2682 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2683 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2685 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2686 if (taildrop->oal >= 0x0800)
2687 taildrop->oal |= 0xF000;
2693 * dpni_set_opr() - Set Order Restoration configuration.
2694 * @mc_io: Pointer to MC portal's I/O object
2695 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2696 * @token: Token of DPNI object
2697 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2698 * @index: Selects the specific queue out of the set allocated
2699 * for the same TC. Value must be in range 0 to
2701 * @options: Configuration mode options
2702 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2703 * @cfg: Configuration options for the OPR
2705 * Return: '0' on Success; Error code otherwise.
2707 int dpni_set_opr(struct fsl_mc_io *mc_io,
2713 struct opr_cfg *cfg,
2716 struct dpni_cmd_set_opr *cmd_params;
2717 struct mc_command cmd = { 0 };
2719 /* prepare command */
2720 cmd.header = mc_encode_cmd_header(
2724 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2725 cmd_params->tc_id = tc;
2726 cmd_params->index = index;
2727 cmd_params->options = options;
2728 cmd_params->opr_id = opr_id;
2729 cmd_params->oloe = cfg->oloe;
2730 cmd_params->oeane = cfg->oeane;
2731 cmd_params->olws = cfg->olws;
2732 cmd_params->oa = cfg->oa;
2733 cmd_params->oprrws = cfg->oprrws;
2735 /* send command to mc*/
2736 return mc_send_command(mc_io, &cmd);
2740 * dpni_get_opr() - Retrieve Order Restoration config and query.
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 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2745 * @index: Selects the specific queue out of the set allocated
2746 * for the same TC. Value must be in range 0 to
2748 * @cfg: Returned OPR configuration
2749 * @qry: Returned OPR query
2751 * Return: '0' on Success; Error code otherwise.
2753 int dpni_get_opr(struct fsl_mc_io *mc_io,
2758 struct opr_cfg *cfg,
2759 struct opr_qry *qry,
2763 struct dpni_rsp_get_opr *rsp_params;
2764 struct dpni_cmd_get_opr *cmd_params;
2765 struct mc_command cmd = { 0 };
2768 /* prepare command */
2769 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2772 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2773 cmd_params->index = index;
2774 cmd_params->tc_id = tc;
2775 cmd_params->flags = flags;
2776 cmd_params->opr_id = opr_id;
2778 /* send command to mc*/
2779 err = mc_send_command(mc_io, &cmd);
2783 /* retrieve response parameters */
2784 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2785 cfg->oloe = rsp_params->oloe;
2786 cfg->oeane = rsp_params->oeane;
2787 cfg->olws = rsp_params->olws;
2788 cfg->oa = rsp_params->oa;
2789 cfg->oprrws = rsp_params->oprrws;
2790 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2791 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2792 qry->nesn = le16_to_cpu(rsp_params->nesn);
2793 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2794 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2795 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2796 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2797 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2798 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2799 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2800 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2801 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2806 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
2809 struct dpni_load_ss_cfg *cfg)
2811 struct dpni_load_sw_sequence *cmd_params;
2812 struct mc_command cmd = { 0 };
2814 /* prepare command */
2815 cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE,
2818 cmd_params = (struct dpni_load_sw_sequence *)cmd.params;
2819 cmd_params->dest = cfg->dest;
2820 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2821 cmd_params->ss_size = cpu_to_le16(cfg->ss_size);
2822 cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova);
2824 /* send command to mc*/
2825 return mc_send_command(mc_io, &cmd);
2828 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
2831 struct dpni_enable_ss_cfg *cfg)
2833 struct dpni_enable_sw_sequence *cmd_params;
2834 struct mc_command cmd = { 0 };
2836 /* prepare command */
2837 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE,
2840 cmd_params = (struct dpni_enable_sw_sequence *)cmd.params;
2841 cmd_params->dest = cfg->dest;
2842 cmd_params->set_start = cfg->set_start;
2843 cmd_params->hxs = cpu_to_le16(cfg->hxs);
2844 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2845 cmd_params->param_offset = cfg->param_offset;
2846 cmd_params->param_size = cfg->param_size;
2847 cmd_params->param_iova = cpu_to_le64(cfg->param_iova);
2849 /* send command to mc*/
2850 return mc_send_command(mc_io, &cmd);
2854 * dpni_get_sw_sequence_layout() - Get the soft sequence layout
2855 * @mc_io: Pointer to MC portal's I/O object
2856 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2857 * @token: Token of DPNI object
2858 * @src: Source of the layout (WRIOP Rx or Tx)
2859 * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory
2861 * warning: After calling this function, call dpni_extract_sw_sequence_layout()
2862 * to get the layout.
2864 * Return: '0' on Success; error code otherwise.
2866 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
2869 enum dpni_soft_sequence_dest src,
2870 uint64_t ss_layout_iova)
2872 struct dpni_get_sw_sequence_layout *cmd_params;
2873 struct mc_command cmd = { 0 };
2875 /* prepare command */
2876 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT,
2880 cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params;
2881 cmd_params->src = src;
2882 cmd_params->layout_iova = cpu_to_le64(ss_layout_iova);
2884 /* send command to mc*/
2885 return mc_send_command(mc_io, &cmd);
2889 * dpni_extract_sw_sequence_layout() - extract the software sequence layout
2890 * @layout: software sequence layout
2891 * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it
2894 * This function has to be called after dpni_get_sw_sequence_layout
2897 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
2898 const uint8_t *sw_sequence_layout_buf)
2900 const struct dpni_sw_sequence_layout_entry *ext_params;
2902 uint16_t ss_size, ss_offset;
2904 ext_params = (const struct dpni_sw_sequence_layout_entry *)
2905 sw_sequence_layout_buf;
2907 for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) {
2908 ss_offset = le16_to_cpu(ext_params[i].ss_offset);
2909 ss_size = le16_to_cpu(ext_params[i].ss_size);
2911 if (ss_offset == 0 && ss_size == 0) {
2916 layout->ss[i].ss_offset = ss_offset;
2917 layout->ss[i].ss_size = ss_size;
2918 layout->ss[i].param_offset = ext_params[i].param_offset;
2919 layout->ss[i].param_size = ext_params[i].param_size;
2923 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2924 * @mc_io: Pointer to MC portal's I/O object
2925 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2926 * @token: Token of DPNI object
2927 * @cfg: Distribution configuration
2928 * If the FS is already enabled with a previous call the classification
2929 * key will be changed but all the table rules are kept. If the
2930 * existing rules do not match the key the results will not be
2931 * predictable. It is the user responsibility to keep keyintegrity.
2932 * If cfg.enable is set to 1 the command will create a flow steering table
2933 * and will classify packets according to this table. The packets
2934 * that miss all the table rules will be classified according to
2935 * settings made in dpni_set_rx_hash_dist()
2936 * If cfg.enable is set to 0 the command will clear flow steering table. The
2937 * packets will be classified according to settings made in
2938 * dpni_set_rx_hash_dist()
2940 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2941 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2943 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2944 struct mc_command cmd = { 0 };
2946 /* prepare command */
2947 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2950 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2951 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2952 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2953 cmd_params->tc = cfg->tc;
2954 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2955 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2957 /* send command to mc*/
2958 return mc_send_command(mc_io, &cmd);
2962 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2963 * @mc_io: Pointer to MC portal's I/O object
2964 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2965 * @token: Token of DPNI object
2966 * @cfg: Distribution configuration
2967 * If cfg.enable is set to 1 the packets will be classified using a hash
2968 * function based on the key received in cfg.key_cfg_iova parameter.
2969 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2970 * dpni_set_rx_dist_default_queue() call
2972 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2973 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2975 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2976 struct mc_command cmd = { 0 };
2978 /* prepare command */
2979 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2982 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2983 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2984 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2985 cmd_params->tc_id = cfg->tc;
2986 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2988 /* send command to mc*/
2989 return mc_send_command(mc_io, &cmd);
2993 * dpni_add_custom_tpid() - Configures a distinct Ethertype value (or TPID
2994 * value) to indicate VLAN tag in adition to the common TPID values
2995 * 0x81000 and 0x88A8
2996 * @mc_io: Pointer to MC portal's I/O object
2997 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2998 * @token: Token of DPNI object
2999 * @tpid: New value for TPID
3001 * Only two custom values are accepted. If the function is called for the third
3002 * time it will return error.
3003 * To replace an existing value use dpni_remove_custom_tpid() to remove a
3004 * previous TPID and after that use again the function.
3006 * Return: '0' on Success; Error code otherwise.
3008 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3009 uint16_t token, uint16_t tpid)
3011 struct dpni_cmd_add_custom_tpid *cmd_params;
3012 struct mc_command cmd = { 0 };
3014 /* prepare command */
3015 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
3018 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
3019 cmd_params->tpid = cpu_to_le16(tpid);
3021 /* send command to mc*/
3022 return mc_send_command(mc_io, &cmd);
3026 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
3027 * previously with dpni_add_custom_tpid()
3028 * @mc_io: Pointer to MC portal's I/O object
3029 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3030 * @token: Token of DPNI object
3031 * @tpid: New value for TPID
3033 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
3036 * Return: '0' on Success; Error code otherwise.
3038 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3039 uint16_t token, uint16_t tpid)
3041 struct dpni_cmd_remove_custom_tpid *cmd_params;
3042 struct mc_command cmd = { 0 };
3044 /* prepare command */
3045 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
3048 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
3049 cmd_params->tpid = cpu_to_le16(tpid);
3051 /* send command to mc*/
3052 return mc_send_command(mc_io, &cmd);
3056 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured to
3057 * detect 802.1q frames
3058 * @mc_io: Pointer to MC portal's I/O object
3059 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3060 * @token: Token of DPNI object
3061 * @tpid: TPID values. Only nonzero members of the structure are valid.
3063 * Return: '0' on Success; Error code otherwise.
3065 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3066 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
3068 struct dpni_rsp_get_custom_tpid *rsp_params;
3069 struct mc_command cmd = { 0 };
3072 /* prepare command */
3073 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
3077 /* send command to mc*/
3078 err = mc_send_command(mc_io, &cmd);
3082 /* read command response */
3083 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
3084 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
3085 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
3091 * dpni_set_port_cfg() - performs configurations at physical port connected on
3092 * this dpni. The command have effect only if dpni is connected to
3093 * another dpni object
3094 * @mc_io: Pointer to MC portal's I/O object
3095 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3096 * @token: Token of DPNI object
3097 * @flags: Valid fields from port_cfg structure
3098 * @port_cfg: Configuration data; one or more of DPNI_PORT_CFG_
3099 * The command can be called only when dpni is connected to a dpmac object. If
3100 * the dpni is unconnected or the endpoint is not a dpni it will return error.
3101 * If dpmac endpoint is disconnected the settings will be lost
3103 int dpni_set_port_cfg(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3104 uint16_t token, uint32_t flags, struct dpni_port_cfg *port_cfg)
3106 struct dpni_cmd_set_port_cfg *cmd_params;
3107 struct mc_command cmd = { 0 };
3109 /* prepare command */
3110 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PORT_CFG,
3113 cmd_params = (struct dpni_cmd_set_port_cfg *)cmd.params;
3114 cmd_params->flags = cpu_to_le32(flags);
3115 dpni_set_field(cmd_params->bit_params, PORT_LOOPBACK_EN,
3116 !!port_cfg->loopback_en);
3118 /* send command to MC */
3119 return mc_send_command(mc_io, &cmd);