1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2022 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->num_opr = le16_to_cpu(rsp_params->num_opr);
600 attr->qos_key_size = rsp_params->qos_key_size;
601 attr->fs_key_size = rsp_params->fs_key_size;
602 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
603 attr->num_cgs = rsp_params->num_cgs;
609 * dpni_set_errors_behavior() - Set errors behavior
610 * @mc_io: Pointer to MC portal's I/O object
611 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
612 * @token: Token of DPNI object
613 * @cfg: Errors configuration
615 * This function may be called numerous times with different
618 * Return: '0' on Success; Error code otherwise.
620 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
623 struct dpni_error_cfg *cfg)
625 struct mc_command cmd = { 0 };
626 struct dpni_cmd_set_errors_behavior *cmd_params;
628 /* prepare command */
629 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
632 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
633 cmd_params->errors = cpu_to_le32(cfg->errors);
634 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
635 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
637 /* send command to mc*/
638 return mc_send_command(mc_io, &cmd);
642 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
643 * @mc_io: Pointer to MC portal's I/O object
644 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
645 * @token: Token of DPNI object
646 * @qtype: Type of queue to retrieve configuration for
647 * @layout: Returns buffer layout attributes
649 * Return: '0' on Success; Error code otherwise.
651 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
654 enum dpni_queue_type qtype,
655 struct dpni_buffer_layout *layout)
657 struct mc_command cmd = { 0 };
658 struct dpni_cmd_get_buffer_layout *cmd_params;
659 struct dpni_rsp_get_buffer_layout *rsp_params;
662 /* prepare command */
663 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
666 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
667 cmd_params->qtype = qtype;
669 /* send command to mc*/
670 err = mc_send_command(mc_io, &cmd);
674 /* retrieve response parameters */
675 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
676 layout->pass_timestamp =
677 (int)dpni_get_field(rsp_params->flags, PASS_TS);
678 layout->pass_parser_result =
679 (int)dpni_get_field(rsp_params->flags, PASS_PR);
680 layout->pass_frame_status =
681 (int)dpni_get_field(rsp_params->flags, PASS_FS);
682 layout->pass_sw_opaque =
683 (int)dpni_get_field(rsp_params->flags, PASS_SWO);
684 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
685 layout->data_align = le16_to_cpu(rsp_params->data_align);
686 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
687 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
693 * dpni_set_buffer_layout() - Set buffer layout configuration.
694 * @mc_io: Pointer to MC portal's I/O object
695 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
696 * @token: Token of DPNI object
697 * @qtype: Type of queue this configuration applies to
698 * @layout: Buffer layout configuration
700 * Return: '0' on Success; Error code otherwise.
702 * @warning Allowed only when DPNI is disabled
704 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
707 enum dpni_queue_type qtype,
708 const struct dpni_buffer_layout *layout)
710 struct mc_command cmd = { 0 };
711 struct dpni_cmd_set_buffer_layout *cmd_params;
713 /* prepare command */
714 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
717 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
718 cmd_params->qtype = qtype;
719 cmd_params->options = cpu_to_le16((uint16_t)layout->options);
720 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
721 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
722 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
723 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
724 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
725 cmd_params->data_align = cpu_to_le16(layout->data_align);
726 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
727 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
729 /* send command to mc*/
730 return mc_send_command(mc_io, &cmd);
734 * dpni_set_offload() - Set DPNI offload configuration.
735 * @mc_io: Pointer to MC portal's I/O object
736 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
737 * @token: Token of DPNI object
738 * @type: Type of DPNI offload
739 * @config: Offload configuration.
740 * For checksum offloads, non-zero value enables the offload
742 * Return: '0' on Success; Error code otherwise.
744 * @warning Allowed only when DPNI is disabled
747 int dpni_set_offload(struct fsl_mc_io *mc_io,
750 enum dpni_offload type,
753 struct mc_command cmd = { 0 };
754 struct dpni_cmd_set_offload *cmd_params;
756 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
759 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
760 cmd_params->dpni_offload = type;
761 cmd_params->config = cpu_to_le32(config);
763 return mc_send_command(mc_io, &cmd);
767 * dpni_get_offload() - Get DPNI offload configuration.
768 * @mc_io: Pointer to MC portal's I/O object
769 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
770 * @token: Token of DPNI object
771 * @type: Type of DPNI offload
772 * @config: Offload configuration.
773 * For checksum offloads, a value of 1 indicates that the
774 * offload is enabled.
776 * Return: '0' on Success; Error code otherwise.
778 * @warning Allowed only when DPNI is disabled
780 int dpni_get_offload(struct fsl_mc_io *mc_io,
783 enum dpni_offload type,
786 struct mc_command cmd = { 0 };
787 struct dpni_cmd_get_offload *cmd_params;
788 struct dpni_rsp_get_offload *rsp_params;
791 /* prepare command */
792 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
795 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
796 cmd_params->dpni_offload = type;
798 /* send command to mc*/
799 err = mc_send_command(mc_io, &cmd);
803 /* retrieve response parameters */
804 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
805 *config = le32_to_cpu(rsp_params->config);
811 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
812 * for enqueue operations
813 * @mc_io: Pointer to MC portal's I/O object
814 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
815 * @token: Token of DPNI object
816 * @qtype: Type of queue to receive QDID for
817 * @qdid: Returned virtual QDID value that should be used as an argument
818 * in all enqueue operations
820 * Return: '0' on Success; Error code otherwise.
822 * If dpni object is created using multiple Tc channels this function will return
823 * qdid value for the first channel
825 int dpni_get_qdid(struct fsl_mc_io *mc_io,
828 enum dpni_queue_type qtype,
831 struct mc_command cmd = { 0 };
832 struct dpni_cmd_get_qdid *cmd_params;
833 struct dpni_rsp_get_qdid *rsp_params;
836 /* prepare command */
837 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
840 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
841 cmd_params->qtype = qtype;
843 /* send command to mc*/
844 err = mc_send_command(mc_io, &cmd);
848 /* retrieve response parameters */
849 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
850 *qdid = le16_to_cpu(rsp_params->qdid);
856 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
857 * @mc_io: Pointer to MC portal's I/O object
858 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
859 * @token: Token of DPNI object
860 * @data_offset: Tx data offset (from start of buffer)
862 * Return: '0' on Success; Error code otherwise.
864 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
867 uint16_t *data_offset)
869 struct mc_command cmd = { 0 };
870 struct dpni_rsp_get_tx_data_offset *rsp_params;
873 /* prepare command */
874 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
878 /* send command to mc*/
879 err = mc_send_command(mc_io, &cmd);
883 /* retrieve response parameters */
884 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
885 *data_offset = le16_to_cpu(rsp_params->data_offset);
891 * dpni_set_link_cfg() - set the link configuration.
892 * @mc_io: Pointer to MC portal's I/O object
893 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
894 * @token: Token of DPNI object
895 * @cfg: Link configuration
897 * Return: '0' on Success; Error code otherwise.
899 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
902 const struct dpni_link_cfg *cfg)
904 struct mc_command cmd = { 0 };
905 struct dpni_cmd_set_link_cfg *cmd_params;
907 /* prepare command */
908 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
911 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
912 cmd_params->rate = cpu_to_le32(cfg->rate);
913 cmd_params->options = cpu_to_le64(cfg->options);
914 cmd_params->advertising = cpu_to_le64(cfg->advertising);
916 /* send command to mc*/
917 return mc_send_command(mc_io, &cmd);
921 * dpni_get_link_cfg() - return the link configuration configured by
922 * dpni_set_link_cfg().
923 * @mc_io: Pointer to MC portal's I/O object
924 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
925 * @token: Token of DPNI object
926 * @cfg: Link configuration from dpni object
928 * Return: '0' on Success; Error code otherwise.
930 int dpni_get_link_cfg(struct fsl_mc_io *mc_io,
933 struct dpni_link_cfg *cfg)
935 struct mc_command cmd = { 0 };
936 struct dpni_cmd_set_link_cfg *rsp_params;
939 /* prepare command */
940 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG,
944 /* send command to mc*/
945 err = mc_send_command(mc_io, &cmd);
949 /* retrieve response parameters */
950 rsp_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
951 cfg->advertising = le64_to_cpu(rsp_params->advertising);
952 cfg->options = le64_to_cpu(rsp_params->options);
953 cfg->rate = le32_to_cpu(rsp_params->rate);
959 * dpni_get_link_state() - Return the link state (either up or down)
960 * @mc_io: Pointer to MC portal's I/O object
961 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
962 * @token: Token of DPNI object
963 * @state: Returned link state;
965 * Return: '0' on Success; Error code otherwise.
967 int dpni_get_link_state(struct fsl_mc_io *mc_io,
970 struct dpni_link_state *state)
972 struct mc_command cmd = { 0 };
973 struct dpni_rsp_get_link_state *rsp_params;
976 /* prepare command */
977 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
981 /* send command to mc*/
982 err = mc_send_command(mc_io, &cmd);
986 /* retrieve response parameters */
987 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
988 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
989 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
990 state->rate = le32_to_cpu(rsp_params->rate);
991 state->options = le64_to_cpu(rsp_params->options);
992 state->supported = le64_to_cpu(rsp_params->supported);
993 state->advertising = le64_to_cpu(rsp_params->advertising);
999 * dpni_set_tx_shaping() - Set the transmit shaping
1000 * @mc_io: Pointer to MC portal's I/O object
1001 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1002 * @token: Token of DPNI object
1003 * @tx_cr_shaper: TX committed rate shaping configuration
1004 * @tx_er_shaper: TX excess rate shaping configuration
1005 * @param: Special parameters
1006 * bit0: Committed and excess rates are coupled
1007 * bit1: 1 modify LNI shaper, 0 modify channel shaper
1008 * bit8-15: Tx channel to be shaped. Used only if bit1 is set to zero
1009 * bits16-26: OAL (Overhead accounting length 11bit value). Used only
1012 * Return: '0' on Success; Error code otherwise.
1014 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
1017 const struct dpni_tx_shaping_cfg *tx_cr_shaper,
1018 const struct dpni_tx_shaping_cfg *tx_er_shaper,
1021 struct dpni_cmd_set_tx_shaping *cmd_params;
1022 struct mc_command cmd = { 0 };
1023 int coupled, lni_shaper;
1027 /* prepare command */
1028 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
1031 cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
1032 cmd_params->tx_cr_max_burst_size =
1033 cpu_to_le16(tx_cr_shaper->max_burst_size);
1034 cmd_params->tx_er_max_burst_size =
1035 cpu_to_le16(tx_er_shaper->max_burst_size);
1036 cmd_params->tx_cr_rate_limit =
1037 cpu_to_le32(tx_cr_shaper->rate_limit);
1038 cmd_params->tx_er_rate_limit =
1039 cpu_to_le32(tx_er_shaper->rate_limit);
1041 coupled = !!(param & 0x01);
1042 dpni_set_field(cmd_params->options, COUPLED, coupled);
1044 lni_shaper = !!((param >> 1) & 0x01);
1045 dpni_set_field(cmd_params->options, LNI_SHAPER, lni_shaper);
1047 channel_id = (param >> 8) & 0xff;
1048 cmd_params->channel_id = channel_id;
1050 oal = (param >> 16) & 0x7FF;
1051 cmd_params->oal = cpu_to_le16(oal);
1053 /* send command to mc*/
1054 return mc_send_command(mc_io, &cmd);
1058 * dpni_set_max_frame_length() - Set the maximum received frame length.
1059 * @mc_io: Pointer to MC portal's I/O object
1060 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1061 * @token: Token of DPNI object
1062 * @max_frame_length: Maximum received frame length (in bytes);
1063 * frame is discarded if its length exceeds this value
1065 * Return: '0' on Success; Error code otherwise.
1067 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
1070 uint16_t max_frame_length)
1072 struct mc_command cmd = { 0 };
1073 struct dpni_cmd_set_max_frame_length *cmd_params;
1075 /* prepare command */
1076 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
1079 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
1080 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
1082 /* send command to mc*/
1083 return mc_send_command(mc_io, &cmd);
1087 * dpni_get_max_frame_length() - Get the maximum received frame length.
1088 * @mc_io: Pointer to MC portal's I/O object
1089 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1090 * @token: Token of DPNI object
1091 * @max_frame_length: Maximum received frame length (in bytes);
1092 * frame is discarded if its length exceeds this value
1094 * Return: '0' on Success; Error code otherwise.
1096 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
1099 uint16_t *max_frame_length)
1101 struct mc_command cmd = { 0 };
1102 struct dpni_rsp_get_max_frame_length *rsp_params;
1105 /* prepare command */
1106 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1110 /* send command to mc*/
1111 err = mc_send_command(mc_io, &cmd);
1115 /* retrieve response parameters */
1116 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1117 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1123 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1124 * @mc_io: Pointer to MC portal's I/O object
1125 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1126 * @token: Token of DPNI object
1127 * @en: Set to '1' to enable; '0' to disable
1129 * Return: '0' on Success; Error code otherwise.
1131 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1136 struct mc_command cmd = { 0 };
1137 struct dpni_cmd_set_multicast_promisc *cmd_params;
1139 /* prepare command */
1140 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1143 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1144 dpni_set_field(cmd_params->enable, ENABLE, en);
1146 /* send command to mc*/
1147 return mc_send_command(mc_io, &cmd);
1151 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1152 * @mc_io: Pointer to MC portal's I/O object
1153 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1154 * @token: Token of DPNI object
1155 * @en: Returns '1' if enabled; '0' otherwise
1157 * Return: '0' on Success; Error code otherwise.
1159 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1164 struct mc_command cmd = { 0 };
1165 struct dpni_rsp_get_multicast_promisc *rsp_params;
1168 /* prepare command */
1169 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1173 /* send command to mc*/
1174 err = mc_send_command(mc_io, &cmd);
1178 /* retrieve response parameters */
1179 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1180 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1186 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1187 * @mc_io: Pointer to MC portal's I/O object
1188 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1189 * @token: Token of DPNI object
1190 * @en: Set to '1' to enable; '0' to disable
1192 * Return: '0' on Success; Error code otherwise.
1194 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1199 struct mc_command cmd = { 0 };
1200 struct dpni_cmd_set_unicast_promisc *cmd_params;
1202 /* prepare command */
1203 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1206 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1207 dpni_set_field(cmd_params->enable, ENABLE, en);
1209 /* send command to mc*/
1210 return mc_send_command(mc_io, &cmd);
1214 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1215 * @mc_io: Pointer to MC portal's I/O object
1216 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1217 * @token: Token of DPNI object
1218 * @en: Returns '1' if enabled; '0' otherwise
1220 * Return: '0' on Success; Error code otherwise.
1222 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1227 struct mc_command cmd = { 0 };
1228 struct dpni_rsp_get_unicast_promisc *rsp_params;
1231 /* prepare command */
1232 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1236 /* send command to mc*/
1237 err = mc_send_command(mc_io, &cmd);
1241 /* retrieve response parameters */
1242 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1243 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1249 * dpni_set_primary_mac_addr() - Set the primary MAC address
1250 * @mc_io: Pointer to MC portal's I/O object
1251 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1252 * @token: Token of DPNI object
1253 * @mac_addr: MAC address to set as primary address
1255 * Return: '0' on Success; Error code otherwise.
1257 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1260 const uint8_t mac_addr[6])
1262 struct mc_command cmd = { 0 };
1263 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1266 /* prepare command */
1267 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1270 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1271 for (i = 0; i < 6; i++)
1272 cmd_params->mac_addr[i] = mac_addr[5 - i];
1274 /* send command to mc*/
1275 return mc_send_command(mc_io, &cmd);
1279 * dpni_get_primary_mac_addr() - Get the primary MAC address
1280 * @mc_io: Pointer to MC portal's I/O object
1281 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1282 * @token: Token of DPNI object
1283 * @mac_addr: Returned MAC address
1285 * Return: '0' on Success; Error code otherwise.
1287 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1290 uint8_t mac_addr[6])
1292 struct mc_command cmd = { 0 };
1293 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1296 /* prepare command */
1297 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1301 /* send command to mc*/
1302 err = mc_send_command(mc_io, &cmd);
1306 /* retrieve response parameters */
1307 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1308 for (i = 0; i < 6; i++)
1309 mac_addr[5 - i] = rsp_params->mac_addr[i];
1315 * dpni_add_mac_addr() - Add MAC address filter
1316 * @mc_io: Pointer to MC portal's I/O object
1317 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1318 * @token: Token of DPNI object
1319 * @mac_addr: MAC address to add
1320 * @flags : 0 - tc_id and flow_id will be ignored.
1321 * Pkt with this mac_id will be passed to the next
1322 * classification stages
1323 * DPNI_MAC_SET_QUEUE_ACTION
1324 * Pkt with this mac will be forward directly to
1325 * queue defined by the tc_id and flow_id
1326 * @tc_id : Traffic class selection (0-7)
1327 * @flow_id : Selects the specific queue out of the set allocated for the
1328 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1329 * Return: '0' on Success; Error code otherwise.
1331 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1334 const uint8_t mac_addr[6],
1339 struct mc_command cmd = { 0 };
1340 struct dpni_cmd_add_mac_addr *cmd_params;
1343 /* prepare command */
1344 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1347 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1348 cmd_params->flags = flags;
1349 cmd_params->tc_id = tc_id;
1350 cmd_params->fq_id = flow_id;
1352 for (i = 0; i < 6; i++)
1353 cmd_params->mac_addr[i] = mac_addr[5 - i];
1355 /* send command to mc*/
1356 return mc_send_command(mc_io, &cmd);
1360 * dpni_remove_mac_addr() - Remove MAC address filter
1361 * @mc_io: Pointer to MC portal's I/O object
1362 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1363 * @token: Token of DPNI object
1364 * @mac_addr: MAC address to remove
1366 * Return: '0' on Success; Error code otherwise.
1368 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1371 const uint8_t mac_addr[6])
1373 struct mc_command cmd = { 0 };
1374 struct dpni_cmd_remove_mac_addr *cmd_params;
1377 /* prepare command */
1378 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1381 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1382 for (i = 0; i < 6; i++)
1383 cmd_params->mac_addr[i] = mac_addr[5 - i];
1385 /* send command to mc*/
1386 return mc_send_command(mc_io, &cmd);
1390 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1391 * @mc_io: Pointer to MC portal's I/O object
1392 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1393 * @token: Token of DPNI object
1394 * @unicast: Set to '1' to clear unicast addresses
1395 * @multicast: Set to '1' to clear multicast addresses
1397 * The primary MAC address is not cleared by this operation.
1399 * Return: '0' on Success; Error code otherwise.
1401 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1407 struct mc_command cmd = { 0 };
1408 struct dpni_cmd_clear_mac_filters *cmd_params;
1410 /* prepare command */
1411 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1414 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1415 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1416 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1418 /* send command to mc*/
1419 return mc_send_command(mc_io, &cmd);
1423 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1424 * port the DPNI is attached to
1425 * @mc_io: Pointer to MC portal's I/O object
1426 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1427 * @token: Token of DPNI object
1428 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1430 * The primary MAC address is not cleared by this operation.
1432 * Return: '0' on Success; Error code otherwise.
1434 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1437 uint8_t mac_addr[6])
1439 struct mc_command cmd = { 0 };
1440 struct dpni_rsp_get_port_mac_addr *rsp_params;
1443 /* prepare command */
1444 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1448 /* send command to mc*/
1449 err = mc_send_command(mc_io, &cmd);
1453 /* retrieve response parameters */
1454 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1455 for (i = 0; i < 6; i++)
1456 mac_addr[5 - i] = rsp_params->mac_addr[i];
1462 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1463 * @mc_io: Pointer to MC portal's I/O object
1464 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1465 * @token: Token of DPNI object
1466 * @en: Set to '1' to enable; '0' to disable
1468 * Return: '0' on Success; Error code otherwise.
1470 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1475 struct dpni_cmd_enable_vlan_filter *cmd_params;
1476 struct mc_command cmd = { 0 };
1478 /* prepare command */
1479 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1482 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1483 dpni_set_field(cmd_params->en, ENABLE, en);
1485 /* send command to mc*/
1486 return mc_send_command(mc_io, &cmd);
1490 * dpni_add_vlan_id() - Add VLAN ID filter
1491 * @mc_io: Pointer to MC portal's I/O object
1492 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1493 * @token: Token of DPNI object
1494 * @vlan_id: VLAN ID to add
1495 * @flags: 0 - tc_id and flow_id will be ignored.
1496 * Pkt with this vlan_id will be passed to the next
1497 * classification stages
1498 * DPNI_VLAN_SET_QUEUE_ACTION
1499 * Pkt with this vlan_id will be forward directly to
1500 * queue defined by the tc_id and flow_id
1502 * @tc_id: Traffic class selection (0-7)
1503 * @flow_id: Selects the specific queue out of the set allocated for the
1504 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1506 * Return: '0' on Success; Error code otherwise.
1508 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1516 struct dpni_cmd_vlan_id *cmd_params;
1517 struct mc_command cmd = { 0 };
1519 /* prepare command */
1520 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1523 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1524 cmd_params->flags = flags;
1525 cmd_params->tc_id = tc_id;
1526 cmd_params->flow_id = flow_id;
1527 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1529 /* send command to mc*/
1530 return mc_send_command(mc_io, &cmd);
1534 * dpni_remove_vlan_id() - Remove VLAN ID filter
1535 * @mc_io: Pointer to MC portal's I/O object
1536 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1537 * @token: Token of DPNI object
1538 * @vlan_id: VLAN ID to remove
1540 * Return: '0' on Success; Error code otherwise.
1542 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1547 struct dpni_cmd_vlan_id *cmd_params;
1548 struct mc_command cmd = { 0 };
1550 /* prepare command */
1551 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1554 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1555 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1557 /* send command to mc*/
1558 return mc_send_command(mc_io, &cmd);
1562 * dpni_clear_vlan_filters() - Clear all VLAN filters
1563 * @mc_io: Pointer to MC portal's I/O object
1564 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1565 * @token: Token of DPNI object
1567 * Return: '0' on Success; Error code otherwise.
1569 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1573 struct mc_command cmd = { 0 };
1575 /* prepare command */
1576 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1580 /* send command to mc*/
1581 return mc_send_command(mc_io, &cmd);
1585 * dpni_set_tx_priorities() - Set transmission TC priority configuration
1586 * @mc_io: Pointer to MC portal's I/O object
1587 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1588 * @token: Token of DPNI object
1589 * @cfg: Transmission selection configuration
1591 * warning: Allowed only when DPNI is disabled
1593 * Return: '0' on Success; Error code otherwise.
1595 int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
1598 const struct dpni_tx_priorities_cfg *cfg)
1600 struct dpni_cmd_set_tx_priorities *cmd_params;
1601 struct mc_command cmd = { 0 };
1604 /* prepare command */
1605 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES,
1608 cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params;
1609 cmd_params->channel_idx = cfg->channel_idx;
1610 dpni_set_field(cmd_params->flags,
1612 cfg->separate_groups);
1613 cmd_params->prio_group_A = cfg->prio_group_A;
1614 cmd_params->prio_group_B = cfg->prio_group_B;
1616 for (i = 0; i + 1 < DPNI_MAX_TC; i = i + 2) {
1617 dpni_set_field(cmd_params->modes[i / 2],
1619 cfg->tc_sched[i].mode);
1620 dpni_set_field(cmd_params->modes[i / 2],
1622 cfg->tc_sched[i + 1].mode);
1625 for (i = 0; i < DPNI_MAX_TC; i++) {
1626 cmd_params->delta_bandwidth[i] =
1627 cpu_to_le16(cfg->tc_sched[i].delta_bandwidth);
1630 /* send command to mc*/
1631 return mc_send_command(mc_io, &cmd);
1635 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1636 * @mc_io: Pointer to MC portal's I/O object
1637 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1638 * @token: Token of DPNI object
1639 * @tc_id: Traffic class selection (0-7)
1640 * @cfg: Traffic class distribution configuration
1642 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1643 * first to prepare the key_cfg_iova parameter
1645 * Return: '0' on Success; error code otherwise.
1647 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1651 const struct dpni_rx_tc_dist_cfg *cfg)
1653 struct mc_command cmd = { 0 };
1654 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1656 /* prepare command */
1657 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1660 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1661 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1662 cmd_params->tc_id = tc_id;
1663 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1664 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1665 dpni_set_field(cmd_params->flags,
1668 dpni_set_field(cmd_params->flags,
1670 cfg->fs_cfg.miss_action);
1671 dpni_set_field(cmd_params->keep_hash_key,
1673 cfg->fs_cfg.keep_hash_key);
1674 dpni_set_field(cmd_params->keep_hash_key,
1676 cfg->fs_cfg.keep_entries);
1678 /* send command to mc*/
1679 return mc_send_command(mc_io, &cmd);
1683 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1684 * @mc_io: Pointer to MC portal's I/O object
1685 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1686 * @token: Token of DPNI object
1687 * @mode: Tx confirmation mode
1689 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1690 * selected at DPNI creation.
1691 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1692 * transmit confirmation (including the private confirmation queues), regardless
1693 * of previous settings; Note that in this case, Tx error frames are still
1694 * enqueued to the general transmit errors queue.
1695 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1696 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1697 * command will be ignored.
1699 * Return: '0' on Success; Error code otherwise.
1701 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1704 enum dpni_confirmation_mode mode)
1706 struct dpni_tx_confirmation_mode *cmd_params;
1707 struct mc_command cmd = { 0 };
1709 /* prepare command */
1710 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1713 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1714 cmd_params->confirmation_mode = mode;
1716 /* send command to mc*/
1717 return mc_send_command(mc_io, &cmd);
1721 * dpni_get_tx_confirmation_mode() - Get Tx confirmation mode
1722 * @mc_io: Pointer to MC portal's I/O object
1723 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1724 * @token: Token of DPNI object
1725 * @mode: Tx confirmation mode
1727 * Return: '0' on Success; Error code otherwise.
1729 int dpni_get_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1732 enum dpni_confirmation_mode *mode)
1734 struct dpni_tx_confirmation_mode *rsp_params;
1735 struct mc_command cmd = { 0 };
1738 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONFIRMATION_MODE,
1742 err = mc_send_command(mc_io, &cmd);
1746 rsp_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1747 *mode = rsp_params->confirmation_mode;
1753 * dpni_set_qos_table() - Set QoS mapping table
1754 * @mc_io: Pointer to MC portal's I/O object
1755 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1756 * @token: Token of DPNI object
1757 * @cfg: QoS table configuration
1759 * This function and all QoS-related functions require that
1760 *'max_tcs > 1' was set at DPNI creation.
1762 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1763 * prepare the key_cfg_iova parameter
1765 * Return: '0' on Success; Error code otherwise.
1767 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1770 const struct dpni_qos_tbl_cfg *cfg)
1772 struct dpni_cmd_set_qos_table *cmd_params;
1773 struct mc_command cmd = { 0 };
1775 /* prepare command */
1776 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1779 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1780 cmd_params->default_tc = cfg->default_tc;
1781 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1782 dpni_set_field(cmd_params->discard_on_miss,
1784 cfg->discard_on_miss);
1785 dpni_set_field(cmd_params->discard_on_miss,
1789 /* send command to mc*/
1790 return mc_send_command(mc_io, &cmd);
1794 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1795 * @mc_io: Pointer to MC portal's I/O object
1796 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1797 * @token: Token of DPNI object
1798 * @cfg: QoS rule to add
1799 * @tc_id: Traffic class selection (0-7)
1800 * @index: Location in the QoS table where to insert the entry.
1801 * Only relevant if MASKING is enabled for QoS classification on
1802 * this DPNI, it is ignored for exact match.
1804 * Return: '0' on Success; Error code otherwise.
1806 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1809 const struct dpni_rule_cfg *cfg,
1815 struct dpni_cmd_add_qos_entry *cmd_params;
1816 struct mc_command cmd = { 0 };
1818 /* prepare command */
1819 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1822 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1823 cmd_params->flags = flags;
1824 cmd_params->flow_id = flow_id;
1825 cmd_params->tc_id = tc_id;
1826 cmd_params->key_size = cfg->key_size;
1827 cmd_params->index = cpu_to_le16(index);
1828 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1829 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1831 /* send command to mc*/
1832 return mc_send_command(mc_io, &cmd);
1836 * dpni_remove_qos_entry() - Remove QoS mapping entry
1837 * @mc_io: Pointer to MC portal's I/O object
1838 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1839 * @token: Token of DPNI object
1840 * @cfg: QoS rule to remove
1842 * Return: '0' on Success; Error code otherwise.
1844 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1847 const struct dpni_rule_cfg *cfg)
1849 struct dpni_cmd_remove_qos_entry *cmd_params;
1850 struct mc_command cmd = { 0 };
1852 /* prepare command */
1853 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1856 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1857 cmd_params->key_size = cfg->key_size;
1858 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1859 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1861 /* send command to mc*/
1862 return mc_send_command(mc_io, &cmd);
1866 * dpni_clear_qos_table() - Clear all QoS mapping entries
1867 * @mc_io: Pointer to MC portal's I/O object
1868 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1869 * @token: Token of DPNI object
1871 * Following this function call, all frames are directed to
1872 * the default traffic class (0)
1874 * Return: '0' on Success; Error code otherwise.
1876 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1880 struct mc_command cmd = { 0 };
1882 /* prepare command */
1883 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1887 /* send command to mc*/
1888 return mc_send_command(mc_io, &cmd);
1892 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1893 * (to select a flow ID)
1894 * @mc_io: Pointer to MC portal's I/O object
1895 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1896 * @token: Token of DPNI object
1897 * @tc_id: Traffic class selection (0-7)
1898 * @index: Location in the QoS table where to insert the entry.
1899 * Only relevant if MASKING is enabled for QoS classification
1900 * on this DPNI, it is ignored for exact match.
1901 * @cfg: Flow steering rule to add
1902 * @action: Action to be taken as result of a classification hit
1904 * Return: '0' on Success; Error code otherwise.
1906 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1911 const struct dpni_rule_cfg *cfg,
1912 const struct dpni_fs_action_cfg *action)
1914 struct dpni_cmd_add_fs_entry *cmd_params;
1915 struct mc_command cmd = { 0 };
1917 /* prepare command */
1918 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1921 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1922 cmd_params->tc_id = tc_id;
1923 cmd_params->key_size = cfg->key_size;
1924 cmd_params->index = cpu_to_le16(index);
1925 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1926 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1927 cmd_params->options = cpu_to_le16(action->options);
1928 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1929 cmd_params->flc = cpu_to_le64(action->flc);
1930 cmd_params->redir_token = cpu_to_le16(action->redirect_obj_token);
1932 /* send command to mc*/
1933 return mc_send_command(mc_io, &cmd);
1937 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1939 * @mc_io: Pointer to MC portal's I/O object
1940 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1941 * @token: Token of DPNI object
1942 * @tc_id: Traffic class selection (0-7)
1943 * @cfg: Flow steering rule to remove
1945 * Return: '0' on Success; Error code otherwise.
1947 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1951 const struct dpni_rule_cfg *cfg)
1953 struct dpni_cmd_remove_fs_entry *cmd_params;
1954 struct mc_command cmd = { 0 };
1956 /* prepare command */
1957 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1960 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1961 cmd_params->tc_id = tc_id;
1962 cmd_params->key_size = cfg->key_size;
1963 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1964 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1966 /* send command to mc*/
1967 return mc_send_command(mc_io, &cmd);
1971 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1973 * @mc_io: Pointer to MC portal's I/O object
1974 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1975 * @token: Token of DPNI object
1976 * @tc_id: Traffic class selection (0-7)
1978 * Return: '0' on Success; Error code otherwise.
1980 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1985 struct dpni_cmd_clear_fs_entries *cmd_params;
1986 struct mc_command cmd = { 0 };
1988 /* prepare command */
1989 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1992 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1993 cmd_params->tc_id = tc_id;
1995 /* send command to mc*/
1996 return mc_send_command(mc_io, &cmd);
2000 * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
2001 * @mc_io: Pointer to MC portal's I/O object
2002 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2003 * @token: Token of DPNI object
2004 * @tc_id: Traffic class selection (0-7)
2005 * @cfg: Traffic class policing configuration
2007 * Return: '0' on Success; error code otherwise.
2009 int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
2013 const struct dpni_rx_tc_policing_cfg *cfg)
2015 struct dpni_cmd_set_rx_tc_policing *cmd_params;
2016 struct mc_command cmd = { 0 };
2018 /* prepare command */
2019 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING,
2022 cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params;
2023 dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color);
2024 dpni_set_field(cmd_params->mode_color, MODE, cfg->mode);
2025 dpni_set_field(cmd_params->units, UNITS, cfg->units);
2026 cmd_params->options = cpu_to_le32(cfg->options);
2027 cmd_params->cir = cpu_to_le32(cfg->cir);
2028 cmd_params->cbs = cpu_to_le32(cfg->cbs);
2029 cmd_params->eir = cpu_to_le32(cfg->eir);
2030 cmd_params->ebs = cpu_to_le32(cfg->ebs);
2031 cmd_params->tc_id = tc_id;
2033 /* send command to mc*/
2034 return mc_send_command(mc_io, &cmd);
2038 * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration
2039 * @mc_io: Pointer to MC portal's I/O object
2040 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2041 * @token: Token of DPNI object
2042 * @tc_id: Traffic class selection (0-7)
2043 * @cfg: Traffic class policing configuration
2045 * Return: '0' on Success; error code otherwise.
2047 int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io,
2051 struct dpni_rx_tc_policing_cfg *cfg)
2053 struct dpni_rsp_get_rx_tc_policing *rsp_params;
2054 struct dpni_cmd_get_rx_tc_policing *cmd_params;
2055 struct mc_command cmd = { 0 };
2058 /* prepare command */
2059 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_TC_POLICING,
2062 cmd_params = (struct dpni_cmd_get_rx_tc_policing *)cmd.params;
2063 cmd_params->tc_id = tc_id;
2066 /* send command to mc*/
2067 err = mc_send_command(mc_io, &cmd);
2071 rsp_params = (struct dpni_rsp_get_rx_tc_policing *)cmd.params;
2072 cfg->options = le32_to_cpu(rsp_params->options);
2073 cfg->cir = le32_to_cpu(rsp_params->cir);
2074 cfg->cbs = le32_to_cpu(rsp_params->cbs);
2075 cfg->eir = le32_to_cpu(rsp_params->eir);
2076 cfg->ebs = le32_to_cpu(rsp_params->ebs);
2077 cfg->units = dpni_get_field(rsp_params->units, UNITS);
2078 cfg->mode = dpni_get_field(rsp_params->mode_color, MODE);
2079 cfg->default_color = dpni_get_field(rsp_params->mode_color, COLOR);
2085 * dpni_prepare_early_drop() - prepare an early drop.
2086 * @cfg: Early-drop configuration
2087 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2089 * This function has to be called before dpni_set_rx_tc_early_drop or
2090 * dpni_set_tx_tc_early_drop
2093 void dpni_prepare_early_drop(const struct dpni_early_drop_cfg *cfg,
2094 uint8_t *early_drop_buf)
2096 struct dpni_early_drop *ext_params;
2098 ext_params = (struct dpni_early_drop *)early_drop_buf;
2100 dpni_set_field(ext_params->flags, DROP_ENABLE, cfg->enable);
2101 dpni_set_field(ext_params->flags, DROP_UNITS, cfg->units);
2102 ext_params->green_drop_probability = cfg->green.drop_probability;
2103 ext_params->green_max_threshold = cpu_to_le64(cfg->green.max_threshold);
2104 ext_params->green_min_threshold = cpu_to_le64(cfg->green.min_threshold);
2105 ext_params->yellow_drop_probability = cfg->yellow.drop_probability;
2106 ext_params->yellow_max_threshold =
2107 cpu_to_le64(cfg->yellow.max_threshold);
2108 ext_params->yellow_min_threshold =
2109 cpu_to_le64(cfg->yellow.min_threshold);
2110 ext_params->red_drop_probability = cfg->red.drop_probability;
2111 ext_params->red_max_threshold = cpu_to_le64(cfg->red.max_threshold);
2112 ext_params->red_min_threshold = cpu_to_le64(cfg->red.min_threshold);
2116 * dpni_extract_early_drop() - extract the early drop configuration.
2117 * @cfg: Early-drop configuration
2118 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2120 * This function has to be called after dpni_get_rx_tc_early_drop or
2121 * dpni_get_tx_tc_early_drop
2124 void dpni_extract_early_drop(struct dpni_early_drop_cfg *cfg,
2125 const uint8_t *early_drop_buf)
2127 const struct dpni_early_drop *ext_params;
2129 ext_params = (const struct dpni_early_drop *)early_drop_buf;
2131 cfg->enable = dpni_get_field(ext_params->flags, DROP_ENABLE);
2132 cfg->units = dpni_get_field(ext_params->flags, DROP_UNITS);
2133 cfg->green.drop_probability = ext_params->green_drop_probability;
2134 cfg->green.max_threshold = le64_to_cpu(ext_params->green_max_threshold);
2135 cfg->green.min_threshold = le64_to_cpu(ext_params->green_min_threshold);
2136 cfg->yellow.drop_probability = ext_params->yellow_drop_probability;
2137 cfg->yellow.max_threshold =
2138 le64_to_cpu(ext_params->yellow_max_threshold);
2139 cfg->yellow.min_threshold =
2140 le64_to_cpu(ext_params->yellow_min_threshold);
2141 cfg->red.drop_probability = ext_params->red_drop_probability;
2142 cfg->red.max_threshold = le64_to_cpu(ext_params->red_max_threshold);
2143 cfg->red.min_threshold = le64_to_cpu(ext_params->red_min_threshold);
2147 * dpni_set_early_drop() - Set traffic class early-drop configuration
2148 * @mc_io: Pointer to MC portal's I/O object
2149 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2150 * @token: Token of DPNI object
2151 * @qtype: Type of queue - only Rx and Tx types are supported
2152 * @param: Traffic class and channel ID.
2153 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2154 * ignored for the rest
2155 * LSB - traffic class
2156 * Use macro DPNI_BUILD_PARAM() to build correct value.
2157 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2158 * traffic class directly.
2159 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory filled
2160 * with the early-drop configuration by calling dpni_prepare_early_drop()
2162 * warning: Before calling this function, call dpni_prepare_early_drop() to
2163 * prepare the early_drop_iova parameter
2165 * Return: '0' on Success; error code otherwise.
2167 int dpni_set_early_drop(struct fsl_mc_io *mc_io,
2170 enum dpni_queue_type qtype,
2172 uint64_t early_drop_iova)
2174 struct dpni_cmd_early_drop *cmd_params;
2175 struct mc_command cmd = { 0 };
2177 /* prepare command */
2178 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_EARLY_DROP,
2181 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2182 cmd_params->qtype = qtype;
2183 cmd_params->tc = (uint8_t)(param & 0xff);
2184 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2185 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2187 /* send command to mc*/
2188 return mc_send_command(mc_io, &cmd);
2192 * dpni_get_early_drop() - Get Rx traffic class early-drop configuration
2193 * @mc_io: Pointer to MC portal's I/O object
2194 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2195 * @token: Token of DPNI object
2196 * @qtype: Type of queue - only Rx and Tx types are supported
2197 * @param: Traffic class and channel ID.
2198 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2199 * ignored for the rest
2200 * LSB - traffic class
2201 * Use macro DPNI_BUILD_PARAM() to build correct value.
2202 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2203 * traffic class directly.
2204 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory
2206 * warning: After calling this function, call dpni_extract_early_drop() to
2207 * get the early drop configuration
2209 * Return: '0' on Success; error code otherwise.
2211 int dpni_get_early_drop(struct fsl_mc_io *mc_io,
2214 enum dpni_queue_type qtype,
2216 uint64_t early_drop_iova)
2218 struct dpni_cmd_early_drop *cmd_params;
2219 struct mc_command cmd = { 0 };
2221 /* prepare command */
2222 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_EARLY_DROP,
2225 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2226 cmd_params->qtype = qtype;
2227 cmd_params->tc = (uint8_t)(param & 0xff);
2228 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2229 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2231 /* send command to mc*/
2232 return mc_send_command(mc_io, &cmd);
2236 * dpni_set_congestion_notification() - Set traffic class congestion
2237 * notification configuration
2238 * @mc_io: Pointer to MC portal's I/O object
2239 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2240 * @token: Token of DPNI object
2241 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2242 * @param: Traffic class and channel. Bits[0-7] contain traaffic class,
2243 * bite[8-15] contains channel id
2244 * @cfg: congestion notification configuration
2246 * Return: '0' on Success; error code otherwise.
2248 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
2251 enum dpni_queue_type qtype,
2253 const struct dpni_congestion_notification_cfg *cfg)
2255 struct dpni_cmd_set_congestion_notification *cmd_params;
2256 struct mc_command cmd = { 0 };
2258 /* prepare command */
2259 cmd.header = mc_encode_cmd_header(
2260 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
2263 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
2264 cmd_params->qtype = qtype;
2265 cmd_params->tc = (uint8_t)(param & 0xff);
2266 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2267 cmd_params->congestion_point = cfg->cg_point;
2268 cmd_params->cgid = (uint8_t)cfg->cgid;
2269 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
2270 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
2271 cmd_params->dest_priority = cfg->dest_cfg.priority;
2272 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
2273 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
2274 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
2275 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
2276 dpni_set_field(cmd_params->type_units,
2278 cfg->dest_cfg.dest_type);
2279 dpni_set_field(cmd_params->type_units,
2283 /* send command to mc*/
2284 return mc_send_command(mc_io, &cmd);
2288 * dpni_get_congestion_notification() - Get traffic class congestion
2289 * notification configuration
2290 * @mc_io: Pointer to MC portal's I/O object
2291 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2292 * @token: Token of DPNI object
2293 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2294 * @param: Traffic class and channel. Bits[0-7] contain traaffic class,
2295 * byte[8-15] contains channel id
2296 * @cfg: congestion notification configuration
2298 * Return: '0' on Success; error code otherwise.
2300 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
2303 enum dpni_queue_type qtype,
2305 struct dpni_congestion_notification_cfg *cfg)
2307 struct dpni_rsp_get_congestion_notification *rsp_params;
2308 struct dpni_cmd_get_congestion_notification *cmd_params;
2309 struct mc_command cmd = { 0 };
2312 /* prepare command */
2313 cmd.header = mc_encode_cmd_header(
2314 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
2317 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
2318 cmd_params->qtype = qtype;
2319 cmd_params->tc = (uint8_t)(param & 0xff);
2320 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2321 cmd_params->congestion_point = cfg->cg_point;
2322 cmd_params->cgid = cfg->cgid;
2324 /* send command to mc*/
2325 err = mc_send_command(mc_io, &cmd);
2329 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
2330 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
2331 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
2332 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
2333 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
2334 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
2335 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
2336 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
2337 cfg->dest_cfg.priority = rsp_params->dest_priority;
2338 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
2345 * dpni_get_api_version() - Get Data Path Network Interface API version
2346 * @mc_io: Pointer to MC portal's I/O object
2347 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2348 * @major_ver: Major version of data path network interface API
2349 * @minor_ver: Minor version of data path network interface API
2351 * Return: '0' on Success; Error code otherwise.
2353 int dpni_get_api_version(struct fsl_mc_io *mc_io,
2355 uint16_t *major_ver,
2356 uint16_t *minor_ver)
2358 struct dpni_rsp_get_api_version *rsp_params;
2359 struct mc_command cmd = { 0 };
2362 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
2366 err = mc_send_command(mc_io, &cmd);
2370 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
2371 *major_ver = le16_to_cpu(rsp_params->major);
2372 *minor_ver = le16_to_cpu(rsp_params->minor);
2378 * dpni_set_queue() - Set queue parameters
2379 * @mc_io: Pointer to MC portal's I/O object
2380 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2381 * @token: Token of DPNI object
2382 * @qtype: Type of queue - all queue types are supported, although
2383 * the command is ignored for Tx
2384 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2385 * @index: Selects the specific queue out of the set allocated for the
2386 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2387 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
2388 * configuration options are set on the queue
2389 * @queue: Queue structure
2391 * Return: '0' on Success; Error code otherwise.
2393 int dpni_set_queue(struct fsl_mc_io *mc_io,
2396 enum dpni_queue_type qtype,
2400 const struct dpni_queue *queue)
2402 struct mc_command cmd = { 0 };
2403 struct dpni_cmd_set_queue *cmd_params;
2405 /* prepare command */
2406 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
2409 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
2410 cmd_params->qtype = qtype;
2411 cmd_params->tc = (uint8_t)(param & 0xff);
2412 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2413 cmd_params->index = index;
2414 cmd_params->options = options;
2415 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
2416 cmd_params->dest_prio = queue->destination.priority;
2417 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
2418 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
2419 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
2420 queue->destination.hold_active);
2421 cmd_params->flc = cpu_to_le64(queue->flc.value);
2422 cmd_params->user_context = cpu_to_le64(queue->user_context);
2423 cmd_params->cgid = queue->cgid;
2425 /* send command to mc */
2426 return mc_send_command(mc_io, &cmd);
2430 * dpni_get_queue() - Get queue parameters
2431 * @mc_io: Pointer to MC portal's I/O object
2432 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2433 * @token: Token of DPNI object
2434 * @qtype: Type of queue - all queue types are supported
2435 * @param: Traffic class and channel ID.
2436 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2437 * ignored for the rest
2438 * LSB - traffic class
2439 * Use macro DPNI_BUILD_PARAM() to build correct value.
2440 * If dpni uses a single channel (uses only channel zero) the parameter can receive
2441 * traffic class directly.
2442 * @index: Selects the specific queue out of the set allocated for the
2443 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2444 * @queue: Queue configuration structure
2445 * @qid: Queue identification
2447 * Return: '0' on Success; Error code otherwise.
2449 int dpni_get_queue(struct fsl_mc_io *mc_io,
2452 enum dpni_queue_type qtype,
2455 struct dpni_queue *queue,
2456 struct dpni_queue_id *qid)
2458 struct mc_command cmd = { 0 };
2459 struct dpni_cmd_get_queue *cmd_params;
2460 struct dpni_rsp_get_queue *rsp_params;
2463 /* prepare command */
2464 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
2467 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
2468 cmd_params->qtype = qtype;
2469 cmd_params->tc = (uint8_t)(param & 0xff);
2470 cmd_params->index = index;
2471 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2473 /* send command to mc */
2474 err = mc_send_command(mc_io, &cmd);
2478 /* retrieve response parameters */
2479 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2480 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2481 queue->destination.priority = rsp_params->dest_prio;
2482 queue->destination.type = dpni_get_field(rsp_params->flags,
2484 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2486 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2488 queue->flc.value = le64_to_cpu(rsp_params->flc);
2489 queue->user_context = le64_to_cpu(rsp_params->user_context);
2490 qid->fqid = le32_to_cpu(rsp_params->fqid);
2491 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2492 if (dpni_get_field(rsp_params->flags, CGID_VALID))
2493 queue->cgid = rsp_params->cgid;
2501 * dpni_get_statistics() - Get DPNI statistics
2502 * @mc_io: Pointer to MC portal's I/O object
2503 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2504 * @token: Token of DPNI object
2505 * @page: Selects the statistics page to retrieve, see
2506 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
2507 * @param: Custom parameter for some pages used to select
2508 * a certain statistic source, for example the TC.
2509 * - page_0: not used
2510 * - page_1: not used
2511 * - page_2: not used
2512 * - page_3: high_byte - channel_id, low_byte - traffic class
2513 * - page_4: high_byte - queue_index have meaning only if dpni is
2514 * created using option DPNI_OPT_CUSTOM_CG, low_byte - traffic class
2515 * - page_5: not used
2516 * - page_6: not used
2517 * @stat: Structure containing the statistics
2519 * Return: '0' on Success; Error code otherwise.
2521 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2526 union dpni_statistics *stat)
2528 struct mc_command cmd = { 0 };
2529 struct dpni_cmd_get_statistics *cmd_params;
2530 struct dpni_rsp_get_statistics *rsp_params;
2533 /* prepare command */
2534 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2537 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2538 cmd_params->page_number = page;
2539 cmd_params->param = param;
2541 /* send command to mc */
2542 err = mc_send_command(mc_io, &cmd);
2546 /* retrieve response parameters */
2547 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2548 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2549 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2555 * dpni_reset_statistics() - Clears DPNI statistics
2556 * @mc_io: Pointer to MC portal's I/O object
2557 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2558 * @token: Token of DPNI object
2560 * Return: '0' on Success; Error code otherwise.
2562 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2566 struct mc_command cmd = { 0 };
2568 /* prepare command */
2569 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2573 /* send command to mc*/
2574 return mc_send_command(mc_io, &cmd);
2578 * dpni_set_taildrop() - Set taildrop per congestion group
2580 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2581 * congestion notification or early drop (WRED) configuration previously applied
2584 * @mc_io: Pointer to MC portal's I/O object
2585 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2586 * @token: Token of DPNI object
2587 * @cg_point: Congestion group identifier DPNI_CP_QUEUE is only supported in
2588 * combination with DPNI_QUEUE_RX.
2589 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2590 * @tc: Traffic class to apply this taildrop to
2591 * @index/cgid: Index of the queue if the DPNI supports multiple queues for
2592 * traffic distribution.
2593 * If CONGESTION_POINT is DPNI_CP_CONGESTION_GROUP then it
2594 * represent the cgid of the congestion point
2595 * @taildrop: Taildrop structure
2597 * Return: '0' on Success; Error code otherwise.
2599 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2602 enum dpni_congestion_point cg_point,
2603 enum dpni_queue_type qtype,
2606 struct dpni_taildrop *taildrop)
2608 struct mc_command cmd = { 0 };
2609 struct dpni_cmd_set_taildrop *cmd_params;
2611 /* prepare command */
2612 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2615 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2616 cmd_params->congestion_point = cg_point;
2617 cmd_params->qtype = qtype;
2618 cmd_params->tc = (uint8_t)(param & 0xff);
2619 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2620 cmd_params->index = index;
2621 cmd_params->units = taildrop->units;
2622 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2623 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2624 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2625 dpni_set_field(cmd_params->oal_hi,
2627 taildrop->oal >> DPNI_OAL_LO_SIZE);
2629 /* send command to mc */
2630 return mc_send_command(mc_io, &cmd);
2634 * dpni_get_taildrop() - Get taildrop information
2635 * @mc_io: Pointer to MC portal's I/O object
2636 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2637 * @token: Token of DPNI object
2638 * @cg_point: Congestion point
2639 * @q_type: Queue type on which the taildrop is configured.
2640 * Only Rx queues are supported for now
2641 * @tc: Traffic class to apply this taildrop to
2642 * @q_index: Index of the queue if the DPNI supports multiple queues for
2643 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2644 * @taildrop: Taildrop structure
2646 * Return: '0' on Success; Error code otherwise.
2648 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2651 enum dpni_congestion_point cg_point,
2652 enum dpni_queue_type qtype,
2655 struct dpni_taildrop *taildrop)
2657 struct mc_command cmd = { 0 };
2658 struct dpni_cmd_get_taildrop *cmd_params;
2659 struct dpni_rsp_get_taildrop *rsp_params;
2660 uint8_t oal_lo, oal_hi;
2663 /* prepare command */
2664 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2667 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2668 cmd_params->congestion_point = cg_point;
2669 cmd_params->qtype = qtype;
2670 cmd_params->tc = tc;
2671 cmd_params->index = index;
2673 /* send command to mc */
2674 err = mc_send_command(mc_io, &cmd);
2678 /* retrieve response parameters */
2679 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2680 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2681 taildrop->units = rsp_params->units;
2682 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2683 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2684 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2685 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2687 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2688 if (taildrop->oal >= 0x0800)
2689 taildrop->oal |= 0xF000;
2695 * dpni_set_opr() - Set Order Restoration configuration.
2696 * @mc_io: Pointer to MC portal's I/O object
2697 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2698 * @token: Token of DPNI object
2699 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2700 * @index: Selects the specific queue out of the set allocated
2701 * for the same TC. Value must be in range 0 to
2703 * @options: Configuration mode options
2704 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2705 * @cfg: Configuration options for the OPR
2707 * Return: '0' on Success; Error code otherwise.
2709 int dpni_set_opr(struct fsl_mc_io *mc_io,
2715 struct opr_cfg *cfg,
2718 struct dpni_cmd_set_opr *cmd_params;
2719 struct mc_command cmd = { 0 };
2721 /* prepare command */
2722 cmd.header = mc_encode_cmd_header(
2726 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2727 cmd_params->tc_id = tc;
2728 cmd_params->index = index;
2729 cmd_params->options = options;
2730 cmd_params->opr_id = opr_id;
2731 cmd_params->oloe = cfg->oloe;
2732 cmd_params->oeane = cfg->oeane;
2733 cmd_params->olws = cfg->olws;
2734 cmd_params->oa = cfg->oa;
2735 cmd_params->oprrws = cfg->oprrws;
2737 /* send command to mc*/
2738 return mc_send_command(mc_io, &cmd);
2742 * dpni_get_opr() - Retrieve Order Restoration config and query.
2743 * @mc_io: Pointer to MC portal's I/O object
2744 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2745 * @token: Token of DPNI object
2746 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2747 * @index: Selects the specific queue out of the set allocated
2748 * for the same TC. Value must be in range 0 to
2750 * @cfg: Returned OPR configuration
2751 * @qry: Returned OPR query
2753 * Return: '0' on Success; Error code otherwise.
2755 int dpni_get_opr(struct fsl_mc_io *mc_io,
2760 struct opr_cfg *cfg,
2761 struct opr_qry *qry,
2765 struct dpni_rsp_get_opr *rsp_params;
2766 struct dpni_cmd_get_opr *cmd_params;
2767 struct mc_command cmd = { 0 };
2770 /* prepare command */
2771 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2774 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2775 cmd_params->index = index;
2776 cmd_params->tc_id = tc;
2777 cmd_params->flags = flags;
2778 cmd_params->opr_id = opr_id;
2780 /* send command to mc*/
2781 err = mc_send_command(mc_io, &cmd);
2785 /* retrieve response parameters */
2786 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2787 cfg->oloe = rsp_params->oloe;
2788 cfg->oeane = rsp_params->oeane;
2789 cfg->olws = rsp_params->olws;
2790 cfg->oa = rsp_params->oa;
2791 cfg->oprrws = rsp_params->oprrws;
2792 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2793 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2794 qry->nesn = le16_to_cpu(rsp_params->nesn);
2795 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2796 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2797 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2798 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2799 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2800 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2801 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2802 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2803 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2808 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
2811 struct dpni_load_ss_cfg *cfg)
2813 struct dpni_load_sw_sequence *cmd_params;
2814 struct mc_command cmd = { 0 };
2816 /* prepare command */
2817 cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE,
2820 cmd_params = (struct dpni_load_sw_sequence *)cmd.params;
2821 cmd_params->dest = cfg->dest;
2822 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2823 cmd_params->ss_size = cpu_to_le16(cfg->ss_size);
2824 cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova);
2826 /* send command to mc*/
2827 return mc_send_command(mc_io, &cmd);
2830 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
2833 struct dpni_enable_ss_cfg *cfg)
2835 struct dpni_enable_sw_sequence *cmd_params;
2836 struct mc_command cmd = { 0 };
2838 /* prepare command */
2839 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE,
2842 cmd_params = (struct dpni_enable_sw_sequence *)cmd.params;
2843 cmd_params->dest = cfg->dest;
2844 cmd_params->set_start = cfg->set_start;
2845 cmd_params->hxs = cpu_to_le16(cfg->hxs);
2846 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2847 cmd_params->param_offset = cfg->param_offset;
2848 cmd_params->param_size = cfg->param_size;
2849 cmd_params->param_iova = cpu_to_le64(cfg->param_iova);
2851 /* send command to mc*/
2852 return mc_send_command(mc_io, &cmd);
2856 * dpni_get_sw_sequence_layout() - Get the soft sequence layout
2857 * @mc_io: Pointer to MC portal's I/O object
2858 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2859 * @token: Token of DPNI object
2860 * @src: Source of the layout (WRIOP Rx or Tx)
2861 * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory
2863 * warning: After calling this function, call dpni_extract_sw_sequence_layout()
2864 * to get the layout.
2866 * Return: '0' on Success; error code otherwise.
2868 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
2871 enum dpni_soft_sequence_dest src,
2872 uint64_t ss_layout_iova)
2874 struct dpni_get_sw_sequence_layout *cmd_params;
2875 struct mc_command cmd = { 0 };
2877 /* prepare command */
2878 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT,
2882 cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params;
2883 cmd_params->src = src;
2884 cmd_params->layout_iova = cpu_to_le64(ss_layout_iova);
2886 /* send command to mc*/
2887 return mc_send_command(mc_io, &cmd);
2891 * dpni_extract_sw_sequence_layout() - extract the software sequence layout
2892 * @layout: software sequence layout
2893 * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it
2896 * This function has to be called after dpni_get_sw_sequence_layout
2899 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
2900 const uint8_t *sw_sequence_layout_buf)
2902 const struct dpni_sw_sequence_layout_entry *ext_params;
2904 uint16_t ss_size, ss_offset;
2906 ext_params = (const struct dpni_sw_sequence_layout_entry *)
2907 sw_sequence_layout_buf;
2909 for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) {
2910 ss_offset = le16_to_cpu(ext_params[i].ss_offset);
2911 ss_size = le16_to_cpu(ext_params[i].ss_size);
2913 if (ss_offset == 0 && ss_size == 0) {
2918 layout->ss[i].ss_offset = ss_offset;
2919 layout->ss[i].ss_size = ss_size;
2920 layout->ss[i].param_offset = ext_params[i].param_offset;
2921 layout->ss[i].param_size = ext_params[i].param_size;
2925 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2926 * @mc_io: Pointer to MC portal's I/O object
2927 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2928 * @token: Token of DPNI object
2929 * @cfg: Distribution configuration
2930 * If the FS is already enabled with a previous call the classification
2931 * key will be changed but all the table rules are kept. If the
2932 * existing rules do not match the key the results will not be
2933 * predictable. It is the user responsibility to keep keyintegrity.
2934 * If cfg.enable is set to 1 the command will create a flow steering table
2935 * and will classify packets according to this table. The packets
2936 * that miss all the table rules will be classified according to
2937 * settings made in dpni_set_rx_hash_dist()
2938 * If cfg.enable is set to 0 the command will clear flow steering table. The
2939 * packets will be classified according to settings made in
2940 * dpni_set_rx_hash_dist()
2942 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2943 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2945 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2946 struct mc_command cmd = { 0 };
2948 /* prepare command */
2949 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2952 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2953 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2954 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2955 cmd_params->tc = cfg->tc;
2956 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2957 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2959 /* send command to mc*/
2960 return mc_send_command(mc_io, &cmd);
2964 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2965 * @mc_io: Pointer to MC portal's I/O object
2966 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2967 * @token: Token of DPNI object
2968 * @cfg: Distribution configuration
2969 * If cfg.enable is set to 1 the packets will be classified using a hash
2970 * function based on the key received in cfg.key_cfg_iova parameter.
2971 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2972 * dpni_set_rx_dist_default_queue() call
2974 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2975 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2977 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2978 struct mc_command cmd = { 0 };
2980 /* prepare command */
2981 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2984 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2985 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2986 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2987 cmd_params->tc_id = cfg->tc;
2988 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2990 /* send command to mc*/
2991 return mc_send_command(mc_io, &cmd);
2995 * dpni_add_custom_tpid() - Configures a distinct Ethertype value (or TPID
2996 * value) to indicate VLAN tag in adition to the common TPID values
2997 * 0x81000 and 0x88A8
2998 * @mc_io: Pointer to MC portal's I/O object
2999 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3000 * @token: Token of DPNI object
3001 * @tpid: New value for TPID
3003 * Only two custom values are accepted. If the function is called for the third
3004 * time it will return error.
3005 * To replace an existing value use dpni_remove_custom_tpid() to remove a
3006 * previous TPID and after that use again the function.
3008 * Return: '0' on Success; Error code otherwise.
3010 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3011 uint16_t token, uint16_t tpid)
3013 struct dpni_cmd_add_custom_tpid *cmd_params;
3014 struct mc_command cmd = { 0 };
3016 /* prepare command */
3017 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
3020 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
3021 cmd_params->tpid = cpu_to_le16(tpid);
3023 /* send command to mc*/
3024 return mc_send_command(mc_io, &cmd);
3028 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
3029 * previously with dpni_add_custom_tpid()
3030 * @mc_io: Pointer to MC portal's I/O object
3031 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3032 * @token: Token of DPNI object
3033 * @tpid: New value for TPID
3035 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
3038 * Return: '0' on Success; Error code otherwise.
3040 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3041 uint16_t token, uint16_t tpid)
3043 struct dpni_cmd_remove_custom_tpid *cmd_params;
3044 struct mc_command cmd = { 0 };
3046 /* prepare command */
3047 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
3050 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
3051 cmd_params->tpid = cpu_to_le16(tpid);
3053 /* send command to mc*/
3054 return mc_send_command(mc_io, &cmd);
3058 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured to
3059 * detect 802.1q frames
3060 * @mc_io: Pointer to MC portal's I/O object
3061 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3062 * @token: Token of DPNI object
3063 * @tpid: TPID values. Only nonzero members of the structure are valid.
3065 * Return: '0' on Success; Error code otherwise.
3067 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3068 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
3070 struct dpni_rsp_get_custom_tpid *rsp_params;
3071 struct mc_command cmd = { 0 };
3074 /* prepare command */
3075 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
3079 /* send command to mc*/
3080 err = mc_send_command(mc_io, &cmd);
3084 /* read command response */
3085 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
3086 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
3087 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
3093 * dpni_set_port_cfg() - performs configurations at physical port connected on
3094 * this dpni. The command have effect only if dpni is connected to
3095 * another dpni object
3096 * @mc_io: Pointer to MC portal's I/O object
3097 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3098 * @token: Token of DPNI object
3099 * @flags: Valid fields from port_cfg structure
3100 * @port_cfg: Configuration data; one or more of DPNI_PORT_CFG_
3101 * The command can be called only when dpni is connected to a dpmac object. If
3102 * the dpni is unconnected or the endpoint is not a dpni it will return error.
3103 * If dpmac endpoint is disconnected the settings will be lost
3105 int dpni_set_port_cfg(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3106 uint16_t token, uint32_t flags, struct dpni_port_cfg *port_cfg)
3108 struct dpni_cmd_set_port_cfg *cmd_params;
3109 struct mc_command cmd = { 0 };
3111 /* prepare command */
3112 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PORT_CFG,
3115 cmd_params = (struct dpni_cmd_set_port_cfg *)cmd.params;
3116 cmd_params->flags = cpu_to_le32(flags);
3117 dpni_set_field(cmd_params->bit_params, PORT_LOOPBACK_EN,
3118 !!port_cfg->loopback_en);
3120 /* send command to MC */
3121 return mc_send_command(mc_io, &cmd);