1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
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->vlan_filter_entries = cfg->vlan_filter_entries;
125 cmd_params->qos_entries = cfg->qos_entries;
126 cmd_params->fs_entries = cpu_to_le16(cfg->fs_entries);
128 /* send command to mc*/
129 err = mc_send_command(mc_io, &cmd);
133 /* retrieve response parameters */
134 *obj_id = mc_cmd_read_object_id(&cmd);
140 * dpni_destroy() - Destroy the DPNI object and release all its resources.
141 * @mc_io: Pointer to MC portal's I/O object
142 * @dprc_token: Parent container token; '0' for default container
143 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
144 * @object_id: The object id; it must be a valid id within the container that
145 * created this object;
147 * The function accepts the authentication token of the parent container that
148 * created the object (not the one that currently owns the object). The object
149 * is searched within parent using the provided 'object_id'.
150 * All tokens to the object must be closed before calling destroy.
152 * Return: '0' on Success; error code otherwise.
154 int dpni_destroy(struct fsl_mc_io *mc_io,
159 struct dpni_cmd_destroy *cmd_params;
160 struct mc_command cmd = { 0 };
162 /* prepare command */
163 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
166 /* set object id to destroy */
167 cmd_params = (struct dpni_cmd_destroy *)cmd.params;
168 cmd_params->dpsw_id = cpu_to_le32(object_id);
170 /* send command to mc*/
171 return mc_send_command(mc_io, &cmd);
175 * dpni_set_pools() - Set buffer pools configuration
176 * @mc_io: Pointer to MC portal's I/O object
177 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
178 * @token: Token of DPNI object
179 * @cfg: Buffer pools configuration
181 * mandatory for DPNI operation
182 * warning:Allowed only when DPNI is disabled
184 * Return: '0' on Success; Error code otherwise.
186 int dpni_set_pools(struct fsl_mc_io *mc_io,
189 const struct dpni_pools_cfg *cfg)
191 struct mc_command cmd = { 0 };
192 struct dpni_cmd_set_pools *cmd_params;
195 /* prepare command */
196 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
199 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
200 cmd_params->num_dpbp = cfg->num_dpbp;
201 for (i = 0; i < DPNI_MAX_DPBP; i++) {
202 cmd_params->pool[i].dpbp_id =
203 cpu_to_le16(cfg->pools[i].dpbp_id);
204 cmd_params->pool[i].priority_mask =
205 cfg->pools[i].priority_mask;
206 cmd_params->buffer_size[i] =
207 cpu_to_le16(cfg->pools[i].buffer_size);
208 cmd_params->backup_pool_mask |=
209 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
212 /* send command to mc*/
213 return mc_send_command(mc_io, &cmd);
217 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
218 * @mc_io: Pointer to MC portal's I/O object
219 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
220 * @token: Token of DPNI object
222 * Return: '0' on Success; Error code otherwise.
224 int dpni_enable(struct fsl_mc_io *mc_io,
228 struct mc_command cmd = { 0 };
230 /* prepare command */
231 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
235 /* send command to mc*/
236 return mc_send_command(mc_io, &cmd);
240 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
241 * @mc_io: Pointer to MC portal's I/O object
242 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
243 * @token: Token of DPNI object
245 * Return: '0' on Success; Error code otherwise.
247 int dpni_disable(struct fsl_mc_io *mc_io,
251 struct mc_command cmd = { 0 };
253 /* prepare command */
254 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
258 /* send command to mc*/
259 return mc_send_command(mc_io, &cmd);
263 * dpni_is_enabled() - Check if the DPNI is enabled.
264 * @mc_io: Pointer to MC portal's I/O object
265 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
266 * @token: Token of DPNI object
267 * @en: Returns '1' if object is enabled; '0' otherwise
269 * Return: '0' on Success; Error code otherwise.
271 int dpni_is_enabled(struct fsl_mc_io *mc_io,
276 struct mc_command cmd = { 0 };
277 struct dpni_rsp_is_enabled *rsp_params;
280 /* prepare command */
281 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
285 /* send command to mc*/
286 err = mc_send_command(mc_io, &cmd);
290 /* retrieve response parameters */
291 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
292 *en = dpni_get_field(rsp_params->enabled, ENABLE);
298 * dpni_reset() - Reset the DPNI, returns the object to initial state.
299 * @mc_io: Pointer to MC portal's I/O object
300 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
301 * @token: Token of DPNI object
303 * Return: '0' on Success; Error code otherwise.
305 int dpni_reset(struct fsl_mc_io *mc_io,
309 struct mc_command cmd = { 0 };
311 /* prepare command */
312 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
316 /* send command to mc*/
317 return mc_send_command(mc_io, &cmd);
321 * dpni_set_irq_enable() - Set overall interrupt state.
322 * @mc_io: Pointer to MC portal's I/O object
323 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
324 * @token: Token of DPNI object
325 * @irq_index: The interrupt index to configure
326 * @en: Interrupt state: - enable = 1, disable = 0
328 * Allows GPP software to control when interrupts are generated.
329 * Each interrupt can have up to 32 causes. The enable/disable control's the
330 * overall interrupt state. if the interrupt is disabled no causes will cause
333 * Return: '0' on Success; Error code otherwise.
335 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
341 struct mc_command cmd = { 0 };
342 struct dpni_cmd_set_irq_enable *cmd_params;
344 /* prepare command */
345 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
348 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
349 dpni_set_field(cmd_params->enable, ENABLE, en);
350 cmd_params->irq_index = irq_index;
352 /* send command to mc*/
353 return mc_send_command(mc_io, &cmd);
357 * dpni_get_irq_enable() - Get overall interrupt state
358 * @mc_io: Pointer to MC portal's I/O object
359 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
360 * @token: Token of DPNI object
361 * @irq_index: The interrupt index to configure
362 * @en: Returned interrupt state - enable = 1, disable = 0
364 * Return: '0' on Success; Error code otherwise.
366 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
372 struct mc_command cmd = { 0 };
373 struct dpni_cmd_get_irq_enable *cmd_params;
374 struct dpni_rsp_get_irq_enable *rsp_params;
378 /* prepare command */
379 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
382 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
383 cmd_params->irq_index = irq_index;
385 /* send command to mc*/
386 err = mc_send_command(mc_io, &cmd);
390 /* retrieve response parameters */
391 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
392 *en = dpni_get_field(rsp_params->enabled, ENABLE);
398 * dpni_set_irq_mask() - Set interrupt mask.
399 * @mc_io: Pointer to MC portal's I/O object
400 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
401 * @token: Token of DPNI object
402 * @irq_index: The interrupt index to configure
403 * @mask: Event mask to trigger interrupt;
406 * 1 = consider event for asserting IRQ
408 * Every interrupt can have up to 32 causes and the interrupt model supports
409 * masking/unmasking each cause independently
411 * Return: '0' on Success; Error code otherwise.
413 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
419 struct mc_command cmd = { 0 };
420 struct dpni_cmd_set_irq_mask *cmd_params;
422 /* prepare command */
423 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
426 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
427 cmd_params->mask = cpu_to_le32(mask);
428 cmd_params->irq_index = irq_index;
430 /* send command to mc*/
431 return mc_send_command(mc_io, &cmd);
435 * dpni_get_irq_mask() - Get interrupt mask.
436 * @mc_io: Pointer to MC portal's I/O object
437 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
438 * @token: Token of DPNI object
439 * @irq_index: The interrupt index to configure
440 * @mask: Returned event mask to trigger interrupt
442 * Every interrupt can have up to 32 causes and the interrupt model supports
443 * masking/unmasking each cause independently
445 * Return: '0' on Success; Error code otherwise.
447 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
453 struct mc_command cmd = { 0 };
454 struct dpni_cmd_get_irq_mask *cmd_params;
455 struct dpni_rsp_get_irq_mask *rsp_params;
458 /* prepare command */
459 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
462 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
463 cmd_params->irq_index = irq_index;
465 /* send command to mc*/
466 err = mc_send_command(mc_io, &cmd);
470 /* retrieve response parameters */
471 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
472 *mask = le32_to_cpu(rsp_params->mask);
478 * dpni_get_irq_status() - Get the current status of any pending interrupts.
479 * @mc_io: Pointer to MC portal's I/O object
480 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
481 * @token: Token of DPNI object
482 * @irq_index: The interrupt index to configure
483 * @status: Returned interrupts status - one bit per cause:
484 * 0 = no interrupt pending
485 * 1 = interrupt pending
487 * Return: '0' on Success; Error code otherwise.
489 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
495 struct mc_command cmd = { 0 };
496 struct dpni_cmd_get_irq_status *cmd_params;
497 struct dpni_rsp_get_irq_status *rsp_params;
500 /* prepare command */
501 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
504 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
505 cmd_params->status = cpu_to_le32(*status);
506 cmd_params->irq_index = irq_index;
508 /* send command to mc*/
509 err = mc_send_command(mc_io, &cmd);
513 /* retrieve response parameters */
514 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
515 *status = le32_to_cpu(rsp_params->status);
521 * dpni_clear_irq_status() - Clear a pending interrupt's status
522 * @mc_io: Pointer to MC portal's I/O object
523 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
524 * @token: Token of DPNI object
525 * @irq_index: The interrupt index to configure
526 * @status: bits to clear (W1C) - one bit per cause:
528 * 1 = clear status bit
530 * Return: '0' on Success; Error code otherwise.
532 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
538 struct mc_command cmd = { 0 };
539 struct dpni_cmd_clear_irq_status *cmd_params;
541 /* prepare command */
542 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
545 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
546 cmd_params->irq_index = irq_index;
547 cmd_params->status = cpu_to_le32(status);
549 /* send command to mc*/
550 return mc_send_command(mc_io, &cmd);
554 * dpni_get_attributes() - Retrieve DPNI attributes.
555 * @mc_io: Pointer to MC portal's I/O object
556 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
557 * @token: Token of DPNI object
558 * @attr: Object's attributes
560 * Return: '0' on Success; Error code otherwise.
562 int dpni_get_attributes(struct fsl_mc_io *mc_io,
565 struct dpni_attr *attr)
567 struct mc_command cmd = { 0 };
568 struct dpni_rsp_get_attr *rsp_params;
572 /* prepare command */
573 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
577 /* send command to mc*/
578 err = mc_send_command(mc_io, &cmd);
582 /* retrieve response parameters */
583 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
584 attr->options = le32_to_cpu(rsp_params->options);
585 attr->num_queues = rsp_params->num_queues;
586 attr->num_rx_tcs = rsp_params->num_rx_tcs;
587 attr->num_tx_tcs = rsp_params->num_tx_tcs;
588 attr->mac_filter_entries = rsp_params->mac_filter_entries;
589 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
590 attr->qos_entries = rsp_params->qos_entries;
591 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
592 attr->qos_key_size = rsp_params->qos_key_size;
593 attr->fs_key_size = rsp_params->fs_key_size;
594 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
600 * dpni_set_errors_behavior() - Set errors behavior
601 * @mc_io: Pointer to MC portal's I/O object
602 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
603 * @token: Token of DPNI object
604 * @cfg: Errors configuration
606 * This function may be called numerous times with different
609 * Return: '0' on Success; Error code otherwise.
611 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
614 struct dpni_error_cfg *cfg)
616 struct mc_command cmd = { 0 };
617 struct dpni_cmd_set_errors_behavior *cmd_params;
619 /* prepare command */
620 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
623 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
624 cmd_params->errors = cpu_to_le32(cfg->errors);
625 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
626 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
628 /* send command to mc*/
629 return mc_send_command(mc_io, &cmd);
633 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
634 * @mc_io: Pointer to MC portal's I/O object
635 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
636 * @token: Token of DPNI object
637 * @qtype: Type of queue to retrieve configuration for
638 * @layout: Returns buffer layout attributes
640 * Return: '0' on Success; Error code otherwise.
642 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
645 enum dpni_queue_type qtype,
646 struct dpni_buffer_layout *layout)
648 struct mc_command cmd = { 0 };
649 struct dpni_cmd_get_buffer_layout *cmd_params;
650 struct dpni_rsp_get_buffer_layout *rsp_params;
653 /* prepare command */
654 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
657 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
658 cmd_params->qtype = qtype;
660 /* send command to mc*/
661 err = mc_send_command(mc_io, &cmd);
665 /* retrieve response parameters */
666 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
667 layout->pass_timestamp = dpni_get_field(rsp_params->flags, PASS_TS);
668 layout->pass_parser_result = dpni_get_field(rsp_params->flags, PASS_PR);
669 layout->pass_frame_status = dpni_get_field(rsp_params->flags, PASS_FS);
670 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
671 layout->data_align = le16_to_cpu(rsp_params->data_align);
672 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
673 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
679 * dpni_set_buffer_layout() - Set buffer layout configuration.
680 * @mc_io: Pointer to MC portal's I/O object
681 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
682 * @token: Token of DPNI object
683 * @qtype: Type of queue this configuration applies to
684 * @layout: Buffer layout configuration
686 * Return: '0' on Success; Error code otherwise.
688 * @warning Allowed only when DPNI is disabled
690 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
693 enum dpni_queue_type qtype,
694 const struct dpni_buffer_layout *layout)
696 struct mc_command cmd = { 0 };
697 struct dpni_cmd_set_buffer_layout *cmd_params;
699 /* prepare command */
700 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
703 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
704 cmd_params->qtype = qtype;
705 cmd_params->options = cpu_to_le16(layout->options);
706 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
707 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
708 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
709 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
710 cmd_params->data_align = cpu_to_le16(layout->data_align);
711 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
712 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
714 /* send command to mc*/
715 return mc_send_command(mc_io, &cmd);
719 * dpni_set_offload() - Set DPNI offload configuration.
720 * @mc_io: Pointer to MC portal's I/O object
721 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
722 * @token: Token of DPNI object
723 * @type: Type of DPNI offload
724 * @config: Offload configuration.
725 * For checksum offloads, non-zero value enables the offload
727 * Return: '0' on Success; Error code otherwise.
729 * @warning Allowed only when DPNI is disabled
732 int dpni_set_offload(struct fsl_mc_io *mc_io,
735 enum dpni_offload type,
738 struct mc_command cmd = { 0 };
739 struct dpni_cmd_set_offload *cmd_params;
741 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
744 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
745 cmd_params->dpni_offload = type;
746 cmd_params->config = cpu_to_le32(config);
748 return mc_send_command(mc_io, &cmd);
752 * dpni_get_offload() - Get DPNI offload configuration.
753 * @mc_io: Pointer to MC portal's I/O object
754 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
755 * @token: Token of DPNI object
756 * @type: Type of DPNI offload
757 * @config: Offload configuration.
758 * For checksum offloads, a value of 1 indicates that the
759 * offload is enabled.
761 * Return: '0' on Success; Error code otherwise.
763 * @warning Allowed only when DPNI is disabled
765 int dpni_get_offload(struct fsl_mc_io *mc_io,
768 enum dpni_offload type,
771 struct mc_command cmd = { 0 };
772 struct dpni_cmd_get_offload *cmd_params;
773 struct dpni_rsp_get_offload *rsp_params;
776 /* prepare command */
777 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
780 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
781 cmd_params->dpni_offload = type;
783 /* send command to mc*/
784 err = mc_send_command(mc_io, &cmd);
788 /* retrieve response parameters */
789 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
790 *config = le32_to_cpu(rsp_params->config);
796 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
797 * for enqueue operations
798 * @mc_io: Pointer to MC portal's I/O object
799 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
800 * @token: Token of DPNI object
801 * @qtype: Type of queue to receive QDID for
802 * @qdid: Returned virtual QDID value that should be used as an argument
803 * in all enqueue operations
805 * Return: '0' on Success; Error code otherwise.
807 int dpni_get_qdid(struct fsl_mc_io *mc_io,
810 enum dpni_queue_type qtype,
813 struct mc_command cmd = { 0 };
814 struct dpni_cmd_get_qdid *cmd_params;
815 struct dpni_rsp_get_qdid *rsp_params;
818 /* prepare command */
819 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
822 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
823 cmd_params->qtype = qtype;
825 /* send command to mc*/
826 err = mc_send_command(mc_io, &cmd);
830 /* retrieve response parameters */
831 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
832 *qdid = le16_to_cpu(rsp_params->qdid);
838 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
839 * @mc_io: Pointer to MC portal's I/O object
840 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
841 * @token: Token of DPNI object
842 * @data_offset: Tx data offset (from start of buffer)
844 * Return: '0' on Success; Error code otherwise.
846 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
849 uint16_t *data_offset)
851 struct mc_command cmd = { 0 };
852 struct dpni_rsp_get_tx_data_offset *rsp_params;
855 /* prepare command */
856 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
860 /* send command to mc*/
861 err = mc_send_command(mc_io, &cmd);
865 /* retrieve response parameters */
866 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
867 *data_offset = le16_to_cpu(rsp_params->data_offset);
873 * dpni_set_link_cfg() - set the link configuration.
874 * @mc_io: Pointer to MC portal's I/O object
875 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
876 * @token: Token of DPNI object
877 * @cfg: Link configuration
879 * Return: '0' on Success; Error code otherwise.
881 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
884 const struct dpni_link_cfg *cfg)
886 struct mc_command cmd = { 0 };
887 struct dpni_cmd_set_link_cfg *cmd_params;
889 /* prepare command */
890 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
893 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
894 cmd_params->rate = cpu_to_le32(cfg->rate);
895 cmd_params->options = cpu_to_le64(cfg->options);
897 /* send command to mc*/
898 return mc_send_command(mc_io, &cmd);
902 * dpni_get_link_state() - Return the link state (either up or down)
903 * @mc_io: Pointer to MC portal's I/O object
904 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
905 * @token: Token of DPNI object
906 * @state: Returned link state;
908 * Return: '0' on Success; Error code otherwise.
910 int dpni_get_link_state(struct fsl_mc_io *mc_io,
913 struct dpni_link_state *state)
915 struct mc_command cmd = { 0 };
916 struct dpni_rsp_get_link_state *rsp_params;
919 /* prepare command */
920 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
924 /* send command to mc*/
925 err = mc_send_command(mc_io, &cmd);
929 /* retrieve response parameters */
930 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
931 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
932 state->rate = le32_to_cpu(rsp_params->rate);
933 state->options = le64_to_cpu(rsp_params->options);
939 * dpni_set_max_frame_length() - Set the maximum received frame length.
940 * @mc_io: Pointer to MC portal's I/O object
941 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
942 * @token: Token of DPNI object
943 * @max_frame_length: Maximum received frame length (in bytes);
944 * frame is discarded if its length exceeds this value
946 * Return: '0' on Success; Error code otherwise.
948 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
951 uint16_t max_frame_length)
953 struct mc_command cmd = { 0 };
954 struct dpni_cmd_set_max_frame_length *cmd_params;
956 /* prepare command */
957 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
960 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
961 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
963 /* send command to mc*/
964 return mc_send_command(mc_io, &cmd);
968 * dpni_get_max_frame_length() - Get the maximum received frame length.
969 * @mc_io: Pointer to MC portal's I/O object
970 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
971 * @token: Token of DPNI object
972 * @max_frame_length: Maximum received frame length (in bytes);
973 * frame is discarded if its length exceeds this value
975 * Return: '0' on Success; Error code otherwise.
977 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
980 uint16_t *max_frame_length)
982 struct mc_command cmd = { 0 };
983 struct dpni_rsp_get_max_frame_length *rsp_params;
986 /* prepare command */
987 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
991 /* send command to mc*/
992 err = mc_send_command(mc_io, &cmd);
996 /* retrieve response parameters */
997 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
998 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1004 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1005 * @mc_io: Pointer to MC portal's I/O object
1006 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1007 * @token: Token of DPNI object
1008 * @en: Set to '1' to enable; '0' to disable
1010 * Return: '0' on Success; Error code otherwise.
1012 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1017 struct mc_command cmd = { 0 };
1018 struct dpni_cmd_set_multicast_promisc *cmd_params;
1020 /* prepare command */
1021 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1024 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1025 dpni_set_field(cmd_params->enable, ENABLE, en);
1027 /* send command to mc*/
1028 return mc_send_command(mc_io, &cmd);
1032 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1033 * @mc_io: Pointer to MC portal's I/O object
1034 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1035 * @token: Token of DPNI object
1036 * @en: Returns '1' if enabled; '0' otherwise
1038 * Return: '0' on Success; Error code otherwise.
1040 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1045 struct mc_command cmd = { 0 };
1046 struct dpni_rsp_get_multicast_promisc *rsp_params;
1049 /* prepare command */
1050 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1054 /* send command to mc*/
1055 err = mc_send_command(mc_io, &cmd);
1059 /* retrieve response parameters */
1060 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1061 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1067 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1068 * @mc_io: Pointer to MC portal's I/O object
1069 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1070 * @token: Token of DPNI object
1071 * @en: Set to '1' to enable; '0' to disable
1073 * Return: '0' on Success; Error code otherwise.
1075 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1080 struct mc_command cmd = { 0 };
1081 struct dpni_cmd_set_unicast_promisc *cmd_params;
1083 /* prepare command */
1084 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1087 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1088 dpni_set_field(cmd_params->enable, ENABLE, en);
1090 /* send command to mc*/
1091 return mc_send_command(mc_io, &cmd);
1095 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1096 * @mc_io: Pointer to MC portal's I/O object
1097 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1098 * @token: Token of DPNI object
1099 * @en: Returns '1' if enabled; '0' otherwise
1101 * Return: '0' on Success; Error code otherwise.
1103 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1108 struct mc_command cmd = { 0 };
1109 struct dpni_rsp_get_unicast_promisc *rsp_params;
1112 /* prepare command */
1113 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1117 /* send command to mc*/
1118 err = mc_send_command(mc_io, &cmd);
1122 /* retrieve response parameters */
1123 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1124 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1130 * dpni_set_primary_mac_addr() - Set the primary MAC address
1131 * @mc_io: Pointer to MC portal's I/O object
1132 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1133 * @token: Token of DPNI object
1134 * @mac_addr: MAC address to set as primary address
1136 * Return: '0' on Success; Error code otherwise.
1138 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1141 const uint8_t mac_addr[6])
1143 struct mc_command cmd = { 0 };
1144 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1147 /* prepare command */
1148 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1151 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1152 for (i = 0; i < 6; i++)
1153 cmd_params->mac_addr[i] = mac_addr[5 - i];
1155 /* send command to mc*/
1156 return mc_send_command(mc_io, &cmd);
1160 * dpni_get_primary_mac_addr() - Get the primary MAC address
1161 * @mc_io: Pointer to MC portal's I/O object
1162 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1163 * @token: Token of DPNI object
1164 * @mac_addr: Returned MAC address
1166 * Return: '0' on Success; Error code otherwise.
1168 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1171 uint8_t mac_addr[6])
1173 struct mc_command cmd = { 0 };
1174 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1177 /* prepare command */
1178 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1182 /* send command to mc*/
1183 err = mc_send_command(mc_io, &cmd);
1187 /* retrieve response parameters */
1188 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1189 for (i = 0; i < 6; i++)
1190 mac_addr[5 - i] = rsp_params->mac_addr[i];
1196 * dpni_add_mac_addr() - Add MAC address filter
1197 * @mc_io: Pointer to MC portal's I/O object
1198 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1199 * @token: Token of DPNI object
1200 * @mac_addr: MAC address to add
1202 * Return: '0' on Success; Error code otherwise.
1204 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1207 const uint8_t mac_addr[6])
1209 struct mc_command cmd = { 0 };
1210 struct dpni_cmd_add_mac_addr *cmd_params;
1213 /* prepare command */
1214 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1217 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1218 for (i = 0; i < 6; i++)
1219 cmd_params->mac_addr[i] = mac_addr[5 - i];
1221 /* send command to mc*/
1222 return mc_send_command(mc_io, &cmd);
1226 * dpni_remove_mac_addr() - Remove MAC address filter
1227 * @mc_io: Pointer to MC portal's I/O object
1228 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1229 * @token: Token of DPNI object
1230 * @mac_addr: MAC address to remove
1232 * Return: '0' on Success; Error code otherwise.
1234 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1237 const uint8_t mac_addr[6])
1239 struct mc_command cmd = { 0 };
1240 struct dpni_cmd_remove_mac_addr *cmd_params;
1243 /* prepare command */
1244 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1247 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1248 for (i = 0; i < 6; i++)
1249 cmd_params->mac_addr[i] = mac_addr[5 - i];
1251 /* send command to mc*/
1252 return mc_send_command(mc_io, &cmd);
1256 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1257 * @mc_io: Pointer to MC portal's I/O object
1258 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1259 * @token: Token of DPNI object
1260 * @unicast: Set to '1' to clear unicast addresses
1261 * @multicast: Set to '1' to clear multicast addresses
1263 * The primary MAC address is not cleared by this operation.
1265 * Return: '0' on Success; Error code otherwise.
1267 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1273 struct mc_command cmd = { 0 };
1274 struct dpni_cmd_clear_mac_filters *cmd_params;
1276 /* prepare command */
1277 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1280 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1281 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1282 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1284 /* send command to mc*/
1285 return mc_send_command(mc_io, &cmd);
1289 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1290 * port the DPNI is attached to
1291 * @mc_io: Pointer to MC portal's I/O object
1292 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1293 * @token: Token of DPNI object
1294 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1296 * The primary MAC address is not cleared by this operation.
1298 * Return: '0' on Success; Error code otherwise.
1300 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1303 uint8_t mac_addr[6])
1305 struct mc_command cmd = { 0 };
1306 struct dpni_rsp_get_port_mac_addr *rsp_params;
1309 /* prepare command */
1310 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1314 /* send command to mc*/
1315 err = mc_send_command(mc_io, &cmd);
1319 /* retrieve response parameters */
1320 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1321 for (i = 0; i < 6; i++)
1322 mac_addr[5 - i] = rsp_params->mac_addr[i];
1328 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1329 * @mc_io: Pointer to MC portal's I/O object
1330 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1331 * @token: Token of DPNI object
1332 * @en: Set to '1' to enable; '0' to disable
1334 * Return: '0' on Success; Error code otherwise.
1336 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1341 struct dpni_cmd_enable_vlan_filter *cmd_params;
1342 struct mc_command cmd = { 0 };
1344 /* prepare command */
1345 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1348 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1349 dpni_set_field(cmd_params->en, ENABLE, en);
1351 /* send command to mc*/
1352 return mc_send_command(mc_io, &cmd);
1356 * dpni_add_vlan_id() - Add VLAN ID filter
1357 * @mc_io: Pointer to MC portal's I/O object
1358 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1359 * @token: Token of DPNI object
1360 * @vlan_id: VLAN ID to add
1362 * Return: '0' on Success; Error code otherwise.
1364 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1369 struct dpni_cmd_vlan_id *cmd_params;
1370 struct mc_command cmd = { 0 };
1372 /* prepare command */
1373 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1376 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1377 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1379 /* send command to mc*/
1380 return mc_send_command(mc_io, &cmd);
1384 * dpni_remove_vlan_id() - Remove VLAN ID filter
1385 * @mc_io: Pointer to MC portal's I/O object
1386 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1387 * @token: Token of DPNI object
1388 * @vlan_id: VLAN ID to remove
1390 * Return: '0' on Success; Error code otherwise.
1392 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1397 struct dpni_cmd_vlan_id *cmd_params;
1398 struct mc_command cmd = { 0 };
1400 /* prepare command */
1401 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1404 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1405 cmd_params->vlan_id = cpu_to_le16(vlan_id);
1407 /* send command to mc*/
1408 return mc_send_command(mc_io, &cmd);
1412 * dpni_clear_vlan_filters() - Clear all VLAN filters
1413 * @mc_io: Pointer to MC portal's I/O object
1414 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1415 * @token: Token of DPNI object
1417 * Return: '0' on Success; Error code otherwise.
1419 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1423 struct mc_command cmd = { 0 };
1425 /* prepare command */
1426 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1430 /* send command to mc*/
1431 return mc_send_command(mc_io, &cmd);
1435 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1436 * @mc_io: Pointer to MC portal's I/O object
1437 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1438 * @token: Token of DPNI object
1439 * @tc_id: Traffic class selection (0-7)
1440 * @cfg: Traffic class distribution configuration
1442 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1443 * first to prepare the key_cfg_iova parameter
1445 * Return: '0' on Success; error code otherwise.
1447 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1451 const struct dpni_rx_tc_dist_cfg *cfg)
1453 struct mc_command cmd = { 0 };
1454 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1456 /* prepare command */
1457 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1460 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1461 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1462 cmd_params->tc_id = tc_id;
1463 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1464 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1465 dpni_set_field(cmd_params->flags,
1468 dpni_set_field(cmd_params->flags,
1470 cfg->fs_cfg.miss_action);
1471 dpni_set_field(cmd_params->keep_hash_key,
1473 cfg->fs_cfg.keep_hash_key);
1475 /* send command to mc*/
1476 return mc_send_command(mc_io, &cmd);
1480 * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1481 * @mc_io: Pointer to MC portal's I/O object
1482 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1483 * @token: Token of DPNI object
1484 * @mode: Tx confirmation mode
1486 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1487 * selected at DPNI creation.
1488 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1489 * transmit confirmation (including the private confirmation queues), regardless
1490 * of previous settings; Note that in this case, Tx error frames are still
1491 * enqueued to the general transmit errors queue.
1492 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1493 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1494 * command will be ignored.
1496 * Return: '0' on Success; Error code otherwise.
1498 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1501 enum dpni_confirmation_mode mode)
1503 struct dpni_tx_confirmation_mode *cmd_params;
1504 struct mc_command cmd = { 0 };
1506 /* prepare command */
1507 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1510 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1511 cmd_params->confirmation_mode = mode;
1513 /* send command to mc*/
1514 return mc_send_command(mc_io, &cmd);
1518 * dpni_set_congestion_notification() - Set traffic class congestion
1519 * notification configuration
1520 * @mc_io: Pointer to MC portal's I/O object
1521 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1522 * @token: Token of DPNI object
1523 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1524 * @tc_id: Traffic class selection (0-7)
1525 * @cfg: congestion notification configuration
1527 * Return: '0' on Success; error code otherwise.
1529 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1532 enum dpni_queue_type qtype,
1534 const struct dpni_congestion_notification_cfg *cfg)
1536 struct dpni_cmd_set_congestion_notification *cmd_params;
1537 struct mc_command cmd = { 0 };
1539 /* prepare command */
1540 cmd.header = mc_encode_cmd_header(
1541 DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
1544 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
1545 cmd_params->qtype = qtype;
1546 cmd_params->tc = tc_id;
1547 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1548 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
1549 cmd_params->dest_priority = cfg->dest_cfg.priority;
1550 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
1551 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
1552 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
1553 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
1554 dpni_set_field(cmd_params->type_units,
1556 cfg->dest_cfg.dest_type);
1557 dpni_set_field(cmd_params->type_units,
1561 /* send command to mc*/
1562 return mc_send_command(mc_io, &cmd);
1566 * dpni_get_congestion_notification() - Get traffic class congestion
1567 * notification configuration
1568 * @mc_io: Pointer to MC portal's I/O object
1569 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1570 * @token: Token of DPNI object
1571 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1572 * @tc_id: Traffic class selection (0-7)
1573 * @cfg: congestion notification configuration
1575 * Return: '0' on Success; error code otherwise.
1577 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1580 enum dpni_queue_type qtype,
1582 struct dpni_congestion_notification_cfg *cfg)
1584 struct dpni_rsp_get_congestion_notification *rsp_params;
1585 struct dpni_cmd_get_congestion_notification *cmd_params;
1586 struct mc_command cmd = { 0 };
1589 /* prepare command */
1590 cmd.header = mc_encode_cmd_header(
1591 DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
1594 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
1595 cmd_params->qtype = qtype;
1596 cmd_params->tc = tc_id;
1598 /* send command to mc*/
1599 err = mc_send_command(mc_io, &cmd);
1603 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
1604 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
1605 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
1606 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
1607 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
1608 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
1609 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
1610 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
1611 cfg->dest_cfg.priority = rsp_params->dest_priority;
1612 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
1619 * dpni_get_api_version() - Get Data Path Network Interface API version
1620 * @mc_io: Pointer to MC portal's I/O object
1621 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1622 * @major_ver: Major version of data path network interface API
1623 * @minor_ver: Minor version of data path network interface API
1625 * Return: '0' on Success; Error code otherwise.
1627 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1629 uint16_t *major_ver,
1630 uint16_t *minor_ver)
1632 struct dpni_rsp_get_api_version *rsp_params;
1633 struct mc_command cmd = { 0 };
1636 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1640 err = mc_send_command(mc_io, &cmd);
1644 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1645 *major_ver = le16_to_cpu(rsp_params->major);
1646 *minor_ver = le16_to_cpu(rsp_params->minor);
1652 * dpni_set_queue() - Set queue parameters
1653 * @mc_io: Pointer to MC portal's I/O object
1654 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1655 * @token: Token of DPNI object
1656 * @qtype: Type of queue - all queue types are supported, although
1657 * the command is ignored for Tx
1658 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1659 * @index: Selects the specific queue out of the set allocated for the
1660 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1661 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
1662 * configuration options are set on the queue
1663 * @queue: Queue structure
1665 * Return: '0' on Success; Error code otherwise.
1667 int dpni_set_queue(struct fsl_mc_io *mc_io,
1670 enum dpni_queue_type qtype,
1674 const struct dpni_queue *queue)
1676 struct mc_command cmd = { 0 };
1677 struct dpni_cmd_set_queue *cmd_params;
1679 /* prepare command */
1680 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1683 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1684 cmd_params->qtype = qtype;
1685 cmd_params->tc = tc;
1686 cmd_params->index = index;
1687 cmd_params->options = options;
1688 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1689 cmd_params->dest_prio = queue->destination.priority;
1690 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1691 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1692 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1693 queue->destination.hold_active);
1694 cmd_params->flc = cpu_to_le64(queue->flc.value);
1695 cmd_params->user_context = cpu_to_le64(queue->user_context);
1697 /* send command to mc */
1698 return mc_send_command(mc_io, &cmd);
1702 * dpni_get_queue() - Get queue parameters
1703 * @mc_io: Pointer to MC portal's I/O object
1704 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1705 * @token: Token of DPNI object
1706 * @qtype: Type of queue - all queue types are supported
1707 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1708 * @index: Selects the specific queue out of the set allocated for the
1709 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1710 * @queue: Queue configuration structure
1711 * @qid: Queue identification
1713 * Return: '0' on Success; Error code otherwise.
1715 int dpni_get_queue(struct fsl_mc_io *mc_io,
1718 enum dpni_queue_type qtype,
1721 struct dpni_queue *queue,
1722 struct dpni_queue_id *qid)
1724 struct mc_command cmd = { 0 };
1725 struct dpni_cmd_get_queue *cmd_params;
1726 struct dpni_rsp_get_queue *rsp_params;
1729 /* prepare command */
1730 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1733 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1734 cmd_params->qtype = qtype;
1735 cmd_params->tc = tc;
1736 cmd_params->index = index;
1738 /* send command to mc */
1739 err = mc_send_command(mc_io, &cmd);
1743 /* retrieve response parameters */
1744 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
1745 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
1746 queue->destination.priority = rsp_params->dest_prio;
1747 queue->destination.type = dpni_get_field(rsp_params->flags,
1749 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
1751 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
1753 queue->flc.value = le64_to_cpu(rsp_params->flc);
1754 queue->user_context = le64_to_cpu(rsp_params->user_context);
1755 qid->fqid = le32_to_cpu(rsp_params->fqid);
1756 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
1762 * dpni_get_statistics() - Get DPNI statistics
1763 * @mc_io: Pointer to MC portal's I/O object
1764 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1765 * @token: Token of DPNI object
1766 * @page: Selects the statistics page to retrieve, see
1767 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 2.
1768 * @param: Custom parameter for some pages used to select
1769 * a certain statistic source, for example the TC.
1770 * @stat: Structure containing the statistics
1772 * Return: '0' on Success; Error code otherwise.
1774 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1779 union dpni_statistics *stat)
1781 struct mc_command cmd = { 0 };
1782 struct dpni_cmd_get_statistics *cmd_params;
1783 struct dpni_rsp_get_statistics *rsp_params;
1786 /* prepare command */
1787 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
1790 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
1791 cmd_params->page_number = page;
1792 cmd_params->param = param;
1794 /* send command to mc */
1795 err = mc_send_command(mc_io, &cmd);
1799 /* retrieve response parameters */
1800 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
1801 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
1802 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
1808 * dpni_reset_statistics() - Clears DPNI statistics
1809 * @mc_io: Pointer to MC portal's I/O object
1810 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1811 * @token: Token of DPNI object
1813 * Return: '0' on Success; Error code otherwise.
1815 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1819 struct mc_command cmd = { 0 };
1821 /* prepare command */
1822 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
1826 /* send command to mc*/
1827 return mc_send_command(mc_io, &cmd);
1831 * dpni_set_taildrop() - Set taildrop per queue or TC
1833 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
1834 * congestion notification or early drop (WRED) configuration previously applied
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 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in
1841 * combination with DPNI_QUEUE_RX.
1842 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
1843 * @tc: Traffic class to apply this taildrop to
1844 * @q_index: Index of the queue if the DPNI supports multiple queues for
1845 * traffic distribution.
1846 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
1847 * @taildrop: Taildrop structure
1849 * Return: '0' on Success; Error code otherwise.
1851 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1854 enum dpni_congestion_point cg_point,
1855 enum dpni_queue_type qtype,
1858 struct dpni_taildrop *taildrop)
1860 struct mc_command cmd = { 0 };
1861 struct dpni_cmd_set_taildrop *cmd_params;
1863 /* prepare command */
1864 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
1867 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
1868 cmd_params->congestion_point = cg_point;
1869 cmd_params->qtype = qtype;
1870 cmd_params->tc = tc;
1871 cmd_params->index = index;
1872 cmd_params->units = taildrop->units;
1873 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
1874 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
1875 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
1876 dpni_set_field(cmd_params->oal_hi,
1878 taildrop->oal >> DPNI_OAL_LO_SIZE);
1880 /* send command to mc */
1881 return mc_send_command(mc_io, &cmd);
1885 * dpni_get_taildrop() - Get taildrop information
1886 * @mc_io: Pointer to MC portal's I/O object
1887 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1888 * @token: Token of DPNI object
1889 * @cg_point: Congestion point
1890 * @q_type: Queue type on which the taildrop is configured.
1891 * Only Rx queues are supported for now
1892 * @tc: Traffic class to apply this taildrop to
1893 * @q_index: Index of the queue if the DPNI supports multiple queues for
1894 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
1895 * @taildrop: Taildrop structure
1897 * Return: '0' on Success; Error code otherwise.
1899 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1902 enum dpni_congestion_point cg_point,
1903 enum dpni_queue_type qtype,
1906 struct dpni_taildrop *taildrop)
1908 struct mc_command cmd = { 0 };
1909 struct dpni_cmd_get_taildrop *cmd_params;
1910 struct dpni_rsp_get_taildrop *rsp_params;
1911 uint8_t oal_lo, oal_hi;
1914 /* prepare command */
1915 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
1918 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
1919 cmd_params->congestion_point = cg_point;
1920 cmd_params->qtype = qtype;
1921 cmd_params->tc = tc;
1922 cmd_params->index = index;
1924 /* send command to mc */
1925 err = mc_send_command(mc_io, &cmd);
1929 /* retrieve response parameters */
1930 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
1931 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
1932 taildrop->units = rsp_params->units;
1933 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
1934 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
1935 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
1936 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
1938 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
1939 if (taildrop->oal >= 0x0800)
1940 taildrop->oal |= 0xF000;