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_state() - Return the link state (either up or down)
921 * @mc_io: Pointer to MC portal's I/O object
922 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
923 * @token: Token of DPNI object
924 * @state: Returned link state;
926 * Return: '0' on Success; Error code otherwise.
928 int dpni_get_link_state(struct fsl_mc_io *mc_io,
931 struct dpni_link_state *state)
933 struct mc_command cmd = { 0 };
934 struct dpni_rsp_get_link_state *rsp_params;
937 /* prepare command */
938 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
942 /* send command to mc*/
943 err = mc_send_command(mc_io, &cmd);
947 /* retrieve response parameters */
948 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
949 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
950 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
951 state->rate = le32_to_cpu(rsp_params->rate);
952 state->options = le64_to_cpu(rsp_params->options);
953 state->supported = le64_to_cpu(rsp_params->supported);
954 state->advertising = le64_to_cpu(rsp_params->advertising);
960 * dpni_set_tx_shaping() - Set the transmit shaping
961 * @mc_io: Pointer to MC portal's I/O object
962 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
963 * @token: Token of DPNI object
964 * @tx_cr_shaper: TX committed rate shaping configuration
965 * @tx_er_shaper: TX excess rate shaping configuration
966 * @param: Special parameters
967 * bit0: Committed and excess rates are coupled
968 * bit1: 1 modify LNI shaper, 0 modify channel shaper
969 * bit8-15: Tx channel to be shaped. Used only if bit1 is set to zero
970 * bits16-26: OAL (Overhead accounting length 11bit value). Used only
973 * Return: '0' on Success; Error code otherwise.
975 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
978 const struct dpni_tx_shaping_cfg *tx_cr_shaper,
979 const struct dpni_tx_shaping_cfg *tx_er_shaper,
982 struct dpni_cmd_set_tx_shaping *cmd_params;
983 struct mc_command cmd = { 0 };
984 int coupled, lni_shaper;
988 /* prepare command */
989 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
992 cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
993 cmd_params->tx_cr_max_burst_size =
994 cpu_to_le16(tx_cr_shaper->max_burst_size);
995 cmd_params->tx_er_max_burst_size =
996 cpu_to_le16(tx_er_shaper->max_burst_size);
997 cmd_params->tx_cr_rate_limit =
998 cpu_to_le32(tx_cr_shaper->rate_limit);
999 cmd_params->tx_er_rate_limit =
1000 cpu_to_le32(tx_er_shaper->rate_limit);
1002 coupled = !!(param & 0x01);
1003 dpni_set_field(cmd_params->options, COUPLED, coupled);
1005 lni_shaper = !!((param >> 1) & 0x01);
1006 dpni_set_field(cmd_params->options, LNI_SHAPER, lni_shaper);
1008 channel_id = (param >> 8) & 0xff;
1009 cmd_params->channel_id = channel_id;
1011 oal = (param >> 16) & 0x7FF;
1012 cmd_params->oal = cpu_to_le16(oal);
1014 /* send command to mc*/
1015 return mc_send_command(mc_io, &cmd);
1019 * dpni_set_max_frame_length() - Set the maximum received frame length.
1020 * @mc_io: Pointer to MC portal's I/O object
1021 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1022 * @token: Token of DPNI object
1023 * @max_frame_length: Maximum received frame length (in bytes);
1024 * frame is discarded if its length exceeds this value
1026 * Return: '0' on Success; Error code otherwise.
1028 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
1031 uint16_t max_frame_length)
1033 struct mc_command cmd = { 0 };
1034 struct dpni_cmd_set_max_frame_length *cmd_params;
1036 /* prepare command */
1037 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
1040 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
1041 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
1043 /* send command to mc*/
1044 return mc_send_command(mc_io, &cmd);
1048 * dpni_get_max_frame_length() - Get the maximum received frame length.
1049 * @mc_io: Pointer to MC portal's I/O object
1050 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1051 * @token: Token of DPNI object
1052 * @max_frame_length: Maximum received frame length (in bytes);
1053 * frame is discarded if its length exceeds this value
1055 * Return: '0' on Success; Error code otherwise.
1057 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
1060 uint16_t *max_frame_length)
1062 struct mc_command cmd = { 0 };
1063 struct dpni_rsp_get_max_frame_length *rsp_params;
1066 /* prepare command */
1067 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1071 /* send command to mc*/
1072 err = mc_send_command(mc_io, &cmd);
1076 /* retrieve response parameters */
1077 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1078 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1084 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1085 * @mc_io: Pointer to MC portal's I/O object
1086 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1087 * @token: Token of DPNI object
1088 * @en: Set to '1' to enable; '0' to disable
1090 * Return: '0' on Success; Error code otherwise.
1092 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1097 struct mc_command cmd = { 0 };
1098 struct dpni_cmd_set_multicast_promisc *cmd_params;
1100 /* prepare command */
1101 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1104 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1105 dpni_set_field(cmd_params->enable, ENABLE, en);
1107 /* send command to mc*/
1108 return mc_send_command(mc_io, &cmd);
1112 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1113 * @mc_io: Pointer to MC portal's I/O object
1114 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1115 * @token: Token of DPNI object
1116 * @en: Returns '1' if enabled; '0' otherwise
1118 * Return: '0' on Success; Error code otherwise.
1120 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1125 struct mc_command cmd = { 0 };
1126 struct dpni_rsp_get_multicast_promisc *rsp_params;
1129 /* prepare command */
1130 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1134 /* send command to mc*/
1135 err = mc_send_command(mc_io, &cmd);
1139 /* retrieve response parameters */
1140 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1141 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1147 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1148 * @mc_io: Pointer to MC portal's I/O object
1149 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1150 * @token: Token of DPNI object
1151 * @en: Set to '1' to enable; '0' to disable
1153 * Return: '0' on Success; Error code otherwise.
1155 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1160 struct mc_command cmd = { 0 };
1161 struct dpni_cmd_set_unicast_promisc *cmd_params;
1163 /* prepare command */
1164 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1167 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1168 dpni_set_field(cmd_params->enable, ENABLE, en);
1170 /* send command to mc*/
1171 return mc_send_command(mc_io, &cmd);
1175 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1176 * @mc_io: Pointer to MC portal's I/O object
1177 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1178 * @token: Token of DPNI object
1179 * @en: Returns '1' if enabled; '0' otherwise
1181 * Return: '0' on Success; Error code otherwise.
1183 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1188 struct mc_command cmd = { 0 };
1189 struct dpni_rsp_get_unicast_promisc *rsp_params;
1192 /* prepare command */
1193 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1197 /* send command to mc*/
1198 err = mc_send_command(mc_io, &cmd);
1202 /* retrieve response parameters */
1203 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1204 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1210 * dpni_set_primary_mac_addr() - Set the primary MAC address
1211 * @mc_io: Pointer to MC portal's I/O object
1212 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1213 * @token: Token of DPNI object
1214 * @mac_addr: MAC address to set as primary address
1216 * Return: '0' on Success; Error code otherwise.
1218 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1221 const uint8_t mac_addr[6])
1223 struct mc_command cmd = { 0 };
1224 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1227 /* prepare command */
1228 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1231 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1232 for (i = 0; i < 6; i++)
1233 cmd_params->mac_addr[i] = mac_addr[5 - i];
1235 /* send command to mc*/
1236 return mc_send_command(mc_io, &cmd);
1240 * dpni_get_primary_mac_addr() - Get the primary MAC address
1241 * @mc_io: Pointer to MC portal's I/O object
1242 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1243 * @token: Token of DPNI object
1244 * @mac_addr: Returned MAC address
1246 * Return: '0' on Success; Error code otherwise.
1248 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1251 uint8_t mac_addr[6])
1253 struct mc_command cmd = { 0 };
1254 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1257 /* prepare command */
1258 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1262 /* send command to mc*/
1263 err = mc_send_command(mc_io, &cmd);
1267 /* retrieve response parameters */
1268 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1269 for (i = 0; i < 6; i++)
1270 mac_addr[5 - i] = rsp_params->mac_addr[i];
1276 * dpni_add_mac_addr() - Add MAC address filter
1277 * @mc_io: Pointer to MC portal's I/O object
1278 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1279 * @token: Token of DPNI object
1280 * @mac_addr: MAC address to add
1281 * @flags : 0 - tc_id and flow_id will be ignored.
1282 * Pkt with this mac_id will be passed to the next
1283 * classification stages
1284 * DPNI_MAC_SET_QUEUE_ACTION
1285 * Pkt with this mac will be forward directly to
1286 * queue defined by the tc_id and flow_id
1287 * @tc_id : Traffic class selection (0-7)
1288 * @flow_id : Selects the specific queue out of the set allocated for the
1289 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1290 * Return: '0' on Success; Error code otherwise.
1292 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1295 const uint8_t mac_addr[6],
1300 struct mc_command cmd = { 0 };
1301 struct dpni_cmd_add_mac_addr *cmd_params;
1304 /* prepare command */
1305 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1308 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1309 cmd_params->flags = flags;
1310 cmd_params->tc_id = tc_id;
1311 cmd_params->fq_id = flow_id;
1313 for (i = 0; i < 6; i++)
1314 cmd_params->mac_addr[i] = mac_addr[5 - i];
1316 /* send command to mc*/
1317 return mc_send_command(mc_io, &cmd);
1321 * dpni_remove_mac_addr() - Remove MAC address filter
1322 * @mc_io: Pointer to MC portal's I/O object
1323 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1324 * @token: Token of DPNI object
1325 * @mac_addr: MAC address to remove
1327 * Return: '0' on Success; Error code otherwise.
1329 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1332 const uint8_t mac_addr[6])
1334 struct mc_command cmd = { 0 };
1335 struct dpni_cmd_remove_mac_addr *cmd_params;
1338 /* prepare command */
1339 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1342 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1343 for (i = 0; i < 6; i++)
1344 cmd_params->mac_addr[i] = mac_addr[5 - i];
1346 /* send command to mc*/
1347 return mc_send_command(mc_io, &cmd);
1351 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1352 * @mc_io: Pointer to MC portal's I/O object
1353 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1354 * @token: Token of DPNI object
1355 * @unicast: Set to '1' to clear unicast addresses
1356 * @multicast: Set to '1' to clear multicast addresses
1358 * The primary MAC address is not cleared by this operation.
1360 * Return: '0' on Success; Error code otherwise.
1362 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1368 struct mc_command cmd = { 0 };
1369 struct dpni_cmd_clear_mac_filters *cmd_params;
1371 /* prepare command */
1372 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1375 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1376 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1377 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1379 /* send command to mc*/
1380 return mc_send_command(mc_io, &cmd);
1384 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1385 * port the DPNI is attached to
1386 * @mc_io: Pointer to MC portal's I/O object
1387 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1388 * @token: Token of DPNI object
1389 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1391 * The primary MAC address is not cleared by this operation.
1393 * Return: '0' on Success; Error code otherwise.
1395 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1398 uint8_t mac_addr[6])
1400 struct mc_command cmd = { 0 };
1401 struct dpni_rsp_get_port_mac_addr *rsp_params;
1404 /* prepare command */
1405 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1409 /* send command to mc*/
1410 err = mc_send_command(mc_io, &cmd);
1414 /* retrieve response parameters */
1415 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1416 for (i = 0; i < 6; i++)
1417 mac_addr[5 - i] = rsp_params->mac_addr[i];
1423 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
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 * @en: Set to '1' to enable; '0' to disable
1429 * Return: '0' on Success; Error code otherwise.
1431 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1436 struct dpni_cmd_enable_vlan_filter *cmd_params;
1437 struct mc_command cmd = { 0 };
1439 /* prepare command */
1440 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1443 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1444 dpni_set_field(cmd_params->en, ENABLE, en);
1446 /* send command to mc*/
1447 return mc_send_command(mc_io, &cmd);
1451 * dpni_add_vlan_id() - Add VLAN ID filter
1452 * @mc_io: Pointer to MC portal's I/O object
1453 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1454 * @token: Token of DPNI object
1455 * @vlan_id: VLAN ID to add
1456 * @flags: 0 - tc_id and flow_id will be ignored.
1457 * Pkt with this vlan_id will be passed to the next
1458 * classification stages
1459 * DPNI_VLAN_SET_QUEUE_ACTION
1460 * Pkt with this vlan_id will be forward directly to
1461 * queue defined by the tc_id and flow_id
1463 * @tc_id: Traffic class selection (0-7)
1464 * @flow_id: Selects the specific queue out of the set allocated for the
1465 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1467 * Return: '0' on Success; Error code otherwise.
1469 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1477 struct dpni_cmd_vlan_id *cmd_params;
1478 struct mc_command cmd = { 0 };
1480 /* prepare command */
1481 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1484 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1485 cmd_params->flags = flags;
1486 cmd_params->tc_id = tc_id;
1487 cmd_params->flow_id = flow_id;
1488 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1490 /* send command to mc*/
1491 return mc_send_command(mc_io, &cmd);
1495 * dpni_remove_vlan_id() - Remove VLAN ID filter
1496 * @mc_io: Pointer to MC portal's I/O object
1497 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1498 * @token: Token of DPNI object
1499 * @vlan_id: VLAN ID to remove
1501 * Return: '0' on Success; Error code otherwise.
1503 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1508 struct dpni_cmd_vlan_id *cmd_params;
1509 struct mc_command cmd = { 0 };
1511 /* prepare command */
1512 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1515 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1516 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1518 /* send command to mc*/
1519 return mc_send_command(mc_io, &cmd);
1523 * dpni_clear_vlan_filters() - Clear all VLAN filters
1524 * @mc_io: Pointer to MC portal's I/O object
1525 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1526 * @token: Token of DPNI object
1528 * Return: '0' on Success; Error code otherwise.
1530 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1534 struct mc_command cmd = { 0 };
1536 /* prepare command */
1537 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1541 /* send command to mc*/
1542 return mc_send_command(mc_io, &cmd);
1546 * dpni_set_tx_priorities() - Set transmission TC priority configuration
1547 * @mc_io: Pointer to MC portal's I/O object
1548 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1549 * @token: Token of DPNI object
1550 * @cfg: Transmission selection configuration
1552 * warning: Allowed only when DPNI is disabled
1554 * Return: '0' on Success; Error code otherwise.
1556 int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
1559 const struct dpni_tx_priorities_cfg *cfg)
1561 struct dpni_cmd_set_tx_priorities *cmd_params;
1562 struct mc_command cmd = { 0 };
1565 /* prepare command */
1566 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES,
1569 cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params;
1570 cmd_params->channel_idx = cfg->channel_idx;
1571 dpni_set_field(cmd_params->flags,
1573 cfg->separate_groups);
1574 cmd_params->prio_group_A = cfg->prio_group_A;
1575 cmd_params->prio_group_B = cfg->prio_group_B;
1577 for (i = 0; i + 1 < DPNI_MAX_TC; i = i + 2) {
1578 dpni_set_field(cmd_params->modes[i / 2],
1580 cfg->tc_sched[i].mode);
1581 dpni_set_field(cmd_params->modes[i / 2],
1583 cfg->tc_sched[i + 1].mode);
1586 for (i = 0; i < DPNI_MAX_TC; i++) {
1587 cmd_params->delta_bandwidth[i] =
1588 cpu_to_le16(cfg->tc_sched[i].delta_bandwidth);
1591 /* send command to mc*/
1592 return mc_send_command(mc_io, &cmd);
1596 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1597 * @mc_io: Pointer to MC portal's I/O object
1598 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1599 * @token: Token of DPNI object
1600 * @tc_id: Traffic class selection (0-7)
1601 * @cfg: Traffic class distribution configuration
1603 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1604 * first to prepare the key_cfg_iova parameter
1606 * Return: '0' on Success; error code otherwise.
1608 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1612 const struct dpni_rx_tc_dist_cfg *cfg)
1614 struct mc_command cmd = { 0 };
1615 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1617 /* prepare command */
1618 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1621 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1622 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1623 cmd_params->tc_id = tc_id;
1624 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1625 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1626 dpni_set_field(cmd_params->flags,
1629 dpni_set_field(cmd_params->flags,
1631 cfg->fs_cfg.miss_action);
1632 dpni_set_field(cmd_params->keep_hash_key,
1634 cfg->fs_cfg.keep_hash_key);
1635 dpni_set_field(cmd_params->keep_hash_key,
1637 cfg->fs_cfg.keep_entries);
1639 /* send command to mc*/
1640 return mc_send_command(mc_io, &cmd);
1644 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1645 * @mc_io: Pointer to MC portal's I/O object
1646 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1647 * @token: Token of DPNI object
1648 * @mode: Tx confirmation mode
1650 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1651 * selected at DPNI creation.
1652 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1653 * transmit confirmation (including the private confirmation queues), regardless
1654 * of previous settings; Note that in this case, Tx error frames are still
1655 * enqueued to the general transmit errors queue.
1656 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1657 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1658 * command will be ignored.
1660 * Return: '0' on Success; Error code otherwise.
1662 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1665 enum dpni_confirmation_mode mode)
1667 struct dpni_tx_confirmation_mode *cmd_params;
1668 struct mc_command cmd = { 0 };
1670 /* prepare command */
1671 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1674 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1675 cmd_params->confirmation_mode = mode;
1677 /* send command to mc*/
1678 return mc_send_command(mc_io, &cmd);
1682 * dpni_set_qos_table() - Set QoS mapping table
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 * @cfg: QoS table configuration
1688 * This function and all QoS-related functions require that
1689 *'max_tcs > 1' was set at DPNI creation.
1691 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1692 * prepare the key_cfg_iova parameter
1694 * Return: '0' on Success; Error code otherwise.
1696 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1699 const struct dpni_qos_tbl_cfg *cfg)
1701 struct dpni_cmd_set_qos_table *cmd_params;
1702 struct mc_command cmd = { 0 };
1704 /* prepare command */
1705 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1708 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1709 cmd_params->default_tc = cfg->default_tc;
1710 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1711 dpni_set_field(cmd_params->discard_on_miss,
1713 cfg->discard_on_miss);
1714 dpni_set_field(cmd_params->discard_on_miss,
1718 /* send command to mc*/
1719 return mc_send_command(mc_io, &cmd);
1723 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1724 * @mc_io: Pointer to MC portal's I/O object
1725 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1726 * @token: Token of DPNI object
1727 * @cfg: QoS rule to add
1728 * @tc_id: Traffic class selection (0-7)
1729 * @index: Location in the QoS table where to insert the entry.
1730 * Only relevant if MASKING is enabled for QoS classification on
1731 * this DPNI, it is ignored for exact match.
1733 * Return: '0' on Success; Error code otherwise.
1735 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1738 const struct dpni_rule_cfg *cfg,
1744 struct dpni_cmd_add_qos_entry *cmd_params;
1745 struct mc_command cmd = { 0 };
1747 /* prepare command */
1748 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1751 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1752 cmd_params->flags = flags;
1753 cmd_params->flow_id = flow_id;
1754 cmd_params->tc_id = tc_id;
1755 cmd_params->key_size = cfg->key_size;
1756 cmd_params->index = cpu_to_le16(index);
1757 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1758 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1760 /* send command to mc*/
1761 return mc_send_command(mc_io, &cmd);
1765 * dpni_remove_qos_entry() - Remove QoS mapping entry
1766 * @mc_io: Pointer to MC portal's I/O object
1767 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1768 * @token: Token of DPNI object
1769 * @cfg: QoS rule to remove
1771 * Return: '0' on Success; Error code otherwise.
1773 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1776 const struct dpni_rule_cfg *cfg)
1778 struct dpni_cmd_remove_qos_entry *cmd_params;
1779 struct mc_command cmd = { 0 };
1781 /* prepare command */
1782 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1785 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1786 cmd_params->key_size = cfg->key_size;
1787 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1788 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1790 /* send command to mc*/
1791 return mc_send_command(mc_io, &cmd);
1795 * dpni_clear_qos_table() - Clear all QoS mapping entries
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
1800 * Following this function call, all frames are directed to
1801 * the default traffic class (0)
1803 * Return: '0' on Success; Error code otherwise.
1805 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1809 struct mc_command cmd = { 0 };
1811 /* prepare command */
1812 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1816 /* send command to mc*/
1817 return mc_send_command(mc_io, &cmd);
1821 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1822 * (to select a flow ID)
1823 * @mc_io: Pointer to MC portal's I/O object
1824 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1825 * @token: Token of DPNI object
1826 * @tc_id: Traffic class selection (0-7)
1827 * @index: Location in the QoS table where to insert the entry.
1828 * Only relevant if MASKING is enabled for QoS classification
1829 * on this DPNI, it is ignored for exact match.
1830 * @cfg: Flow steering rule to add
1831 * @action: Action to be taken as result of a classification hit
1833 * Return: '0' on Success; Error code otherwise.
1835 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1840 const struct dpni_rule_cfg *cfg,
1841 const struct dpni_fs_action_cfg *action)
1843 struct dpni_cmd_add_fs_entry *cmd_params;
1844 struct mc_command cmd = { 0 };
1846 /* prepare command */
1847 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1850 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1851 cmd_params->tc_id = tc_id;
1852 cmd_params->key_size = cfg->key_size;
1853 cmd_params->index = cpu_to_le16(index);
1854 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1855 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1856 cmd_params->options = cpu_to_le16(action->options);
1857 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1858 cmd_params->flc = cpu_to_le64(action->flc);
1859 cmd_params->redir_token = cpu_to_le16(action->redirect_obj_token);
1861 /* send command to mc*/
1862 return mc_send_command(mc_io, &cmd);
1866 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1868 * @mc_io: Pointer to MC portal's I/O object
1869 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1870 * @token: Token of DPNI object
1871 * @tc_id: Traffic class selection (0-7)
1872 * @cfg: Flow steering rule to remove
1874 * Return: '0' on Success; Error code otherwise.
1876 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1880 const struct dpni_rule_cfg *cfg)
1882 struct dpni_cmd_remove_fs_entry *cmd_params;
1883 struct mc_command cmd = { 0 };
1885 /* prepare command */
1886 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1889 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1890 cmd_params->tc_id = tc_id;
1891 cmd_params->key_size = cfg->key_size;
1892 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1893 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1895 /* send command to mc*/
1896 return mc_send_command(mc_io, &cmd);
1900 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
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)
1907 * Return: '0' on Success; Error code otherwise.
1909 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1914 struct dpni_cmd_clear_fs_entries *cmd_params;
1915 struct mc_command cmd = { 0 };
1917 /* prepare command */
1918 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1921 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1922 cmd_params->tc_id = tc_id;
1924 /* send command to mc*/
1925 return mc_send_command(mc_io, &cmd);
1929 * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
1930 * @mc_io: Pointer to MC portal's I/O object
1931 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1932 * @token: Token of DPNI object
1933 * @tc_id: Traffic class selection (0-7)
1934 * @cfg: Traffic class policing configuration
1936 * Return: '0' on Success; error code otherwise.
1938 int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
1942 const struct dpni_rx_tc_policing_cfg *cfg)
1944 struct dpni_cmd_set_rx_tc_policing *cmd_params;
1945 struct mc_command cmd = { 0 };
1947 /* prepare command */
1948 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING,
1951 cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params;
1952 dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color);
1953 dpni_set_field(cmd_params->mode_color, MODE, cfg->mode);
1954 dpni_set_field(cmd_params->units, UNITS, cfg->units);
1955 cmd_params->options = cpu_to_le32(cfg->options);
1956 cmd_params->cir = cpu_to_le32(cfg->cir);
1957 cmd_params->cbs = cpu_to_le32(cfg->cbs);
1958 cmd_params->eir = cpu_to_le32(cfg->eir);
1959 cmd_params->ebs = cpu_to_le32(cfg->ebs);
1960 cmd_params->tc_id = tc_id;
1962 /* send command to mc*/
1963 return mc_send_command(mc_io, &cmd);
1967 * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration
1968 * @mc_io: Pointer to MC portal's I/O object
1969 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1970 * @token: Token of DPNI object
1971 * @tc_id: Traffic class selection (0-7)
1972 * @cfg: Traffic class policing configuration
1974 * Return: '0' on Success; error code otherwise.
1976 int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io,
1980 struct dpni_rx_tc_policing_cfg *cfg)
1982 struct dpni_rsp_get_rx_tc_policing *rsp_params;
1983 struct dpni_cmd_get_rx_tc_policing *cmd_params;
1984 struct mc_command cmd = { 0 };
1987 /* prepare command */
1988 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_TC_POLICING,
1991 cmd_params = (struct dpni_cmd_get_rx_tc_policing *)cmd.params;
1992 cmd_params->tc_id = tc_id;
1995 /* send command to mc*/
1996 err = mc_send_command(mc_io, &cmd);
2000 rsp_params = (struct dpni_rsp_get_rx_tc_policing *)cmd.params;
2001 cfg->options = le32_to_cpu(rsp_params->options);
2002 cfg->cir = le32_to_cpu(rsp_params->cir);
2003 cfg->cbs = le32_to_cpu(rsp_params->cbs);
2004 cfg->eir = le32_to_cpu(rsp_params->eir);
2005 cfg->ebs = le32_to_cpu(rsp_params->ebs);
2006 cfg->units = dpni_get_field(rsp_params->units, UNITS);
2007 cfg->mode = dpni_get_field(rsp_params->mode_color, MODE);
2008 cfg->default_color = dpni_get_field(rsp_params->mode_color, COLOR);
2014 * dpni_prepare_early_drop() - prepare an early drop.
2015 * @cfg: Early-drop configuration
2016 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2018 * This function has to be called before dpni_set_rx_tc_early_drop or
2019 * dpni_set_tx_tc_early_drop
2022 void dpni_prepare_early_drop(const struct dpni_early_drop_cfg *cfg,
2023 uint8_t *early_drop_buf)
2025 struct dpni_early_drop *ext_params;
2027 ext_params = (struct dpni_early_drop *)early_drop_buf;
2029 dpni_set_field(ext_params->flags, DROP_ENABLE, cfg->enable);
2030 dpni_set_field(ext_params->flags, DROP_UNITS, cfg->units);
2031 ext_params->green_drop_probability = cfg->green.drop_probability;
2032 ext_params->green_max_threshold = cpu_to_le64(cfg->green.max_threshold);
2033 ext_params->green_min_threshold = cpu_to_le64(cfg->green.min_threshold);
2034 ext_params->yellow_drop_probability = cfg->yellow.drop_probability;
2035 ext_params->yellow_max_threshold =
2036 cpu_to_le64(cfg->yellow.max_threshold);
2037 ext_params->yellow_min_threshold =
2038 cpu_to_le64(cfg->yellow.min_threshold);
2039 ext_params->red_drop_probability = cfg->red.drop_probability;
2040 ext_params->red_max_threshold = cpu_to_le64(cfg->red.max_threshold);
2041 ext_params->red_min_threshold = cpu_to_le64(cfg->red.min_threshold);
2045 * dpni_extract_early_drop() - extract the early drop configuration.
2046 * @cfg: Early-drop configuration
2047 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2049 * This function has to be called after dpni_get_rx_tc_early_drop or
2050 * dpni_get_tx_tc_early_drop
2053 void dpni_extract_early_drop(struct dpni_early_drop_cfg *cfg,
2054 const uint8_t *early_drop_buf)
2056 const struct dpni_early_drop *ext_params;
2058 ext_params = (const struct dpni_early_drop *)early_drop_buf;
2060 cfg->enable = dpni_get_field(ext_params->flags, DROP_ENABLE);
2061 cfg->units = dpni_get_field(ext_params->flags, DROP_UNITS);
2062 cfg->green.drop_probability = ext_params->green_drop_probability;
2063 cfg->green.max_threshold = le64_to_cpu(ext_params->green_max_threshold);
2064 cfg->green.min_threshold = le64_to_cpu(ext_params->green_min_threshold);
2065 cfg->yellow.drop_probability = ext_params->yellow_drop_probability;
2066 cfg->yellow.max_threshold =
2067 le64_to_cpu(ext_params->yellow_max_threshold);
2068 cfg->yellow.min_threshold =
2069 le64_to_cpu(ext_params->yellow_min_threshold);
2070 cfg->red.drop_probability = ext_params->red_drop_probability;
2071 cfg->red.max_threshold = le64_to_cpu(ext_params->red_max_threshold);
2072 cfg->red.min_threshold = le64_to_cpu(ext_params->red_min_threshold);
2076 * dpni_set_early_drop() - Set traffic class early-drop configuration
2077 * @mc_io: Pointer to MC portal's I/O object
2078 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2079 * @token: Token of DPNI object
2080 * @qtype: Type of queue - only Rx and Tx types are supported
2081 * @param: Traffic class and channel ID.
2082 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2083 * ignored for the rest
2084 * LSB - traffic class
2085 * Use macro DPNI_BUILD_PARAM() to build correct value.
2086 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2087 * traffic class directly.
2088 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory filled
2089 * with the early-drop configuration by calling dpni_prepare_early_drop()
2091 * warning: Before calling this function, call dpni_prepare_early_drop() to
2092 * prepare the early_drop_iova parameter
2094 * Return: '0' on Success; error code otherwise.
2096 int dpni_set_early_drop(struct fsl_mc_io *mc_io,
2099 enum dpni_queue_type qtype,
2101 uint64_t early_drop_iova)
2103 struct dpni_cmd_early_drop *cmd_params;
2104 struct mc_command cmd = { 0 };
2106 /* prepare command */
2107 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_EARLY_DROP,
2110 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2111 cmd_params->qtype = qtype;
2112 cmd_params->tc = (uint8_t)(param & 0xff);
2113 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2114 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2116 /* send command to mc*/
2117 return mc_send_command(mc_io, &cmd);
2121 * dpni_get_early_drop() - Get Rx traffic class early-drop configuration
2122 * @mc_io: Pointer to MC portal's I/O object
2123 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2124 * @token: Token of DPNI object
2125 * @qtype: Type of queue - only Rx and Tx types are supported
2126 * @param: Traffic class and channel ID.
2127 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2128 * ignored for the rest
2129 * LSB - traffic class
2130 * Use macro DPNI_BUILD_PARAM() to build correct value.
2131 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2132 * traffic class directly.
2133 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory
2135 * warning: After calling this function, call dpni_extract_early_drop() to
2136 * get the early drop configuration
2138 * Return: '0' on Success; error code otherwise.
2140 int dpni_get_early_drop(struct fsl_mc_io *mc_io,
2143 enum dpni_queue_type qtype,
2145 uint64_t early_drop_iova)
2147 struct dpni_cmd_early_drop *cmd_params;
2148 struct mc_command cmd = { 0 };
2150 /* prepare command */
2151 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_EARLY_DROP,
2154 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2155 cmd_params->qtype = qtype;
2156 cmd_params->tc = (uint8_t)(param & 0xff);
2157 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2158 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2160 /* send command to mc*/
2161 return mc_send_command(mc_io, &cmd);
2165 * dpni_set_congestion_notification() - Set traffic class congestion
2166 * notification configuration
2167 * @mc_io: Pointer to MC portal's I/O object
2168 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2169 * @token: Token of DPNI object
2170 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2171 * @tc_id: Traffic class selection (0-7)
2172 * @cfg: congestion notification configuration
2174 * Return: '0' on Success; error code otherwise.
2176 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
2179 enum dpni_queue_type qtype,
2181 const struct dpni_congestion_notification_cfg *cfg)
2183 struct dpni_cmd_set_congestion_notification *cmd_params;
2184 struct mc_command cmd = { 0 };
2186 /* prepare command */
2187 cmd.header = mc_encode_cmd_header(
2188 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
2191 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
2192 cmd_params->qtype = qtype;
2193 cmd_params->tc = (uint8_t)(param & 0xff);
2194 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2195 cmd_params->congestion_point = cfg->cg_point;
2196 cmd_params->cgid = (uint8_t)cfg->cgid;
2197 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
2198 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
2199 cmd_params->dest_priority = cfg->dest_cfg.priority;
2200 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
2201 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
2202 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
2203 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
2204 dpni_set_field(cmd_params->type_units,
2206 cfg->dest_cfg.dest_type);
2207 dpni_set_field(cmd_params->type_units,
2211 /* send command to mc*/
2212 return mc_send_command(mc_io, &cmd);
2216 * dpni_get_congestion_notification() - Get traffic class congestion
2217 * notification configuration
2218 * @mc_io: Pointer to MC portal's I/O object
2219 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2220 * @token: Token of DPNI object
2221 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2222 * @param: Traffic class and channel. Bits[0-7] contain traaffic class,
2223 * byte[8-15] contains channel id
2224 * @cfg: congestion notification configuration
2226 * Return: '0' on Success; error code otherwise.
2228 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
2231 enum dpni_queue_type qtype,
2233 struct dpni_congestion_notification_cfg *cfg)
2235 struct dpni_rsp_get_congestion_notification *rsp_params;
2236 struct dpni_cmd_get_congestion_notification *cmd_params;
2237 struct mc_command cmd = { 0 };
2240 /* prepare command */
2241 cmd.header = mc_encode_cmd_header(
2242 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
2245 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
2246 cmd_params->qtype = qtype;
2247 cmd_params->tc = (uint8_t)(param & 0xff);
2248 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2249 cmd_params->congestion_point = cfg->cg_point;
2250 cmd_params->cgid = cfg->cgid;
2252 /* send command to mc*/
2253 err = mc_send_command(mc_io, &cmd);
2257 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
2258 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
2259 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
2260 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
2261 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
2262 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
2263 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
2264 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
2265 cfg->dest_cfg.priority = rsp_params->dest_priority;
2266 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
2273 * dpni_get_api_version() - Get Data Path Network Interface API version
2274 * @mc_io: Pointer to MC portal's I/O object
2275 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2276 * @major_ver: Major version of data path network interface API
2277 * @minor_ver: Minor version of data path network interface API
2279 * Return: '0' on Success; Error code otherwise.
2281 int dpni_get_api_version(struct fsl_mc_io *mc_io,
2283 uint16_t *major_ver,
2284 uint16_t *minor_ver)
2286 struct dpni_rsp_get_api_version *rsp_params;
2287 struct mc_command cmd = { 0 };
2290 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
2294 err = mc_send_command(mc_io, &cmd);
2298 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
2299 *major_ver = le16_to_cpu(rsp_params->major);
2300 *minor_ver = le16_to_cpu(rsp_params->minor);
2306 * dpni_set_queue() - Set queue parameters
2307 * @mc_io: Pointer to MC portal's I/O object
2308 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2309 * @token: Token of DPNI object
2310 * @qtype: Type of queue - all queue types are supported, although
2311 * the command is ignored for Tx
2312 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2313 * @index: Selects the specific queue out of the set allocated for the
2314 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2315 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
2316 * configuration options are set on the queue
2317 * @queue: Queue structure
2319 * Return: '0' on Success; Error code otherwise.
2321 int dpni_set_queue(struct fsl_mc_io *mc_io,
2324 enum dpni_queue_type qtype,
2328 const struct dpni_queue *queue)
2330 struct mc_command cmd = { 0 };
2331 struct dpni_cmd_set_queue *cmd_params;
2333 /* prepare command */
2334 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
2337 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
2338 cmd_params->qtype = qtype;
2339 cmd_params->tc = (uint8_t)(param & 0xff);
2340 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2341 cmd_params->index = index;
2342 cmd_params->options = options;
2343 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
2344 cmd_params->dest_prio = queue->destination.priority;
2345 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
2346 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
2347 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
2348 queue->destination.hold_active);
2349 cmd_params->flc = cpu_to_le64(queue->flc.value);
2350 cmd_params->user_context = cpu_to_le64(queue->user_context);
2351 cmd_params->cgid = queue->cgid;
2353 /* send command to mc */
2354 return mc_send_command(mc_io, &cmd);
2358 * dpni_get_queue() - Get queue parameters
2359 * @mc_io: Pointer to MC portal's I/O object
2360 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2361 * @token: Token of DPNI object
2362 * @qtype: Type of queue - all queue types are supported
2363 * @param: Traffic class and channel ID.
2364 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2365 * ignored for the rest
2366 * LSB - traffic class
2367 * Use macro DPNI_BUILD_PARAM() to build correct value.
2368 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2369 * traffic class directly.
2370 * @index: Selects the specific queue out of the set allocated for the
2371 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2372 * @queue: Queue configuration structure
2373 * @qid: Queue identification
2375 * Return: '0' on Success; Error code otherwise.
2377 int dpni_get_queue(struct fsl_mc_io *mc_io,
2380 enum dpni_queue_type qtype,
2383 struct dpni_queue *queue,
2384 struct dpni_queue_id *qid)
2386 struct mc_command cmd = { 0 };
2387 struct dpni_cmd_get_queue *cmd_params;
2388 struct dpni_rsp_get_queue *rsp_params;
2391 /* prepare command */
2392 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
2395 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
2396 cmd_params->qtype = qtype;
2397 cmd_params->tc = (uint8_t)(param & 0xff);
2398 cmd_params->index = index;
2399 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2401 /* send command to mc */
2402 err = mc_send_command(mc_io, &cmd);
2406 /* retrieve response parameters */
2407 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2408 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2409 queue->destination.priority = rsp_params->dest_prio;
2410 queue->destination.type = dpni_get_field(rsp_params->flags,
2412 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2414 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2416 queue->flc.value = le64_to_cpu(rsp_params->flc);
2417 queue->user_context = le64_to_cpu(rsp_params->user_context);
2418 qid->fqid = le32_to_cpu(rsp_params->fqid);
2419 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2420 if (dpni_get_field(rsp_params->flags, CGID_VALID))
2421 queue->cgid = rsp_params->cgid;
2429 * dpni_get_statistics() - Get DPNI statistics
2430 * @mc_io: Pointer to MC portal's I/O object
2431 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2432 * @token: Token of DPNI object
2433 * @page: Selects the statistics page to retrieve, see
2434 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
2435 * @param: Custom parameter for some pages used to select
2436 * a certain statistic source, for example the TC.
2437 * - page_0: not used
2438 * - page_1: not used
2439 * - page_2: not used
2440 * - page_3: high_byte - channel_id, low_byte - traffic class
2441 * - page_4: high_byte - queue_index have meaning only if dpni is
2442 * created using option DPNI_OPT_CUSTOM_CG, low_byte - traffic class
2443 * - page_5: not used
2444 * - page_6: not used
2445 * @stat: Structure containing the statistics
2447 * Return: '0' on Success; Error code otherwise.
2449 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2454 union dpni_statistics *stat)
2456 struct mc_command cmd = { 0 };
2457 struct dpni_cmd_get_statistics *cmd_params;
2458 struct dpni_rsp_get_statistics *rsp_params;
2461 /* prepare command */
2462 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2465 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2466 cmd_params->page_number = page;
2467 cmd_params->param = param;
2469 /* send command to mc */
2470 err = mc_send_command(mc_io, &cmd);
2474 /* retrieve response parameters */
2475 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2476 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2477 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2483 * dpni_reset_statistics() - Clears DPNI statistics
2484 * @mc_io: Pointer to MC portal's I/O object
2485 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2486 * @token: Token of DPNI object
2488 * Return: '0' on Success; Error code otherwise.
2490 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2494 struct mc_command cmd = { 0 };
2496 /* prepare command */
2497 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2501 /* send command to mc*/
2502 return mc_send_command(mc_io, &cmd);
2506 * dpni_set_taildrop() - Set taildrop per congestion group
2508 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2509 * congestion notification or early drop (WRED) configuration previously applied
2512 * @mc_io: Pointer to MC portal's I/O object
2513 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2514 * @token: Token of DPNI object
2515 * @cg_point: Congestion group identifier DPNI_CP_QUEUE is only supported in
2516 * combination with DPNI_QUEUE_RX.
2517 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2518 * @tc: Traffic class to apply this taildrop to
2519 * @index/cgid: Index of the queue if the DPNI supports multiple queues for
2520 * traffic distribution.
2521 * If CONGESTION_POINT is DPNI_CP_CONGESTION_GROUP then it
2522 * represent the cgid of the congestion point
2523 * @taildrop: Taildrop structure
2525 * Return: '0' on Success; Error code otherwise.
2527 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2530 enum dpni_congestion_point cg_point,
2531 enum dpni_queue_type qtype,
2534 struct dpni_taildrop *taildrop)
2536 struct mc_command cmd = { 0 };
2537 struct dpni_cmd_set_taildrop *cmd_params;
2539 /* prepare command */
2540 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2543 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2544 cmd_params->congestion_point = cg_point;
2545 cmd_params->qtype = qtype;
2546 cmd_params->tc = (uint8_t)(param & 0xff);
2547 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2548 cmd_params->index = index;
2549 cmd_params->units = taildrop->units;
2550 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2551 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2552 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2553 dpni_set_field(cmd_params->oal_hi,
2555 taildrop->oal >> DPNI_OAL_LO_SIZE);
2557 /* send command to mc */
2558 return mc_send_command(mc_io, &cmd);
2562 * dpni_get_taildrop() - Get taildrop information
2563 * @mc_io: Pointer to MC portal's I/O object
2564 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2565 * @token: Token of DPNI object
2566 * @cg_point: Congestion point
2567 * @q_type: Queue type on which the taildrop is configured.
2568 * Only Rx queues are supported for now
2569 * @tc: Traffic class to apply this taildrop to
2570 * @q_index: Index of the queue if the DPNI supports multiple queues for
2571 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2572 * @taildrop: Taildrop structure
2574 * Return: '0' on Success; Error code otherwise.
2576 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2579 enum dpni_congestion_point cg_point,
2580 enum dpni_queue_type qtype,
2583 struct dpni_taildrop *taildrop)
2585 struct mc_command cmd = { 0 };
2586 struct dpni_cmd_get_taildrop *cmd_params;
2587 struct dpni_rsp_get_taildrop *rsp_params;
2588 uint8_t oal_lo, oal_hi;
2591 /* prepare command */
2592 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2595 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2596 cmd_params->congestion_point = cg_point;
2597 cmd_params->qtype = qtype;
2598 cmd_params->tc = tc;
2599 cmd_params->index = index;
2601 /* send command to mc */
2602 err = mc_send_command(mc_io, &cmd);
2606 /* retrieve response parameters */
2607 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2608 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2609 taildrop->units = rsp_params->units;
2610 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2611 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2612 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2613 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2615 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2616 if (taildrop->oal >= 0x0800)
2617 taildrop->oal |= 0xF000;
2623 * dpni_set_opr() - Set Order Restoration configuration.
2624 * @mc_io: Pointer to MC portal's I/O object
2625 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2626 * @token: Token of DPNI object
2627 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2628 * @index: Selects the specific queue out of the set allocated
2629 * for the same TC. Value must be in range 0 to
2631 * @options: Configuration mode options
2632 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2633 * @cfg: Configuration options for the OPR
2635 * Return: '0' on Success; Error code otherwise.
2637 int dpni_set_opr(struct fsl_mc_io *mc_io,
2643 struct opr_cfg *cfg,
2646 struct dpni_cmd_set_opr *cmd_params;
2647 struct mc_command cmd = { 0 };
2649 /* prepare command */
2650 cmd.header = mc_encode_cmd_header(
2654 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2655 cmd_params->tc_id = tc;
2656 cmd_params->index = index;
2657 cmd_params->options = options;
2658 cmd_params->opr_id = opr_id;
2659 cmd_params->oloe = cfg->oloe;
2660 cmd_params->oeane = cfg->oeane;
2661 cmd_params->olws = cfg->olws;
2662 cmd_params->oa = cfg->oa;
2663 cmd_params->oprrws = cfg->oprrws;
2665 /* send command to mc*/
2666 return mc_send_command(mc_io, &cmd);
2670 * dpni_get_opr() - Retrieve Order Restoration config and query.
2671 * @mc_io: Pointer to MC portal's I/O object
2672 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2673 * @token: Token of DPNI object
2674 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2675 * @index: Selects the specific queue out of the set allocated
2676 * for the same TC. Value must be in range 0 to
2678 * @cfg: Returned OPR configuration
2679 * @qry: Returned OPR query
2681 * Return: '0' on Success; Error code otherwise.
2683 int dpni_get_opr(struct fsl_mc_io *mc_io,
2688 struct opr_cfg *cfg,
2689 struct opr_qry *qry,
2693 struct dpni_rsp_get_opr *rsp_params;
2694 struct dpni_cmd_get_opr *cmd_params;
2695 struct mc_command cmd = { 0 };
2698 /* prepare command */
2699 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2702 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2703 cmd_params->index = index;
2704 cmd_params->tc_id = tc;
2705 cmd_params->flags = flags;
2706 cmd_params->opr_id = opr_id;
2708 /* send command to mc*/
2709 err = mc_send_command(mc_io, &cmd);
2713 /* retrieve response parameters */
2714 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2715 cfg->oloe = rsp_params->oloe;
2716 cfg->oeane = rsp_params->oeane;
2717 cfg->olws = rsp_params->olws;
2718 cfg->oa = rsp_params->oa;
2719 cfg->oprrws = rsp_params->oprrws;
2720 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2721 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2722 qry->nesn = le16_to_cpu(rsp_params->nesn);
2723 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2724 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2725 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2726 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2727 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2728 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2729 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2730 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2731 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2737 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2738 * @mc_io: Pointer to MC portal's I/O object
2739 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2740 * @token: Token of DPNI object
2741 * @cfg: Distribution configuration
2742 * If the FS is already enabled with a previous call the classification
2743 * key will be changed but all the table rules are kept. If the
2744 * existing rules do not match the key the results will not be
2745 * predictable. It is the user responsibility to keep keyintegrity.
2746 * If cfg.enable is set to 1 the command will create a flow steering table
2747 * and will classify packets according to this table. The packets
2748 * that miss all the table rules will be classified according to
2749 * settings made in dpni_set_rx_hash_dist()
2750 * If cfg.enable is set to 0 the command will clear flow steering table. The
2751 * packets will be classified according to settings made in
2752 * dpni_set_rx_hash_dist()
2754 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2755 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2757 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2758 struct mc_command cmd = { 0 };
2760 /* prepare command */
2761 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2764 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2765 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2766 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2767 cmd_params->tc = cfg->tc;
2768 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2769 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2771 /* send command to mc*/
2772 return mc_send_command(mc_io, &cmd);
2776 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2777 * @mc_io: Pointer to MC portal's I/O object
2778 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2779 * @token: Token of DPNI object
2780 * @cfg: Distribution configuration
2781 * If cfg.enable is set to 1 the packets will be classified using a hash
2782 * function based on the key received in cfg.key_cfg_iova parameter.
2783 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2784 * dpni_set_rx_dist_default_queue() call
2786 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2787 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2789 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2790 struct mc_command cmd = { 0 };
2792 /* prepare command */
2793 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2796 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2797 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2798 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2799 cmd_params->tc_id = cfg->tc;
2800 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2802 /* send command to mc*/
2803 return mc_send_command(mc_io, &cmd);
2807 * dpni_add_custom_tpid() - Configures a distinct Ethertype value (or TPID
2808 * value) to indicate VLAN tag in adition to the common TPID values
2809 * 0x81000 and 0x88A8
2810 * @mc_io: Pointer to MC portal's I/O object
2811 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2812 * @token: Token of DPNI object
2813 * @tpid: New value for TPID
2815 * Only two custom values are accepted. If the function is called for the third
2816 * time it will return error.
2817 * To replace an existing value use dpni_remove_custom_tpid() to remove a
2818 * previous TPID and after that use again the function.
2820 * Return: '0' on Success; Error code otherwise.
2822 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2823 uint16_t token, uint16_t tpid)
2825 struct dpni_cmd_add_custom_tpid *cmd_params;
2826 struct mc_command cmd = { 0 };
2828 /* prepare command */
2829 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
2832 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
2833 cmd_params->tpid = cpu_to_le16(tpid);
2835 /* send command to mc*/
2836 return mc_send_command(mc_io, &cmd);
2840 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
2841 * previously with dpni_add_custom_tpid()
2842 * @mc_io: Pointer to MC portal's I/O object
2843 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2844 * @token: Token of DPNI object
2845 * @tpid: New value for TPID
2847 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
2850 * Return: '0' on Success; Error code otherwise.
2852 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2853 uint16_t token, uint16_t tpid)
2855 struct dpni_cmd_remove_custom_tpid *cmd_params;
2856 struct mc_command cmd = { 0 };
2858 /* prepare command */
2859 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
2862 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
2863 cmd_params->tpid = cpu_to_le16(tpid);
2865 /* send command to mc*/
2866 return mc_send_command(mc_io, &cmd);
2870 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured to
2871 * detect 802.1q frames
2872 * @mc_io: Pointer to MC portal's I/O object
2873 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2874 * @token: Token of DPNI object
2875 * @tpid: TPID values. Only nonzero members of the structure are valid.
2877 * Return: '0' on Success; Error code otherwise.
2879 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2880 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
2882 struct dpni_rsp_get_custom_tpid *rsp_params;
2883 struct mc_command cmd = { 0 };
2886 /* prepare command */
2887 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
2891 /* send command to mc*/
2892 err = mc_send_command(mc_io, &cmd);
2896 /* read command response */
2897 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
2898 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
2899 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
2904 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
2907 struct dpni_load_ss_cfg *cfg)
2909 struct dpni_load_sw_sequence *cmd_params;
2910 struct mc_command cmd = { 0 };
2912 /* prepare command */
2913 cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE,
2916 cmd_params = (struct dpni_load_sw_sequence *)cmd.params;
2917 cmd_params->dest = cfg->dest;
2918 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2919 cmd_params->ss_size = cpu_to_le16(cfg->ss_size);
2920 cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova);
2922 /* send command to mc*/
2923 return mc_send_command(mc_io, &cmd);
2926 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
2929 struct dpni_enable_ss_cfg *cfg)
2931 struct dpni_enable_sw_sequence *cmd_params;
2932 struct mc_command cmd = { 0 };
2934 /* prepare command */
2935 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE,
2938 cmd_params = (struct dpni_enable_sw_sequence *)cmd.params;
2939 cmd_params->dest = cfg->dest;
2940 cmd_params->set_start = cfg->set_start;
2941 cmd_params->hxs = cpu_to_le16(cfg->hxs);
2942 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2943 cmd_params->param_offset = cfg->param_offset;
2944 cmd_params->param_size = cfg->param_size;
2945 cmd_params->param_iova = cpu_to_le64(cfg->param_iova);
2947 /* send command to mc*/
2948 return mc_send_command(mc_io, &cmd);
2952 * dpni_get_sw_sequence_layout() - Get the soft sequence layout
2953 * @mc_io: Pointer to MC portal's I/O object
2954 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2955 * @token: Token of DPNI object
2956 * @src: Source of the layout (WRIOP Rx or Tx)
2957 * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory
2959 * warning: After calling this function, call dpni_extract_sw_sequence_layout()
2960 * to get the layout.
2962 * Return: '0' on Success; error code otherwise.
2964 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
2967 enum dpni_soft_sequence_dest src,
2968 uint64_t ss_layout_iova)
2970 struct dpni_get_sw_sequence_layout *cmd_params;
2971 struct mc_command cmd = { 0 };
2973 /* prepare command */
2974 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT,
2978 cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params;
2979 cmd_params->src = src;
2980 cmd_params->layout_iova = cpu_to_le64(ss_layout_iova);
2982 /* send command to mc*/
2983 return mc_send_command(mc_io, &cmd);
2987 * dpni_extract_sw_sequence_layout() - extract the software sequence layout
2988 * @layout: software sequence layout
2989 * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it
2992 * This function has to be called after dpni_get_sw_sequence_layout
2995 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
2996 const uint8_t *sw_sequence_layout_buf)
2998 const struct dpni_sw_sequence_layout_entry *ext_params;
3000 uint16_t ss_size, ss_offset;
3002 ext_params = (const struct dpni_sw_sequence_layout_entry *)
3003 sw_sequence_layout_buf;
3005 for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) {
3006 ss_offset = le16_to_cpu(ext_params[i].ss_offset);
3007 ss_size = le16_to_cpu(ext_params[i].ss_size);
3009 if (ss_offset == 0 && ss_size == 0) {
3014 layout->ss[i].ss_offset = ss_offset;
3015 layout->ss[i].ss_size = ss_size;
3016 layout->ss[i].param_offset = ext_params[i].param_offset;
3017 layout->ss[i].param_size = ext_params[i].param_size;