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;
132 /* send command to mc*/
133 err = mc_send_command(mc_io, &cmd);
137 /* retrieve response parameters */
138 *obj_id = mc_cmd_read_object_id(&cmd);
144 * dpni_destroy() - Destroy the DPNI object and release all its resources.
145 * @mc_io: Pointer to MC portal's I/O object
146 * @dprc_token: Parent container token; '0' for default container
147 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
148 * @object_id: The object id; it must be a valid id within the container that
149 * created this object;
151 * The function accepts the authentication token of the parent container that
152 * created the object (not the one that currently owns the object). The object
153 * is searched within parent using the provided 'object_id'.
154 * All tokens to the object must be closed before calling destroy.
156 * Return: '0' on Success; error code otherwise.
158 int dpni_destroy(struct fsl_mc_io *mc_io,
163 struct dpni_cmd_destroy *cmd_params;
164 struct mc_command cmd = { 0 };
166 /* prepare command */
167 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
170 /* set object id to destroy */
171 cmd_params = (struct dpni_cmd_destroy *)cmd.params;
172 cmd_params->dpsw_id = cpu_to_le32(object_id);
174 /* send command to mc*/
175 return mc_send_command(mc_io, &cmd);
179 * dpni_set_pools() - Set buffer pools configuration
180 * @mc_io: Pointer to MC portal's I/O object
181 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
182 * @token: Token of DPNI object
183 * @cfg: Buffer pools configuration
185 * mandatory for DPNI operation
186 * warning:Allowed only when DPNI is disabled
188 * Return: '0' on Success; Error code otherwise.
190 int dpni_set_pools(struct fsl_mc_io *mc_io,
193 const struct dpni_pools_cfg *cfg)
195 struct mc_command cmd = { 0 };
196 struct dpni_cmd_set_pools *cmd_params;
199 /* prepare command */
200 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
203 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
204 cmd_params->num_dpbp = cfg->num_dpbp;
205 cmd_params->pool_options = cfg->pool_options;
206 for (i = 0; i < cmd_params->num_dpbp; i++) {
207 cmd_params->pool[i].dpbp_id =
208 cpu_to_le16(cfg->pools[i].dpbp_id);
209 cmd_params->pool[i].priority_mask =
210 cfg->pools[i].priority_mask;
211 cmd_params->buffer_size[i] =
212 cpu_to_le16(cfg->pools[i].buffer_size);
213 cmd_params->backup_pool_mask |=
214 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
217 /* send command to mc*/
218 return mc_send_command(mc_io, &cmd);
222 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
223 * @mc_io: Pointer to MC portal's I/O object
224 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
225 * @token: Token of DPNI object
227 * Return: '0' on Success; Error code otherwise.
229 int dpni_enable(struct fsl_mc_io *mc_io,
233 struct mc_command cmd = { 0 };
235 /* prepare command */
236 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
240 /* send command to mc*/
241 return mc_send_command(mc_io, &cmd);
245 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
246 * @mc_io: Pointer to MC portal's I/O object
247 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
248 * @token: Token of DPNI object
250 * Return: '0' on Success; Error code otherwise.
252 int dpni_disable(struct fsl_mc_io *mc_io,
256 struct mc_command cmd = { 0 };
258 /* prepare command */
259 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
263 /* send command to mc*/
264 return mc_send_command(mc_io, &cmd);
268 * dpni_is_enabled() - Check if the DPNI is enabled.
269 * @mc_io: Pointer to MC portal's I/O object
270 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
271 * @token: Token of DPNI object
272 * @en: Returns '1' if object is enabled; '0' otherwise
274 * Return: '0' on Success; Error code otherwise.
276 int dpni_is_enabled(struct fsl_mc_io *mc_io,
281 struct mc_command cmd = { 0 };
282 struct dpni_rsp_is_enabled *rsp_params;
285 /* prepare command */
286 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
290 /* send command to mc*/
291 err = mc_send_command(mc_io, &cmd);
295 /* retrieve response parameters */
296 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
297 *en = dpni_get_field(rsp_params->enabled, ENABLE);
303 * dpni_reset() - Reset the DPNI, returns the object to initial state.
304 * @mc_io: Pointer to MC portal's I/O object
305 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
306 * @token: Token of DPNI object
308 * Return: '0' on Success; Error code otherwise.
310 int dpni_reset(struct fsl_mc_io *mc_io,
314 struct mc_command cmd = { 0 };
316 /* prepare command */
317 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
321 /* send command to mc*/
322 return mc_send_command(mc_io, &cmd);
326 * dpni_set_irq_enable() - Set overall interrupt state.
327 * @mc_io: Pointer to MC portal's I/O object
328 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
329 * @token: Token of DPNI object
330 * @irq_index: The interrupt index to configure
331 * @en: Interrupt state: - enable = 1, disable = 0
333 * Allows GPP software to control when interrupts are generated.
334 * Each interrupt can have up to 32 causes. The enable/disable control's the
335 * overall interrupt state. if the interrupt is disabled no causes will cause
338 * Return: '0' on Success; Error code otherwise.
340 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
346 struct mc_command cmd = { 0 };
347 struct dpni_cmd_set_irq_enable *cmd_params;
349 /* prepare command */
350 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
353 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
354 dpni_set_field(cmd_params->enable, ENABLE, en);
355 cmd_params->irq_index = irq_index;
357 /* send command to mc*/
358 return mc_send_command(mc_io, &cmd);
362 * dpni_get_irq_enable() - Get overall interrupt state
363 * @mc_io: Pointer to MC portal's I/O object
364 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
365 * @token: Token of DPNI object
366 * @irq_index: The interrupt index to configure
367 * @en: Returned interrupt state - enable = 1, disable = 0
369 * Return: '0' on Success; Error code otherwise.
371 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
377 struct mc_command cmd = { 0 };
378 struct dpni_cmd_get_irq_enable *cmd_params;
379 struct dpni_rsp_get_irq_enable *rsp_params;
383 /* prepare command */
384 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
387 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
388 cmd_params->irq_index = irq_index;
390 /* send command to mc*/
391 err = mc_send_command(mc_io, &cmd);
395 /* retrieve response parameters */
396 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
397 *en = dpni_get_field(rsp_params->enabled, ENABLE);
403 * dpni_set_irq_mask() - Set interrupt mask.
404 * @mc_io: Pointer to MC portal's I/O object
405 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
406 * @token: Token of DPNI object
407 * @irq_index: The interrupt index to configure
408 * @mask: Event mask to trigger interrupt;
411 * 1 = consider event for asserting IRQ
413 * Every interrupt can have up to 32 causes and the interrupt model supports
414 * masking/unmasking each cause independently
416 * Return: '0' on Success; Error code otherwise.
418 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
424 struct mc_command cmd = { 0 };
425 struct dpni_cmd_set_irq_mask *cmd_params;
427 /* prepare command */
428 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
431 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
432 cmd_params->mask = cpu_to_le32(mask);
433 cmd_params->irq_index = irq_index;
435 /* send command to mc*/
436 return mc_send_command(mc_io, &cmd);
440 * dpni_get_irq_mask() - Get interrupt mask.
441 * @mc_io: Pointer to MC portal's I/O object
442 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
443 * @token: Token of DPNI object
444 * @irq_index: The interrupt index to configure
445 * @mask: Returned event mask to trigger interrupt
447 * Every interrupt can have up to 32 causes and the interrupt model supports
448 * masking/unmasking each cause independently
450 * Return: '0' on Success; Error code otherwise.
452 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
458 struct mc_command cmd = { 0 };
459 struct dpni_cmd_get_irq_mask *cmd_params;
460 struct dpni_rsp_get_irq_mask *rsp_params;
463 /* prepare command */
464 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
467 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
468 cmd_params->irq_index = irq_index;
470 /* send command to mc*/
471 err = mc_send_command(mc_io, &cmd);
475 /* retrieve response parameters */
476 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
477 *mask = le32_to_cpu(rsp_params->mask);
483 * dpni_get_irq_status() - Get the current status of any pending interrupts.
484 * @mc_io: Pointer to MC portal's I/O object
485 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
486 * @token: Token of DPNI object
487 * @irq_index: The interrupt index to configure
488 * @status: Returned interrupts status - one bit per cause:
489 * 0 = no interrupt pending
490 * 1 = interrupt pending
492 * Return: '0' on Success; Error code otherwise.
494 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
500 struct mc_command cmd = { 0 };
501 struct dpni_cmd_get_irq_status *cmd_params;
502 struct dpni_rsp_get_irq_status *rsp_params;
505 /* prepare command */
506 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
509 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
510 cmd_params->status = cpu_to_le32(*status);
511 cmd_params->irq_index = irq_index;
513 /* send command to mc*/
514 err = mc_send_command(mc_io, &cmd);
518 /* retrieve response parameters */
519 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
520 *status = le32_to_cpu(rsp_params->status);
526 * dpni_clear_irq_status() - Clear a pending interrupt's status
527 * @mc_io: Pointer to MC portal's I/O object
528 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
529 * @token: Token of DPNI object
530 * @irq_index: The interrupt index to configure
531 * @status: bits to clear (W1C) - one bit per cause:
533 * 1 = clear status bit
535 * Return: '0' on Success; Error code otherwise.
537 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
543 struct mc_command cmd = { 0 };
544 struct dpni_cmd_clear_irq_status *cmd_params;
546 /* prepare command */
547 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
550 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
551 cmd_params->irq_index = irq_index;
552 cmd_params->status = cpu_to_le32(status);
554 /* send command to mc*/
555 return mc_send_command(mc_io, &cmd);
559 * dpni_get_attributes() - Retrieve DPNI attributes.
560 * @mc_io: Pointer to MC portal's I/O object
561 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
562 * @token: Token of DPNI object
563 * @attr: Object's attributes
565 * Return: '0' on Success; Error code otherwise.
567 int dpni_get_attributes(struct fsl_mc_io *mc_io,
570 struct dpni_attr *attr)
572 struct mc_command cmd = { 0 };
573 struct dpni_rsp_get_attr *rsp_params;
577 /* prepare command */
578 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
582 /* send command to mc*/
583 err = mc_send_command(mc_io, &cmd);
587 /* retrieve response parameters */
588 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
589 attr->options = le32_to_cpu(rsp_params->options);
590 attr->num_queues = rsp_params->num_queues;
591 attr->num_rx_tcs = rsp_params->num_rx_tcs;
592 attr->num_tx_tcs = rsp_params->num_tx_tcs;
593 attr->mac_filter_entries = rsp_params->mac_filter_entries;
594 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
595 attr->qos_entries = rsp_params->qos_entries;
596 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
597 attr->qos_key_size = rsp_params->qos_key_size;
598 attr->fs_key_size = rsp_params->fs_key_size;
599 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
600 attr->num_cgs = rsp_params->num_cgs;
606 * dpni_set_errors_behavior() - Set errors behavior
607 * @mc_io: Pointer to MC portal's I/O object
608 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
609 * @token: Token of DPNI object
610 * @cfg: Errors configuration
612 * This function may be called numerous times with different
615 * Return: '0' on Success; Error code otherwise.
617 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
620 struct dpni_error_cfg *cfg)
622 struct mc_command cmd = { 0 };
623 struct dpni_cmd_set_errors_behavior *cmd_params;
625 /* prepare command */
626 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
629 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
630 cmd_params->errors = cpu_to_le32(cfg->errors);
631 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
632 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
634 /* send command to mc*/
635 return mc_send_command(mc_io, &cmd);
639 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
640 * @mc_io: Pointer to MC portal's I/O object
641 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
642 * @token: Token of DPNI object
643 * @qtype: Type of queue to retrieve configuration for
644 * @layout: Returns buffer layout attributes
646 * Return: '0' on Success; Error code otherwise.
648 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
651 enum dpni_queue_type qtype,
652 struct dpni_buffer_layout *layout)
654 struct mc_command cmd = { 0 };
655 struct dpni_cmd_get_buffer_layout *cmd_params;
656 struct dpni_rsp_get_buffer_layout *rsp_params;
659 /* prepare command */
660 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
663 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
664 cmd_params->qtype = qtype;
666 /* send command to mc*/
667 err = mc_send_command(mc_io, &cmd);
671 /* retrieve response parameters */
672 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
673 layout->pass_timestamp =
674 (int)dpni_get_field(rsp_params->flags, PASS_TS);
675 layout->pass_parser_result =
676 (int)dpni_get_field(rsp_params->flags, PASS_PR);
677 layout->pass_frame_status =
678 (int)dpni_get_field(rsp_params->flags, PASS_FS);
679 layout->pass_sw_opaque =
680 (int)dpni_get_field(rsp_params->flags, PASS_SWO);
681 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
682 layout->data_align = le16_to_cpu(rsp_params->data_align);
683 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
684 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
690 * dpni_set_buffer_layout() - Set buffer layout configuration.
691 * @mc_io: Pointer to MC portal's I/O object
692 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
693 * @token: Token of DPNI object
694 * @qtype: Type of queue this configuration applies to
695 * @layout: Buffer layout configuration
697 * Return: '0' on Success; Error code otherwise.
699 * @warning Allowed only when DPNI is disabled
701 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
704 enum dpni_queue_type qtype,
705 const struct dpni_buffer_layout *layout)
707 struct mc_command cmd = { 0 };
708 struct dpni_cmd_set_buffer_layout *cmd_params;
710 /* prepare command */
711 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
714 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
715 cmd_params->qtype = qtype;
716 cmd_params->options = cpu_to_le16((uint16_t)layout->options);
717 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
718 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
719 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
720 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
721 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
722 cmd_params->data_align = cpu_to_le16(layout->data_align);
723 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
724 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
726 /* send command to mc*/
727 return mc_send_command(mc_io, &cmd);
731 * dpni_set_offload() - Set DPNI offload configuration.
732 * @mc_io: Pointer to MC portal's I/O object
733 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
734 * @token: Token of DPNI object
735 * @type: Type of DPNI offload
736 * @config: Offload configuration.
737 * For checksum offloads, non-zero value enables the offload
739 * Return: '0' on Success; Error code otherwise.
741 * @warning Allowed only when DPNI is disabled
744 int dpni_set_offload(struct fsl_mc_io *mc_io,
747 enum dpni_offload type,
750 struct mc_command cmd = { 0 };
751 struct dpni_cmd_set_offload *cmd_params;
753 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
756 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
757 cmd_params->dpni_offload = type;
758 cmd_params->config = cpu_to_le32(config);
760 return mc_send_command(mc_io, &cmd);
764 * dpni_get_offload() - Get DPNI offload configuration.
765 * @mc_io: Pointer to MC portal's I/O object
766 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
767 * @token: Token of DPNI object
768 * @type: Type of DPNI offload
769 * @config: Offload configuration.
770 * For checksum offloads, a value of 1 indicates that the
771 * offload is enabled.
773 * Return: '0' on Success; Error code otherwise.
775 * @warning Allowed only when DPNI is disabled
777 int dpni_get_offload(struct fsl_mc_io *mc_io,
780 enum dpni_offload type,
783 struct mc_command cmd = { 0 };
784 struct dpni_cmd_get_offload *cmd_params;
785 struct dpni_rsp_get_offload *rsp_params;
788 /* prepare command */
789 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
792 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
793 cmd_params->dpni_offload = type;
795 /* send command to mc*/
796 err = mc_send_command(mc_io, &cmd);
800 /* retrieve response parameters */
801 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
802 *config = le32_to_cpu(rsp_params->config);
808 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
809 * for enqueue operations
810 * @mc_io: Pointer to MC portal's I/O object
811 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
812 * @token: Token of DPNI object
813 * @qtype: Type of queue to receive QDID for
814 * @qdid: Returned virtual QDID value that should be used as an argument
815 * in all enqueue operations
817 * Return: '0' on Success; Error code otherwise.
819 int dpni_get_qdid(struct fsl_mc_io *mc_io,
822 enum dpni_queue_type qtype,
825 struct mc_command cmd = { 0 };
826 struct dpni_cmd_get_qdid *cmd_params;
827 struct dpni_rsp_get_qdid *rsp_params;
830 /* prepare command */
831 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
834 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
835 cmd_params->qtype = qtype;
837 /* send command to mc*/
838 err = mc_send_command(mc_io, &cmd);
842 /* retrieve response parameters */
843 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
844 *qdid = le16_to_cpu(rsp_params->qdid);
850 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
851 * @mc_io: Pointer to MC portal's I/O object
852 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
853 * @token: Token of DPNI object
854 * @data_offset: Tx data offset (from start of buffer)
856 * Return: '0' on Success; Error code otherwise.
858 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
861 uint16_t *data_offset)
863 struct mc_command cmd = { 0 };
864 struct dpni_rsp_get_tx_data_offset *rsp_params;
867 /* prepare command */
868 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
872 /* send command to mc*/
873 err = mc_send_command(mc_io, &cmd);
877 /* retrieve response parameters */
878 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
879 *data_offset = le16_to_cpu(rsp_params->data_offset);
885 * dpni_set_link_cfg() - set the link configuration.
886 * @mc_io: Pointer to MC portal's I/O object
887 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
888 * @token: Token of DPNI object
889 * @cfg: Link configuration
891 * Return: '0' on Success; Error code otherwise.
893 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
896 const struct dpni_link_cfg *cfg)
898 struct mc_command cmd = { 0 };
899 struct dpni_cmd_set_link_cfg *cmd_params;
901 /* prepare command */
902 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
905 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
906 cmd_params->rate = cpu_to_le32(cfg->rate);
907 cmd_params->options = cpu_to_le64(cfg->options);
908 cmd_params->advertising = cpu_to_le64(cfg->advertising);
910 /* send command to mc*/
911 return mc_send_command(mc_io, &cmd);
915 * dpni_get_link_state() - Return the link state (either up or down)
916 * @mc_io: Pointer to MC portal's I/O object
917 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
918 * @token: Token of DPNI object
919 * @state: Returned link state;
921 * Return: '0' on Success; Error code otherwise.
923 int dpni_get_link_state(struct fsl_mc_io *mc_io,
926 struct dpni_link_state *state)
928 struct mc_command cmd = { 0 };
929 struct dpni_rsp_get_link_state *rsp_params;
932 /* prepare command */
933 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
937 /* send command to mc*/
938 err = mc_send_command(mc_io, &cmd);
942 /* retrieve response parameters */
943 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
944 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
945 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
946 state->rate = le32_to_cpu(rsp_params->rate);
947 state->options = le64_to_cpu(rsp_params->options);
948 state->supported = le64_to_cpu(rsp_params->supported);
949 state->advertising = le64_to_cpu(rsp_params->advertising);
955 * dpni_set_tx_shaping() - Set the transmit shaping
956 * @mc_io: Pointer to MC portal's I/O object
957 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
958 * @token: Token of DPNI object
959 * @tx_cr_shaper: TX committed rate shaping configuration
960 * @tx_er_shaper: TX excess rate shaping configuration
961 * @coupled: Committed and excess rate shapers are coupled
963 * Return: '0' on Success; Error code otherwise.
965 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
968 const struct dpni_tx_shaping_cfg *tx_cr_shaper,
969 const struct dpni_tx_shaping_cfg *tx_er_shaper,
972 struct dpni_cmd_set_tx_shaping *cmd_params;
973 struct mc_command cmd = { 0 };
975 /* prepare command */
976 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
979 cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
980 cmd_params->tx_cr_max_burst_size =
981 cpu_to_le16(tx_cr_shaper->max_burst_size);
982 cmd_params->tx_er_max_burst_size =
983 cpu_to_le16(tx_er_shaper->max_burst_size);
984 cmd_params->tx_cr_rate_limit =
985 cpu_to_le32(tx_cr_shaper->rate_limit);
986 cmd_params->tx_er_rate_limit =
987 cpu_to_le32(tx_er_shaper->rate_limit);
988 dpni_set_field(cmd_params->coupled, COUPLED, coupled);
990 /* send command to mc*/
991 return mc_send_command(mc_io, &cmd);
995 * dpni_set_max_frame_length() - Set the maximum received frame length.
996 * @mc_io: Pointer to MC portal's I/O object
997 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
998 * @token: Token of DPNI object
999 * @max_frame_length: Maximum received frame length (in bytes);
1000 * frame is discarded if its length exceeds this value
1002 * Return: '0' on Success; Error code otherwise.
1004 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
1007 uint16_t max_frame_length)
1009 struct mc_command cmd = { 0 };
1010 struct dpni_cmd_set_max_frame_length *cmd_params;
1012 /* prepare command */
1013 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
1016 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
1017 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
1019 /* send command to mc*/
1020 return mc_send_command(mc_io, &cmd);
1024 * dpni_get_max_frame_length() - Get the maximum received frame length.
1025 * @mc_io: Pointer to MC portal's I/O object
1026 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1027 * @token: Token of DPNI object
1028 * @max_frame_length: Maximum received frame length (in bytes);
1029 * frame is discarded if its length exceeds this value
1031 * Return: '0' on Success; Error code otherwise.
1033 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
1036 uint16_t *max_frame_length)
1038 struct mc_command cmd = { 0 };
1039 struct dpni_rsp_get_max_frame_length *rsp_params;
1042 /* prepare command */
1043 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1047 /* send command to mc*/
1048 err = mc_send_command(mc_io, &cmd);
1052 /* retrieve response parameters */
1053 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1054 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1060 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1061 * @mc_io: Pointer to MC portal's I/O object
1062 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1063 * @token: Token of DPNI object
1064 * @en: Set to '1' to enable; '0' to disable
1066 * Return: '0' on Success; Error code otherwise.
1068 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1073 struct mc_command cmd = { 0 };
1074 struct dpni_cmd_set_multicast_promisc *cmd_params;
1076 /* prepare command */
1077 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1080 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1081 dpni_set_field(cmd_params->enable, ENABLE, en);
1083 /* send command to mc*/
1084 return mc_send_command(mc_io, &cmd);
1088 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1089 * @mc_io: Pointer to MC portal's I/O object
1090 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1091 * @token: Token of DPNI object
1092 * @en: Returns '1' if enabled; '0' otherwise
1094 * Return: '0' on Success; Error code otherwise.
1096 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1101 struct mc_command cmd = { 0 };
1102 struct dpni_rsp_get_multicast_promisc *rsp_params;
1105 /* prepare command */
1106 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1110 /* send command to mc*/
1111 err = mc_send_command(mc_io, &cmd);
1115 /* retrieve response parameters */
1116 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1117 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1123 * dpni_set_unicast_promisc() - Enable/disable unicast 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_unicast_promisc(struct fsl_mc_io *mc_io,
1136 struct mc_command cmd = { 0 };
1137 struct dpni_cmd_set_unicast_promisc *cmd_params;
1139 /* prepare command */
1140 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1143 cmd_params = (struct dpni_cmd_set_unicast_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_unicast_promisc() - Get unicast 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_unicast_promisc(struct fsl_mc_io *mc_io,
1164 struct mc_command cmd = { 0 };
1165 struct dpni_rsp_get_unicast_promisc *rsp_params;
1168 /* prepare command */
1169 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_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_unicast_promisc *)cmd.params;
1180 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1186 * dpni_set_primary_mac_addr() - Set the primary MAC address
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 * @mac_addr: MAC address to set as primary address
1192 * Return: '0' on Success; Error code otherwise.
1194 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1197 const uint8_t mac_addr[6])
1199 struct mc_command cmd = { 0 };
1200 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1203 /* prepare command */
1204 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1207 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1208 for (i = 0; i < 6; i++)
1209 cmd_params->mac_addr[i] = mac_addr[5 - i];
1211 /* send command to mc*/
1212 return mc_send_command(mc_io, &cmd);
1216 * dpni_get_primary_mac_addr() - Get the primary MAC address
1217 * @mc_io: Pointer to MC portal's I/O object
1218 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1219 * @token: Token of DPNI object
1220 * @mac_addr: Returned MAC address
1222 * Return: '0' on Success; Error code otherwise.
1224 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1227 uint8_t mac_addr[6])
1229 struct mc_command cmd = { 0 };
1230 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1233 /* prepare command */
1234 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1238 /* send command to mc*/
1239 err = mc_send_command(mc_io, &cmd);
1243 /* retrieve response parameters */
1244 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1245 for (i = 0; i < 6; i++)
1246 mac_addr[5 - i] = rsp_params->mac_addr[i];
1252 * dpni_add_mac_addr() - Add MAC address filter
1253 * @mc_io: Pointer to MC portal's I/O object
1254 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1255 * @token: Token of DPNI object
1256 * @mac_addr: MAC address to add
1257 * @flags : 0 - tc_id and flow_id will be ignored.
1258 * Pkt with this mac_id will be passed to the next
1259 * classification stages
1260 * DPNI_MAC_SET_QUEUE_ACTION
1261 * Pkt with this mac will be forward directly to
1262 * queue defined by the tc_id and flow_id
1263 * @tc_id : Traffic class selection (0-7)
1264 * @flow_id : Selects the specific queue out of the set allocated for the
1265 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1266 * Return: '0' on Success; Error code otherwise.
1268 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1271 const uint8_t mac_addr[6],
1276 struct mc_command cmd = { 0 };
1277 struct dpni_cmd_add_mac_addr *cmd_params;
1280 /* prepare command */
1281 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1284 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1285 cmd_params->flags = flags;
1286 cmd_params->tc_id = tc_id;
1287 cmd_params->fq_id = flow_id;
1289 for (i = 0; i < 6; i++)
1290 cmd_params->mac_addr[i] = mac_addr[5 - i];
1292 /* send command to mc*/
1293 return mc_send_command(mc_io, &cmd);
1297 * dpni_remove_mac_addr() - Remove MAC address filter
1298 * @mc_io: Pointer to MC portal's I/O object
1299 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1300 * @token: Token of DPNI object
1301 * @mac_addr: MAC address to remove
1303 * Return: '0' on Success; Error code otherwise.
1305 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1308 const uint8_t mac_addr[6])
1310 struct mc_command cmd = { 0 };
1311 struct dpni_cmd_remove_mac_addr *cmd_params;
1314 /* prepare command */
1315 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1318 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1319 for (i = 0; i < 6; i++)
1320 cmd_params->mac_addr[i] = mac_addr[5 - i];
1322 /* send command to mc*/
1323 return mc_send_command(mc_io, &cmd);
1327 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1328 * @mc_io: Pointer to MC portal's I/O object
1329 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1330 * @token: Token of DPNI object
1331 * @unicast: Set to '1' to clear unicast addresses
1332 * @multicast: Set to '1' to clear multicast addresses
1334 * The primary MAC address is not cleared by this operation.
1336 * Return: '0' on Success; Error code otherwise.
1338 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1344 struct mc_command cmd = { 0 };
1345 struct dpni_cmd_clear_mac_filters *cmd_params;
1347 /* prepare command */
1348 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1351 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1352 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1353 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1355 /* send command to mc*/
1356 return mc_send_command(mc_io, &cmd);
1360 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1361 * port the DPNI is attached to
1362 * @mc_io: Pointer to MC portal's I/O object
1363 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1364 * @token: Token of DPNI object
1365 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1367 * The primary MAC address is not cleared by this operation.
1369 * Return: '0' on Success; Error code otherwise.
1371 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1374 uint8_t mac_addr[6])
1376 struct mc_command cmd = { 0 };
1377 struct dpni_rsp_get_port_mac_addr *rsp_params;
1380 /* prepare command */
1381 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1385 /* send command to mc*/
1386 err = mc_send_command(mc_io, &cmd);
1390 /* retrieve response parameters */
1391 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1392 for (i = 0; i < 6; i++)
1393 mac_addr[5 - i] = rsp_params->mac_addr[i];
1399 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1400 * @mc_io: Pointer to MC portal's I/O object
1401 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1402 * @token: Token of DPNI object
1403 * @en: Set to '1' to enable; '0' to disable
1405 * Return: '0' on Success; Error code otherwise.
1407 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1412 struct dpni_cmd_enable_vlan_filter *cmd_params;
1413 struct mc_command cmd = { 0 };
1415 /* prepare command */
1416 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1419 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1420 dpni_set_field(cmd_params->en, ENABLE, en);
1422 /* send command to mc*/
1423 return mc_send_command(mc_io, &cmd);
1427 * dpni_add_vlan_id() - Add VLAN ID filter
1428 * @mc_io: Pointer to MC portal's I/O object
1429 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1430 * @token: Token of DPNI object
1431 * @vlan_id: VLAN ID to add
1432 * @flags: 0 - tc_id and flow_id will be ignored.
1433 * Pkt with this vlan_id will be passed to the next
1434 * classification stages
1435 * DPNI_VLAN_SET_QUEUE_ACTION
1436 * Pkt with this vlan_id will be forward directly to
1437 * queue defined by the tc_id and flow_id
1439 * @tc_id: Traffic class selection (0-7)
1440 * @flow_id: Selects the specific queue out of the set allocated for the
1441 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1443 * Return: '0' on Success; Error code otherwise.
1445 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1453 struct dpni_cmd_vlan_id *cmd_params;
1454 struct mc_command cmd = { 0 };
1456 /* prepare command */
1457 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1460 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1461 cmd_params->flags = flags;
1462 cmd_params->tc_id = tc_id;
1463 cmd_params->flow_id = flow_id;
1464 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1466 /* send command to mc*/
1467 return mc_send_command(mc_io, &cmd);
1471 * dpni_remove_vlan_id() - Remove VLAN ID filter
1472 * @mc_io: Pointer to MC portal's I/O object
1473 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1474 * @token: Token of DPNI object
1475 * @vlan_id: VLAN ID to remove
1477 * Return: '0' on Success; Error code otherwise.
1479 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1484 struct dpni_cmd_vlan_id *cmd_params;
1485 struct mc_command cmd = { 0 };
1487 /* prepare command */
1488 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1491 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1492 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1494 /* send command to mc*/
1495 return mc_send_command(mc_io, &cmd);
1499 * dpni_clear_vlan_filters() - Clear all VLAN filters
1500 * @mc_io: Pointer to MC portal's I/O object
1501 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1502 * @token: Token of DPNI object
1504 * Return: '0' on Success; Error code otherwise.
1506 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1510 struct mc_command cmd = { 0 };
1512 /* prepare command */
1513 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1517 /* send command to mc*/
1518 return mc_send_command(mc_io, &cmd);
1522 * dpni_set_tx_priorities() - Set transmission TC priority configuration
1523 * @mc_io: Pointer to MC portal's I/O object
1524 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1525 * @token: Token of DPNI object
1526 * @cfg: Transmission selection configuration
1528 * warning: Allowed only when DPNI is disabled
1530 * Return: '0' on Success; Error code otherwise.
1532 int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
1535 const struct dpni_tx_priorities_cfg *cfg)
1537 struct dpni_cmd_set_tx_priorities *cmd_params;
1538 struct mc_command cmd = { 0 };
1541 /* prepare command */
1542 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES,
1545 cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params;
1546 dpni_set_field(cmd_params->flags,
1548 cfg->separate_groups);
1549 cmd_params->prio_group_A = cfg->prio_group_A;
1550 cmd_params->prio_group_B = cfg->prio_group_B;
1552 for (i = 0; i + 1 < DPNI_MAX_TC; i = i + 2) {
1553 dpni_set_field(cmd_params->modes[i / 2],
1555 cfg->tc_sched[i].mode);
1556 dpni_set_field(cmd_params->modes[i / 2],
1558 cfg->tc_sched[i + 1].mode);
1561 for (i = 0; i < DPNI_MAX_TC; i++) {
1562 cmd_params->delta_bandwidth[i] =
1563 cpu_to_le16(cfg->tc_sched[i].delta_bandwidth);
1566 /* send command to mc*/
1567 return mc_send_command(mc_io, &cmd);
1571 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1572 * @mc_io: Pointer to MC portal's I/O object
1573 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1574 * @token: Token of DPNI object
1575 * @tc_id: Traffic class selection (0-7)
1576 * @cfg: Traffic class distribution configuration
1578 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1579 * first to prepare the key_cfg_iova parameter
1581 * Return: '0' on Success; error code otherwise.
1583 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1587 const struct dpni_rx_tc_dist_cfg *cfg)
1589 struct mc_command cmd = { 0 };
1590 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1592 /* prepare command */
1593 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1596 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1597 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1598 cmd_params->tc_id = tc_id;
1599 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1600 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1601 dpni_set_field(cmd_params->flags,
1604 dpni_set_field(cmd_params->flags,
1606 cfg->fs_cfg.miss_action);
1607 dpni_set_field(cmd_params->keep_hash_key,
1609 cfg->fs_cfg.keep_hash_key);
1610 dpni_set_field(cmd_params->keep_hash_key,
1612 cfg->fs_cfg.keep_entries);
1614 /* send command to mc*/
1615 return mc_send_command(mc_io, &cmd);
1619 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1620 * @mc_io: Pointer to MC portal's I/O object
1621 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1622 * @token: Token of DPNI object
1623 * @mode: Tx confirmation mode
1625 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1626 * selected at DPNI creation.
1627 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1628 * transmit confirmation (including the private confirmation queues), regardless
1629 * of previous settings; Note that in this case, Tx error frames are still
1630 * enqueued to the general transmit errors queue.
1631 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1632 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1633 * command will be ignored.
1635 * Return: '0' on Success; Error code otherwise.
1637 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1640 enum dpni_confirmation_mode mode)
1642 struct dpni_tx_confirmation_mode *cmd_params;
1643 struct mc_command cmd = { 0 };
1645 /* prepare command */
1646 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1649 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1650 cmd_params->confirmation_mode = mode;
1652 /* send command to mc*/
1653 return mc_send_command(mc_io, &cmd);
1657 * dpni_set_qos_table() - Set QoS mapping table
1658 * @mc_io: Pointer to MC portal's I/O object
1659 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1660 * @token: Token of DPNI object
1661 * @cfg: QoS table configuration
1663 * This function and all QoS-related functions require that
1664 *'max_tcs > 1' was set at DPNI creation.
1666 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1667 * prepare the key_cfg_iova parameter
1669 * Return: '0' on Success; Error code otherwise.
1671 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1674 const struct dpni_qos_tbl_cfg *cfg)
1676 struct dpni_cmd_set_qos_table *cmd_params;
1677 struct mc_command cmd = { 0 };
1679 /* prepare command */
1680 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1683 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1684 cmd_params->default_tc = cfg->default_tc;
1685 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1686 dpni_set_field(cmd_params->discard_on_miss,
1688 cfg->discard_on_miss);
1689 dpni_set_field(cmd_params->discard_on_miss,
1693 /* send command to mc*/
1694 return mc_send_command(mc_io, &cmd);
1698 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1699 * @mc_io: Pointer to MC portal's I/O object
1700 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1701 * @token: Token of DPNI object
1702 * @cfg: QoS rule to add
1703 * @tc_id: Traffic class selection (0-7)
1704 * @index: Location in the QoS table where to insert the entry.
1705 * Only relevant if MASKING is enabled for QoS classification on
1706 * this DPNI, it is ignored for exact match.
1708 * Return: '0' on Success; Error code otherwise.
1710 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1713 const struct dpni_rule_cfg *cfg,
1719 struct dpni_cmd_add_qos_entry *cmd_params;
1720 struct mc_command cmd = { 0 };
1722 /* prepare command */
1723 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1726 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1727 cmd_params->flags = flags;
1728 cmd_params->flow_id = flow_id;
1729 cmd_params->tc_id = tc_id;
1730 cmd_params->key_size = cfg->key_size;
1731 cmd_params->index = cpu_to_le16(index);
1732 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1733 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1735 /* send command to mc*/
1736 return mc_send_command(mc_io, &cmd);
1740 * dpni_remove_qos_entry() - Remove QoS mapping entry
1741 * @mc_io: Pointer to MC portal's I/O object
1742 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1743 * @token: Token of DPNI object
1744 * @cfg: QoS rule to remove
1746 * Return: '0' on Success; Error code otherwise.
1748 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1751 const struct dpni_rule_cfg *cfg)
1753 struct dpni_cmd_remove_qos_entry *cmd_params;
1754 struct mc_command cmd = { 0 };
1756 /* prepare command */
1757 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1760 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1761 cmd_params->key_size = cfg->key_size;
1762 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1763 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1765 /* send command to mc*/
1766 return mc_send_command(mc_io, &cmd);
1770 * dpni_clear_qos_table() - Clear all QoS mapping entries
1771 * @mc_io: Pointer to MC portal's I/O object
1772 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1773 * @token: Token of DPNI object
1775 * Following this function call, all frames are directed to
1776 * the default traffic class (0)
1778 * Return: '0' on Success; Error code otherwise.
1780 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1784 struct mc_command cmd = { 0 };
1786 /* prepare command */
1787 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1791 /* send command to mc*/
1792 return mc_send_command(mc_io, &cmd);
1796 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1797 * (to select a flow ID)
1798 * @mc_io: Pointer to MC portal's I/O object
1799 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1800 * @token: Token of DPNI object
1801 * @tc_id: Traffic class selection (0-7)
1802 * @index: Location in the QoS table where to insert the entry.
1803 * Only relevant if MASKING is enabled for QoS classification
1804 * on this DPNI, it is ignored for exact match.
1805 * @cfg: Flow steering rule to add
1806 * @action: Action to be taken as result of a classification hit
1808 * Return: '0' on Success; Error code otherwise.
1810 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1815 const struct dpni_rule_cfg *cfg,
1816 const struct dpni_fs_action_cfg *action)
1818 struct dpni_cmd_add_fs_entry *cmd_params;
1819 struct mc_command cmd = { 0 };
1821 /* prepare command */
1822 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1825 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1826 cmd_params->tc_id = tc_id;
1827 cmd_params->key_size = cfg->key_size;
1828 cmd_params->index = cpu_to_le16(index);
1829 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1830 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1831 cmd_params->options = cpu_to_le16(action->options);
1832 cmd_params->flow_id = cpu_to_le16(action->flow_id);
1833 cmd_params->flc = cpu_to_le64(action->flc);
1834 cmd_params->redir_token = cpu_to_le16(action->redirect_obj_token);
1836 /* send command to mc*/
1837 return mc_send_command(mc_io, &cmd);
1841 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1843 * @mc_io: Pointer to MC portal's I/O object
1844 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1845 * @token: Token of DPNI object
1846 * @tc_id: Traffic class selection (0-7)
1847 * @cfg: Flow steering rule to remove
1849 * Return: '0' on Success; Error code otherwise.
1851 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1855 const struct dpni_rule_cfg *cfg)
1857 struct dpni_cmd_remove_fs_entry *cmd_params;
1858 struct mc_command cmd = { 0 };
1860 /* prepare command */
1861 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1864 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1865 cmd_params->tc_id = tc_id;
1866 cmd_params->key_size = cfg->key_size;
1867 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1868 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1870 /* send command to mc*/
1871 return mc_send_command(mc_io, &cmd);
1875 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1877 * @mc_io: Pointer to MC portal's I/O object
1878 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1879 * @token: Token of DPNI object
1880 * @tc_id: Traffic class selection (0-7)
1882 * Return: '0' on Success; Error code otherwise.
1884 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1889 struct dpni_cmd_clear_fs_entries *cmd_params;
1890 struct mc_command cmd = { 0 };
1892 /* prepare command */
1893 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1896 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1897 cmd_params->tc_id = tc_id;
1899 /* send command to mc*/
1900 return mc_send_command(mc_io, &cmd);
1904 * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
1905 * @mc_io: Pointer to MC portal's I/O object
1906 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1907 * @token: Token of DPNI object
1908 * @tc_id: Traffic class selection (0-7)
1909 * @cfg: Traffic class policing configuration
1911 * Return: '0' on Success; error code otherwise.
1913 int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
1917 const struct dpni_rx_tc_policing_cfg *cfg)
1919 struct dpni_cmd_set_rx_tc_policing *cmd_params;
1920 struct mc_command cmd = { 0 };
1922 /* prepare command */
1923 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING,
1926 cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params;
1927 dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color);
1928 dpni_set_field(cmd_params->mode_color, MODE, cfg->mode);
1929 dpni_set_field(cmd_params->units, UNITS, cfg->units);
1930 cmd_params->options = cpu_to_le32(cfg->options);
1931 cmd_params->cir = cpu_to_le32(cfg->cir);
1932 cmd_params->cbs = cpu_to_le32(cfg->cbs);
1933 cmd_params->eir = cpu_to_le32(cfg->eir);
1934 cmd_params->ebs = cpu_to_le32(cfg->ebs);
1935 cmd_params->tc_id = tc_id;
1937 /* send command to mc*/
1938 return mc_send_command(mc_io, &cmd);
1942 * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration
1943 * @mc_io: Pointer to MC portal's I/O object
1944 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1945 * @token: Token of DPNI object
1946 * @tc_id: Traffic class selection (0-7)
1947 * @cfg: Traffic class policing configuration
1949 * Return: '0' on Success; error code otherwise.
1951 int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io,
1955 struct dpni_rx_tc_policing_cfg *cfg)
1957 struct dpni_rsp_get_rx_tc_policing *rsp_params;
1958 struct dpni_cmd_get_rx_tc_policing *cmd_params;
1959 struct mc_command cmd = { 0 };
1962 /* prepare command */
1963 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_TC_POLICING,
1966 cmd_params = (struct dpni_cmd_get_rx_tc_policing *)cmd.params;
1967 cmd_params->tc_id = tc_id;
1970 /* send command to mc*/
1971 err = mc_send_command(mc_io, &cmd);
1975 rsp_params = (struct dpni_rsp_get_rx_tc_policing *)cmd.params;
1976 cfg->options = le32_to_cpu(rsp_params->options);
1977 cfg->cir = le32_to_cpu(rsp_params->cir);
1978 cfg->cbs = le32_to_cpu(rsp_params->cbs);
1979 cfg->eir = le32_to_cpu(rsp_params->eir);
1980 cfg->ebs = le32_to_cpu(rsp_params->ebs);
1981 cfg->units = dpni_get_field(rsp_params->units, UNITS);
1982 cfg->mode = dpni_get_field(rsp_params->mode_color, MODE);
1983 cfg->default_color = dpni_get_field(rsp_params->mode_color, COLOR);
1989 * dpni_prepare_early_drop() - prepare an early drop.
1990 * @cfg: Early-drop configuration
1991 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
1993 * This function has to be called before dpni_set_rx_tc_early_drop or
1994 * dpni_set_tx_tc_early_drop
1997 void dpni_prepare_early_drop(const struct dpni_early_drop_cfg *cfg,
1998 uint8_t *early_drop_buf)
2000 struct dpni_early_drop *ext_params;
2002 ext_params = (struct dpni_early_drop *)early_drop_buf;
2004 dpni_set_field(ext_params->flags, DROP_ENABLE, cfg->enable);
2005 dpni_set_field(ext_params->flags, DROP_UNITS, cfg->units);
2006 ext_params->green_drop_probability = cfg->green.drop_probability;
2007 ext_params->green_max_threshold = cpu_to_le64(cfg->green.max_threshold);
2008 ext_params->green_min_threshold = cpu_to_le64(cfg->green.min_threshold);
2009 ext_params->yellow_drop_probability = cfg->yellow.drop_probability;
2010 ext_params->yellow_max_threshold =
2011 cpu_to_le64(cfg->yellow.max_threshold);
2012 ext_params->yellow_min_threshold =
2013 cpu_to_le64(cfg->yellow.min_threshold);
2014 ext_params->red_drop_probability = cfg->red.drop_probability;
2015 ext_params->red_max_threshold = cpu_to_le64(cfg->red.max_threshold);
2016 ext_params->red_min_threshold = cpu_to_le64(cfg->red.min_threshold);
2020 * dpni_extract_early_drop() - extract the early drop configuration.
2021 * @cfg: Early-drop configuration
2022 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2024 * This function has to be called after dpni_get_rx_tc_early_drop or
2025 * dpni_get_tx_tc_early_drop
2028 void dpni_extract_early_drop(struct dpni_early_drop_cfg *cfg,
2029 const uint8_t *early_drop_buf)
2031 const struct dpni_early_drop *ext_params;
2033 ext_params = (const struct dpni_early_drop *)early_drop_buf;
2035 cfg->enable = dpni_get_field(ext_params->flags, DROP_ENABLE);
2036 cfg->units = dpni_get_field(ext_params->flags, DROP_UNITS);
2037 cfg->green.drop_probability = ext_params->green_drop_probability;
2038 cfg->green.max_threshold = le64_to_cpu(ext_params->green_max_threshold);
2039 cfg->green.min_threshold = le64_to_cpu(ext_params->green_min_threshold);
2040 cfg->yellow.drop_probability = ext_params->yellow_drop_probability;
2041 cfg->yellow.max_threshold =
2042 le64_to_cpu(ext_params->yellow_max_threshold);
2043 cfg->yellow.min_threshold =
2044 le64_to_cpu(ext_params->yellow_min_threshold);
2045 cfg->red.drop_probability = ext_params->red_drop_probability;
2046 cfg->red.max_threshold = le64_to_cpu(ext_params->red_max_threshold);
2047 cfg->red.min_threshold = le64_to_cpu(ext_params->red_min_threshold);
2051 * dpni_set_early_drop() - Set traffic class early-drop configuration
2052 * @mc_io: Pointer to MC portal's I/O object
2053 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2054 * @token: Token of DPNI object
2055 * @qtype: Type of queue - only Rx and Tx types are supported
2056 * @tc_id: Traffic class selection (0-7)
2057 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory filled
2058 * with the early-drop configuration by calling dpni_prepare_early_drop()
2060 * warning: Before calling this function, call dpni_prepare_early_drop() to
2061 * prepare the early_drop_iova parameter
2063 * Return: '0' on Success; error code otherwise.
2065 int dpni_set_early_drop(struct fsl_mc_io *mc_io,
2068 enum dpni_queue_type qtype,
2070 uint64_t early_drop_iova)
2072 struct dpni_cmd_early_drop *cmd_params;
2073 struct mc_command cmd = { 0 };
2075 /* prepare command */
2076 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_EARLY_DROP,
2079 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2080 cmd_params->qtype = qtype;
2081 cmd_params->tc = tc_id;
2082 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2084 /* send command to mc*/
2085 return mc_send_command(mc_io, &cmd);
2089 * dpni_get_early_drop() - Get Rx traffic class early-drop configuration
2090 * @mc_io: Pointer to MC portal's I/O object
2091 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2092 * @token: Token of DPNI object
2093 * @qtype: Type of queue - only Rx and Tx types are supported
2094 * @tc_id: Traffic class selection (0-7)
2095 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory
2097 * warning: After calling this function, call dpni_extract_early_drop() to
2098 * get the early drop configuration
2100 * Return: '0' on Success; error code otherwise.
2102 int dpni_get_early_drop(struct fsl_mc_io *mc_io,
2105 enum dpni_queue_type qtype,
2107 uint64_t early_drop_iova)
2109 struct dpni_cmd_early_drop *cmd_params;
2110 struct mc_command cmd = { 0 };
2112 /* prepare command */
2113 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_EARLY_DROP,
2116 cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2117 cmd_params->qtype = qtype;
2118 cmd_params->tc = tc_id;
2119 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2121 /* send command to mc*/
2122 return mc_send_command(mc_io, &cmd);
2126 * dpni_set_congestion_notification() - Set traffic class congestion
2127 * notification configuration
2128 * @mc_io: Pointer to MC portal's I/O object
2129 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2130 * @token: Token of DPNI object
2131 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2132 * @tc_id: Traffic class selection (0-7)
2133 * @cfg: congestion notification configuration
2135 * Return: '0' on Success; error code otherwise.
2137 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
2140 enum dpni_queue_type qtype,
2142 const struct dpni_congestion_notification_cfg *cfg)
2144 struct dpni_cmd_set_congestion_notification *cmd_params;
2145 struct mc_command cmd = { 0 };
2147 /* prepare command */
2148 cmd.header = mc_encode_cmd_header(
2149 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
2152 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
2153 cmd_params->qtype = qtype;
2154 cmd_params->tc = tc_id;
2155 cmd_params->congestion_point = cfg->cg_point;
2156 cmd_params->cgid = (uint8_t)cfg->cgid;
2157 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
2158 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
2159 cmd_params->dest_priority = cfg->dest_cfg.priority;
2160 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
2161 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
2162 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
2163 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
2164 dpni_set_field(cmd_params->type_units,
2166 cfg->dest_cfg.dest_type);
2167 dpni_set_field(cmd_params->type_units,
2171 /* send command to mc*/
2172 return mc_send_command(mc_io, &cmd);
2176 * dpni_get_congestion_notification() - Get traffic class congestion
2177 * notification configuration
2178 * @mc_io: Pointer to MC portal's I/O object
2179 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2180 * @token: Token of DPNI object
2181 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2182 * @tc_id: Traffic class selection (0-7)
2183 * @cfg: congestion notification configuration
2185 * Return: '0' on Success; error code otherwise.
2187 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
2190 enum dpni_queue_type qtype,
2192 struct dpni_congestion_notification_cfg *cfg)
2194 struct dpni_rsp_get_congestion_notification *rsp_params;
2195 struct dpni_cmd_get_congestion_notification *cmd_params;
2196 struct mc_command cmd = { 0 };
2199 /* prepare command */
2200 cmd.header = mc_encode_cmd_header(
2201 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
2204 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
2205 cmd_params->qtype = qtype;
2206 cmd_params->tc = tc_id;
2207 cmd_params->congestion_point = cfg->cg_point;
2208 cmd_params->cgid = cfg->cgid;
2210 /* send command to mc*/
2211 err = mc_send_command(mc_io, &cmd);
2215 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
2216 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
2217 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
2218 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
2219 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
2220 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
2221 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
2222 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
2223 cfg->dest_cfg.priority = rsp_params->dest_priority;
2224 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
2231 * dpni_get_api_version() - Get Data Path Network Interface API version
2232 * @mc_io: Pointer to MC portal's I/O object
2233 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2234 * @major_ver: Major version of data path network interface API
2235 * @minor_ver: Minor version of data path network interface API
2237 * Return: '0' on Success; Error code otherwise.
2239 int dpni_get_api_version(struct fsl_mc_io *mc_io,
2241 uint16_t *major_ver,
2242 uint16_t *minor_ver)
2244 struct dpni_rsp_get_api_version *rsp_params;
2245 struct mc_command cmd = { 0 };
2248 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
2252 err = mc_send_command(mc_io, &cmd);
2256 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
2257 *major_ver = le16_to_cpu(rsp_params->major);
2258 *minor_ver = le16_to_cpu(rsp_params->minor);
2264 * dpni_set_queue() - Set queue parameters
2265 * @mc_io: Pointer to MC portal's I/O object
2266 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2267 * @token: Token of DPNI object
2268 * @qtype: Type of queue - all queue types are supported, although
2269 * the command is ignored for Tx
2270 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2271 * @index: Selects the specific queue out of the set allocated for the
2272 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2273 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
2274 * configuration options are set on the queue
2275 * @queue: Queue structure
2277 * Return: '0' on Success; Error code otherwise.
2279 int dpni_set_queue(struct fsl_mc_io *mc_io,
2282 enum dpni_queue_type qtype,
2286 const struct dpni_queue *queue)
2288 struct mc_command cmd = { 0 };
2289 struct dpni_cmd_set_queue *cmd_params;
2291 /* prepare command */
2292 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
2295 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
2296 cmd_params->qtype = qtype;
2297 cmd_params->tc = tc;
2298 cmd_params->index = index;
2299 cmd_params->options = options;
2300 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
2301 cmd_params->dest_prio = queue->destination.priority;
2302 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
2303 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
2304 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
2305 queue->destination.hold_active);
2306 cmd_params->flc = cpu_to_le64(queue->flc.value);
2307 cmd_params->user_context = cpu_to_le64(queue->user_context);
2308 cmd_params->cgid = queue->cgid;
2310 /* send command to mc */
2311 return mc_send_command(mc_io, &cmd);
2315 * dpni_get_queue() - Get queue parameters
2316 * @mc_io: Pointer to MC portal's I/O object
2317 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2318 * @token: Token of DPNI object
2319 * @qtype: Type of queue - all queue types are supported
2320 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2321 * @index: Selects the specific queue out of the set allocated for the
2322 * same TC. Value must be in range 0 to NUM_QUEUES - 1
2323 * @queue: Queue configuration structure
2324 * @qid: Queue identification
2326 * Return: '0' on Success; Error code otherwise.
2328 int dpni_get_queue(struct fsl_mc_io *mc_io,
2331 enum dpni_queue_type qtype,
2334 struct dpni_queue *queue,
2335 struct dpni_queue_id *qid)
2337 struct mc_command cmd = { 0 };
2338 struct dpni_cmd_get_queue *cmd_params;
2339 struct dpni_rsp_get_queue *rsp_params;
2342 /* prepare command */
2343 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
2346 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
2347 cmd_params->qtype = qtype;
2348 cmd_params->tc = tc;
2349 cmd_params->index = index;
2351 /* send command to mc */
2352 err = mc_send_command(mc_io, &cmd);
2356 /* retrieve response parameters */
2357 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2358 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2359 queue->destination.priority = rsp_params->dest_prio;
2360 queue->destination.type = dpni_get_field(rsp_params->flags,
2362 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2364 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2366 queue->flc.value = le64_to_cpu(rsp_params->flc);
2367 queue->user_context = le64_to_cpu(rsp_params->user_context);
2368 qid->fqid = le32_to_cpu(rsp_params->fqid);
2369 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2370 if (dpni_get_field(rsp_params->flags, CGID_VALID))
2371 queue->cgid = rsp_params->cgid;
2379 * dpni_get_statistics() - Get DPNI statistics
2380 * @mc_io: Pointer to MC portal's I/O object
2381 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2382 * @token: Token of DPNI object
2383 * @page: Selects the statistics page to retrieve, see
2384 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
2385 * @param: Custom parameter for some pages used to select
2386 * a certain statistic source, for example the TC.
2387 * @stat: Structure containing the statistics
2389 * Return: '0' on Success; Error code otherwise.
2391 int dpni_get_statistics(struct fsl_mc_io *mc_io,
2396 union dpni_statistics *stat)
2398 struct mc_command cmd = { 0 };
2399 struct dpni_cmd_get_statistics *cmd_params;
2400 struct dpni_rsp_get_statistics *rsp_params;
2403 /* prepare command */
2404 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2407 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2408 cmd_params->page_number = page;
2409 cmd_params->param = param;
2411 /* send command to mc */
2412 err = mc_send_command(mc_io, &cmd);
2416 /* retrieve response parameters */
2417 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2418 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2419 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2425 * dpni_reset_statistics() - Clears DPNI statistics
2426 * @mc_io: Pointer to MC portal's I/O object
2427 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2428 * @token: Token of DPNI object
2430 * Return: '0' on Success; Error code otherwise.
2432 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2436 struct mc_command cmd = { 0 };
2438 /* prepare command */
2439 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2443 /* send command to mc*/
2444 return mc_send_command(mc_io, &cmd);
2448 * dpni_set_taildrop() - Set taildrop per congestion group
2450 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2451 * congestion notification or early drop (WRED) configuration previously applied
2454 * @mc_io: Pointer to MC portal's I/O object
2455 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2456 * @token: Token of DPNI object
2457 * @cg_point: Congestion group identifier DPNI_CP_QUEUE is only supported in
2458 * combination with DPNI_QUEUE_RX.
2459 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2460 * @tc: Traffic class to apply this taildrop to
2461 * @index/cgid: Index of the queue if the DPNI supports multiple queues for
2462 * traffic distribution.
2463 * If CONGESTION_POINT is DPNI_CP_CONGESTION_GROUP then it
2464 * represent the cgid of the congestion point
2465 * @taildrop: Taildrop structure
2467 * Return: '0' on Success; Error code otherwise.
2469 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2472 enum dpni_congestion_point cg_point,
2473 enum dpni_queue_type qtype,
2476 struct dpni_taildrop *taildrop)
2478 struct mc_command cmd = { 0 };
2479 struct dpni_cmd_set_taildrop *cmd_params;
2481 /* prepare command */
2482 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2485 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2486 cmd_params->congestion_point = cg_point;
2487 cmd_params->qtype = qtype;
2488 cmd_params->tc = tc;
2489 cmd_params->index = index;
2490 cmd_params->units = taildrop->units;
2491 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2492 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2493 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2494 dpni_set_field(cmd_params->oal_hi,
2496 taildrop->oal >> DPNI_OAL_LO_SIZE);
2498 /* send command to mc */
2499 return mc_send_command(mc_io, &cmd);
2503 * dpni_get_taildrop() - Get taildrop information
2504 * @mc_io: Pointer to MC portal's I/O object
2505 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2506 * @token: Token of DPNI object
2507 * @cg_point: Congestion point
2508 * @q_type: Queue type on which the taildrop is configured.
2509 * Only Rx queues are supported for now
2510 * @tc: Traffic class to apply this taildrop to
2511 * @q_index: Index of the queue if the DPNI supports multiple queues for
2512 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2513 * @taildrop: Taildrop structure
2515 * Return: '0' on Success; Error code otherwise.
2517 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2520 enum dpni_congestion_point cg_point,
2521 enum dpni_queue_type qtype,
2524 struct dpni_taildrop *taildrop)
2526 struct mc_command cmd = { 0 };
2527 struct dpni_cmd_get_taildrop *cmd_params;
2528 struct dpni_rsp_get_taildrop *rsp_params;
2529 uint8_t oal_lo, oal_hi;
2532 /* prepare command */
2533 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2536 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2537 cmd_params->congestion_point = cg_point;
2538 cmd_params->qtype = qtype;
2539 cmd_params->tc = tc;
2540 cmd_params->index = index;
2542 /* send command to mc */
2543 err = mc_send_command(mc_io, &cmd);
2547 /* retrieve response parameters */
2548 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2549 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2550 taildrop->units = rsp_params->units;
2551 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2552 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2553 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2554 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2556 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2557 if (taildrop->oal >= 0x0800)
2558 taildrop->oal |= 0xF000;
2564 * dpni_set_opr() - Set Order Restoration configuration.
2565 * @mc_io: Pointer to MC portal's I/O object
2566 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2567 * @token: Token of DPNI object
2568 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2569 * @index: Selects the specific queue out of the set allocated
2570 * for the same TC. Value must be in range 0 to
2572 * @options: Configuration mode options
2573 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2574 * @cfg: Configuration options for the OPR
2576 * Return: '0' on Success; Error code otherwise.
2578 int dpni_set_opr(struct fsl_mc_io *mc_io,
2584 struct opr_cfg *cfg,
2587 struct dpni_cmd_set_opr *cmd_params;
2588 struct mc_command cmd = { 0 };
2590 /* prepare command */
2591 cmd.header = mc_encode_cmd_header(
2595 cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2596 cmd_params->tc_id = tc;
2597 cmd_params->index = index;
2598 cmd_params->options = options;
2599 cmd_params->opr_id = opr_id;
2600 cmd_params->oloe = cfg->oloe;
2601 cmd_params->oeane = cfg->oeane;
2602 cmd_params->olws = cfg->olws;
2603 cmd_params->oa = cfg->oa;
2604 cmd_params->oprrws = cfg->oprrws;
2606 /* send command to mc*/
2607 return mc_send_command(mc_io, &cmd);
2611 * dpni_get_opr() - Retrieve Order Restoration config and query.
2612 * @mc_io: Pointer to MC portal's I/O object
2613 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2614 * @token: Token of DPNI object
2615 * @tc: Traffic class, in range 0 to NUM_TCS - 1
2616 * @index: Selects the specific queue out of the set allocated
2617 * for the same TC. Value must be in range 0 to
2619 * @cfg: Returned OPR configuration
2620 * @qry: Returned OPR query
2622 * Return: '0' on Success; Error code otherwise.
2624 int dpni_get_opr(struct fsl_mc_io *mc_io,
2629 struct opr_cfg *cfg,
2630 struct opr_qry *qry,
2634 struct dpni_rsp_get_opr *rsp_params;
2635 struct dpni_cmd_get_opr *cmd_params;
2636 struct mc_command cmd = { 0 };
2639 /* prepare command */
2640 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2643 cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2644 cmd_params->index = index;
2645 cmd_params->tc_id = tc;
2646 cmd_params->flags = flags;
2647 cmd_params->opr_id = opr_id;
2649 /* send command to mc*/
2650 err = mc_send_command(mc_io, &cmd);
2654 /* retrieve response parameters */
2655 rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2656 cfg->oloe = rsp_params->oloe;
2657 cfg->oeane = rsp_params->oeane;
2658 cfg->olws = rsp_params->olws;
2659 cfg->oa = rsp_params->oa;
2660 cfg->oprrws = rsp_params->oprrws;
2661 qry->rip = dpni_get_field(rsp_params->flags, RIP);
2662 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2663 qry->nesn = le16_to_cpu(rsp_params->nesn);
2664 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2665 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2666 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2667 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2668 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2669 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2670 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2671 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2672 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2678 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2679 * @mc_io: Pointer to MC portal's I/O object
2680 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2681 * @token: Token of DPNI object
2682 * @cfg: Distribution configuration
2683 * If the FS is already enabled with a previous call the classification
2684 * key will be changed but all the table rules are kept. If the
2685 * existing rules do not match the key the results will not be
2686 * predictable. It is the user responsibility to keep keyintegrity.
2687 * If cfg.enable is set to 1 the command will create a flow steering table
2688 * and will classify packets according to this table. The packets
2689 * that miss all the table rules will be classified according to
2690 * settings made in dpni_set_rx_hash_dist()
2691 * If cfg.enable is set to 0 the command will clear flow steering table. The
2692 * packets will be classified according to settings made in
2693 * dpni_set_rx_hash_dist()
2695 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2696 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2698 struct dpni_cmd_set_rx_fs_dist *cmd_params;
2699 struct mc_command cmd = { 0 };
2701 /* prepare command */
2702 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2705 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2706 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2707 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2708 cmd_params->tc = cfg->tc;
2709 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2710 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2712 /* send command to mc*/
2713 return mc_send_command(mc_io, &cmd);
2717 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2718 * @mc_io: Pointer to MC portal's I/O object
2719 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2720 * @token: Token of DPNI object
2721 * @cfg: Distribution configuration
2722 * If cfg.enable is set to 1 the packets will be classified using a hash
2723 * function based on the key received in cfg.key_cfg_iova parameter.
2724 * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2725 * dpni_set_rx_dist_default_queue() call
2727 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2728 uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2730 struct dpni_cmd_set_rx_hash_dist *cmd_params;
2731 struct mc_command cmd = { 0 };
2733 /* prepare command */
2734 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2737 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2738 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2739 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2740 cmd_params->tc_id = cfg->tc;
2741 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2743 /* send command to mc*/
2744 return mc_send_command(mc_io, &cmd);
2748 * dpni_add_custom_tpid() - Configures a distinct Ethertype value (or TPID
2749 * value) to indicate VLAN tag in adition to the common TPID values
2750 * 0x81000 and 0x88A8
2751 * @mc_io: Pointer to MC portal's I/O object
2752 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2753 * @token: Token of DPNI object
2754 * @tpid: New value for TPID
2756 * Only two custom values are accepted. If the function is called for the third
2757 * time it will return error.
2758 * To replace an existing value use dpni_remove_custom_tpid() to remove a
2759 * previous TPID and after that use again the function.
2761 * Return: '0' on Success; Error code otherwise.
2763 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2764 uint16_t token, uint16_t tpid)
2766 struct dpni_cmd_add_custom_tpid *cmd_params;
2767 struct mc_command cmd = { 0 };
2769 /* prepare command */
2770 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
2773 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
2774 cmd_params->tpid = cpu_to_le16(tpid);
2776 /* send command to mc*/
2777 return mc_send_command(mc_io, &cmd);
2781 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
2782 * previously with dpni_add_custom_tpid()
2783 * @mc_io: Pointer to MC portal's I/O object
2784 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2785 * @token: Token of DPNI object
2786 * @tpid: New value for TPID
2788 * Use this function when a TPID value added with dpni_add_custom_tpid() needs
2791 * Return: '0' on Success; Error code otherwise.
2793 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2794 uint16_t token, uint16_t tpid)
2796 struct dpni_cmd_remove_custom_tpid *cmd_params;
2797 struct mc_command cmd = { 0 };
2799 /* prepare command */
2800 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
2803 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
2804 cmd_params->tpid = cpu_to_le16(tpid);
2806 /* send command to mc*/
2807 return mc_send_command(mc_io, &cmd);
2811 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured to
2812 * detect 802.1q frames
2813 * @mc_io: Pointer to MC portal's I/O object
2814 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2815 * @token: Token of DPNI object
2816 * @tpid: TPID values. Only nonzero members of the structure are valid.
2818 * Return: '0' on Success; Error code otherwise.
2820 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2821 uint16_t token, struct dpni_custom_tpid_cfg *tpid)
2823 struct dpni_rsp_get_custom_tpid *rsp_params;
2824 struct mc_command cmd = { 0 };
2827 /* prepare command */
2828 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
2832 /* send command to mc*/
2833 err = mc_send_command(mc_io, &cmd);
2837 /* read command response */
2838 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
2839 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
2840 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
2845 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
2848 struct dpni_load_ss_cfg *cfg)
2850 struct dpni_load_sw_sequence *cmd_params;
2851 struct mc_command cmd = { 0 };
2853 /* prepare command */
2854 cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE,
2857 cmd_params = (struct dpni_load_sw_sequence *)cmd.params;
2858 cmd_params->dest = cfg->dest;
2859 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2860 cmd_params->ss_size = cpu_to_le16(cfg->ss_size);
2861 cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova);
2863 /* send command to mc*/
2864 return mc_send_command(mc_io, &cmd);
2867 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
2870 struct dpni_enable_ss_cfg *cfg)
2872 struct dpni_enable_sw_sequence *cmd_params;
2873 struct mc_command cmd = { 0 };
2875 /* prepare command */
2876 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE,
2879 cmd_params = (struct dpni_enable_sw_sequence *)cmd.params;
2880 cmd_params->dest = cfg->dest;
2881 cmd_params->set_start = cfg->set_start;
2882 cmd_params->hxs = cpu_to_le16(cfg->hxs);
2883 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2884 cmd_params->param_offset = cfg->param_offset;
2885 cmd_params->param_size = cfg->param_size;
2886 cmd_params->param_iova = cpu_to_le64(cfg->param_iova);
2888 /* send command to mc*/
2889 return mc_send_command(mc_io, &cmd);
2893 * dpni_get_sw_sequence_layout() - Get the soft sequence layout
2894 * @mc_io: Pointer to MC portal's I/O object
2895 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2896 * @token: Token of DPNI object
2897 * @src: Source of the layout (WRIOP Rx or Tx)
2898 * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory
2900 * warning: After calling this function, call dpni_extract_sw_sequence_layout()
2901 * to get the layout.
2903 * Return: '0' on Success; error code otherwise.
2905 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
2908 enum dpni_soft_sequence_dest src,
2909 uint64_t ss_layout_iova)
2911 struct dpni_get_sw_sequence_layout *cmd_params;
2912 struct mc_command cmd = { 0 };
2914 /* prepare command */
2915 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT,
2919 cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params;
2920 cmd_params->src = src;
2921 cmd_params->layout_iova = cpu_to_le64(ss_layout_iova);
2923 /* send command to mc*/
2924 return mc_send_command(mc_io, &cmd);
2928 * dpni_extract_sw_sequence_layout() - extract the software sequence layout
2929 * @layout: software sequence layout
2930 * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it
2933 * This function has to be called after dpni_get_sw_sequence_layout
2936 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
2937 const uint8_t *sw_sequence_layout_buf)
2939 const struct dpni_sw_sequence_layout_entry *ext_params;
2941 uint16_t ss_size, ss_offset;
2943 ext_params = (const struct dpni_sw_sequence_layout_entry *)
2944 sw_sequence_layout_buf;
2946 for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) {
2947 ss_offset = le16_to_cpu(ext_params[i].ss_offset);
2948 ss_size = le16_to_cpu(ext_params[i].ss_size);
2950 if (ss_offset == 0 && ss_size == 0) {
2955 layout->ss[i].ss_offset = ss_offset;
2956 layout->ss[i].ss_size = ss_size;
2957 layout->ss[i].param_offset = ext_params[i].param_offset;
2958 layout->ss[i].param_size = ext_params[i].param_size;