Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright 2014-2016 Freescale Semiconductor Inc.
0004  * Copyright 2017-2021 NXP
0005  *
0006  */
0007 
0008 #include <linux/fsl/mc.h>
0009 #include "dpsw.h"
0010 #include "dpsw-cmd.h"
0011 
0012 static void build_if_id_bitmap(__le64 *bmap, const u16 *id, const u16 num_ifs)
0013 {
0014     int i;
0015 
0016     for (i = 0; (i < num_ifs) && (i < DPSW_MAX_IF); i++) {
0017         if (id[i] < DPSW_MAX_IF)
0018             bmap[id[i] / 64] |= cpu_to_le64(BIT_MASK(id[i] % 64));
0019     }
0020 }
0021 
0022 /**
0023  * dpsw_open() - Open a control session for the specified object
0024  * @mc_io:  Pointer to MC portal's I/O object
0025  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0026  * @dpsw_id:    DPSW unique ID
0027  * @token:  Returned token; use in subsequent API calls
0028  *
0029  * This function can be used to open a control session for an
0030  * already created object; an object may have been declared in
0031  * the DPL or by calling the dpsw_create() function.
0032  * This function returns a unique authentication token,
0033  * associated with the specific object ID and the specific MC
0034  * portal; this token must be used in all subsequent commands for
0035  * this specific object
0036  *
0037  * Return:  '0' on Success; Error code otherwise.
0038  */
0039 int dpsw_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpsw_id, u16 *token)
0040 {
0041     struct fsl_mc_command cmd = { 0 };
0042     struct dpsw_cmd_open *cmd_params;
0043     int err;
0044 
0045     /* prepare command */
0046     cmd.header = mc_encode_cmd_header(DPSW_CMDID_OPEN,
0047                       cmd_flags,
0048                       0);
0049     cmd_params = (struct dpsw_cmd_open *)cmd.params;
0050     cmd_params->dpsw_id = cpu_to_le32(dpsw_id);
0051 
0052     /* send command to mc*/
0053     err = mc_send_command(mc_io, &cmd);
0054     if (err)
0055         return err;
0056 
0057     /* retrieve response parameters */
0058     *token = mc_cmd_hdr_read_token(&cmd);
0059 
0060     return 0;
0061 }
0062 
0063 /**
0064  * dpsw_close() - Close the control session of the object
0065  * @mc_io:  Pointer to MC portal's I/O object
0066  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0067  * @token:  Token of DPSW object
0068  *
0069  * After this function is called, no further operations are
0070  * allowed on the object without opening a new control session.
0071  *
0072  * Return:  '0' on Success; Error code otherwise.
0073  */
0074 int dpsw_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0075 {
0076     struct fsl_mc_command cmd = { 0 };
0077 
0078     /* prepare command */
0079     cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLOSE,
0080                       cmd_flags,
0081                       token);
0082 
0083     /* send command to mc*/
0084     return mc_send_command(mc_io, &cmd);
0085 }
0086 
0087 /**
0088  * dpsw_enable() - Enable DPSW functionality
0089  * @mc_io:  Pointer to MC portal's I/O object
0090  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0091  * @token:  Token of DPSW object
0092  *
0093  * Return:  Completion status. '0' on Success; Error code otherwise.
0094  */
0095 int dpsw_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0096 {
0097     struct fsl_mc_command cmd = { 0 };
0098 
0099     /* prepare command */
0100     cmd.header = mc_encode_cmd_header(DPSW_CMDID_ENABLE,
0101                       cmd_flags,
0102                       token);
0103 
0104     /* send command to mc*/
0105     return mc_send_command(mc_io, &cmd);
0106 }
0107 
0108 /**
0109  * dpsw_disable() - Disable DPSW functionality
0110  * @mc_io:  Pointer to MC portal's I/O object
0111  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0112  * @token:  Token of DPSW object
0113  *
0114  * Return:  Completion status. '0' on Success; Error code otherwise.
0115  */
0116 int dpsw_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0117 {
0118     struct fsl_mc_command cmd = { 0 };
0119 
0120     /* prepare command */
0121     cmd.header = mc_encode_cmd_header(DPSW_CMDID_DISABLE,
0122                       cmd_flags,
0123                       token);
0124 
0125     /* send command to mc*/
0126     return mc_send_command(mc_io, &cmd);
0127 }
0128 
0129 /**
0130  * dpsw_reset() - Reset the DPSW, returns the object to initial state.
0131  * @mc_io:  Pointer to MC portal's I/O object
0132  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0133  * @token:  Token of DPSW object
0134  *
0135  * Return:  '0' on Success; Error code otherwise.
0136  */
0137 int dpsw_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0138 {
0139     struct fsl_mc_command cmd = { 0 };
0140 
0141     /* prepare command */
0142     cmd.header = mc_encode_cmd_header(DPSW_CMDID_RESET,
0143                       cmd_flags,
0144                       token);
0145 
0146     /* send command to mc*/
0147     return mc_send_command(mc_io, &cmd);
0148 }
0149 
0150 /**
0151  * dpsw_set_irq_enable() - Set overall interrupt state.
0152  * @mc_io:  Pointer to MC portal's I/O object
0153  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0154  * @token:  Token of DPCI object
0155  * @irq_index:  The interrupt index to configure
0156  * @en:     Interrupt state - enable = 1, disable = 0
0157  *
0158  * Allows GPP software to control when interrupts are generated.
0159  * Each interrupt can have up to 32 causes.  The enable/disable control's the
0160  * overall interrupt state. if the interrupt is disabled no causes will cause
0161  * an interrupt
0162  *
0163  * Return:  '0' on Success; Error code otherwise.
0164  */
0165 int dpsw_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0166             u8 irq_index, u8 en)
0167 {
0168     struct fsl_mc_command cmd = { 0 };
0169     struct dpsw_cmd_set_irq_enable *cmd_params;
0170 
0171     /* prepare command */
0172     cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_ENABLE,
0173                       cmd_flags,
0174                       token);
0175     cmd_params = (struct dpsw_cmd_set_irq_enable *)cmd.params;
0176     dpsw_set_field(cmd_params->enable_state, ENABLE, en);
0177     cmd_params->irq_index = irq_index;
0178 
0179     /* send command to mc*/
0180     return mc_send_command(mc_io, &cmd);
0181 }
0182 
0183 /**
0184  * dpsw_set_irq_mask() - Set interrupt mask.
0185  * @mc_io:  Pointer to MC portal's I/O object
0186  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0187  * @token:  Token of DPCI object
0188  * @irq_index:  The interrupt index to configure
0189  * @mask:   Event mask to trigger interrupt;
0190  *      each bit:
0191  *          0 = ignore event
0192  *          1 = consider event for asserting IRQ
0193  *
0194  * Every interrupt can have up to 32 causes and the interrupt model supports
0195  * masking/unmasking each cause independently
0196  *
0197  * Return:  '0' on Success; Error code otherwise.
0198  */
0199 int dpsw_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0200               u8 irq_index, u32 mask)
0201 {
0202     struct fsl_mc_command cmd = { 0 };
0203     struct dpsw_cmd_set_irq_mask *cmd_params;
0204 
0205     /* prepare command */
0206     cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_MASK,
0207                       cmd_flags,
0208                       token);
0209     cmd_params = (struct dpsw_cmd_set_irq_mask *)cmd.params;
0210     cmd_params->mask = cpu_to_le32(mask);
0211     cmd_params->irq_index = irq_index;
0212 
0213     /* send command to mc*/
0214     return mc_send_command(mc_io, &cmd);
0215 }
0216 
0217 /**
0218  * dpsw_get_irq_status() - Get the current status of any pending interrupts
0219  * @mc_io:  Pointer to MC portal's I/O object
0220  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0221  * @token:  Token of DPSW object
0222  * @irq_index:  The interrupt index to configure
0223  * @status: Returned interrupts status - one bit per cause:
0224  *          0 = no interrupt pending
0225  *          1 = interrupt pending
0226  *
0227  * Return:  '0' on Success; Error code otherwise.
0228  */
0229 int dpsw_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0230             u8 irq_index, u32 *status)
0231 {
0232     struct fsl_mc_command cmd = { 0 };
0233     struct dpsw_cmd_get_irq_status *cmd_params;
0234     struct dpsw_rsp_get_irq_status *rsp_params;
0235     int err;
0236 
0237     /* prepare command */
0238     cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_IRQ_STATUS,
0239                       cmd_flags,
0240                       token);
0241     cmd_params = (struct dpsw_cmd_get_irq_status *)cmd.params;
0242     cmd_params->status = cpu_to_le32(*status);
0243     cmd_params->irq_index = irq_index;
0244 
0245     /* send command to mc*/
0246     err = mc_send_command(mc_io, &cmd);
0247     if (err)
0248         return err;
0249 
0250     /* retrieve response parameters */
0251     rsp_params = (struct dpsw_rsp_get_irq_status *)cmd.params;
0252     *status = le32_to_cpu(rsp_params->status);
0253 
0254     return 0;
0255 }
0256 
0257 /**
0258  * dpsw_clear_irq_status() - Clear a pending interrupt's status
0259  * @mc_io:  Pointer to MC portal's I/O object
0260  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0261  * @token:  Token of DPCI object
0262  * @irq_index:  The interrupt index to configure
0263  * @status: bits to clear (W1C) - one bit per cause:
0264  *          0 = don't change
0265  *          1 = clear status bit
0266  *
0267  * Return:  '0' on Success; Error code otherwise.
0268  */
0269 int dpsw_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0270               u8 irq_index, u32 status)
0271 {
0272     struct fsl_mc_command cmd = { 0 };
0273     struct dpsw_cmd_clear_irq_status *cmd_params;
0274 
0275     /* prepare command */
0276     cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLEAR_IRQ_STATUS,
0277                       cmd_flags,
0278                       token);
0279     cmd_params = (struct dpsw_cmd_clear_irq_status *)cmd.params;
0280     cmd_params->status = cpu_to_le32(status);
0281     cmd_params->irq_index = irq_index;
0282 
0283     /* send command to mc*/
0284     return mc_send_command(mc_io, &cmd);
0285 }
0286 
0287 /**
0288  * dpsw_get_attributes() - Retrieve DPSW attributes
0289  * @mc_io:  Pointer to MC portal's I/O object
0290  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0291  * @token:  Token of DPSW object
0292  * @attr:   Returned DPSW attributes
0293  *
0294  * Return:  Completion status. '0' on Success; Error code otherwise.
0295  */
0296 int dpsw_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0297             struct dpsw_attr *attr)
0298 {
0299     struct fsl_mc_command cmd = { 0 };
0300     struct dpsw_rsp_get_attr *rsp_params;
0301     int err;
0302 
0303     /* prepare command */
0304     cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_ATTR,
0305                       cmd_flags,
0306                       token);
0307 
0308     /* send command to mc*/
0309     err = mc_send_command(mc_io, &cmd);
0310     if (err)
0311         return err;
0312 
0313     /* retrieve response parameters */
0314     rsp_params = (struct dpsw_rsp_get_attr *)cmd.params;
0315     attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
0316     attr->max_fdbs = rsp_params->max_fdbs;
0317     attr->num_fdbs = rsp_params->num_fdbs;
0318     attr->max_vlans = le16_to_cpu(rsp_params->max_vlans);
0319     attr->num_vlans = le16_to_cpu(rsp_params->num_vlans);
0320     attr->max_fdb_entries = le16_to_cpu(rsp_params->max_fdb_entries);
0321     attr->fdb_aging_time = le16_to_cpu(rsp_params->fdb_aging_time);
0322     attr->id = le32_to_cpu(rsp_params->dpsw_id);
0323     attr->mem_size = le16_to_cpu(rsp_params->mem_size);
0324     attr->max_fdb_mc_groups = le16_to_cpu(rsp_params->max_fdb_mc_groups);
0325     attr->max_meters_per_if = rsp_params->max_meters_per_if;
0326     attr->options = le64_to_cpu(rsp_params->options);
0327     attr->component_type = dpsw_get_field(rsp_params->component_type, COMPONENT_TYPE);
0328     attr->flooding_cfg = dpsw_get_field(rsp_params->repl_cfg, FLOODING_CFG);
0329     attr->broadcast_cfg = dpsw_get_field(rsp_params->repl_cfg, BROADCAST_CFG);
0330     return 0;
0331 }
0332 
0333 /**
0334  * dpsw_if_set_link_cfg() - Set the link configuration.
0335  * @mc_io:  Pointer to MC portal's I/O object
0336  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0337  * @token:  Token of DPSW object
0338  * @if_id:  Interface id
0339  * @cfg:    Link configuration
0340  *
0341  * Return:  '0' on Success; Error code otherwise.
0342  */
0343 int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
0344              struct dpsw_link_cfg *cfg)
0345 {
0346     struct fsl_mc_command cmd = { 0 };
0347     struct dpsw_cmd_if_set_link_cfg *cmd_params;
0348 
0349     /* prepare command */
0350     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LINK_CFG,
0351                       cmd_flags,
0352                       token);
0353     cmd_params = (struct dpsw_cmd_if_set_link_cfg *)cmd.params;
0354     cmd_params->if_id = cpu_to_le16(if_id);
0355     cmd_params->rate = cpu_to_le32(cfg->rate);
0356     cmd_params->options = cpu_to_le64(cfg->options);
0357 
0358     /* send command to mc*/
0359     return mc_send_command(mc_io, &cmd);
0360 }
0361 
0362 /**
0363  * dpsw_if_get_link_state - Return the link state
0364  * @mc_io:  Pointer to MC portal's I/O object
0365  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0366  * @token:  Token of DPSW object
0367  * @if_id:  Interface id
0368  * @state:  Link state  1 - linkup, 0 - link down or disconnected
0369  *
0370  * Return:  '0' on Success; Error code otherwise.
0371  */
0372 int dpsw_if_get_link_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0373                u16 if_id, struct dpsw_link_state *state)
0374 {
0375     struct fsl_mc_command cmd = { 0 };
0376     struct dpsw_cmd_if_get_link_state *cmd_params;
0377     struct dpsw_rsp_if_get_link_state *rsp_params;
0378     int err;
0379 
0380     /* prepare command */
0381     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_LINK_STATE,
0382                       cmd_flags,
0383                       token);
0384     cmd_params = (struct dpsw_cmd_if_get_link_state *)cmd.params;
0385     cmd_params->if_id = cpu_to_le16(if_id);
0386 
0387     /* send command to mc*/
0388     err = mc_send_command(mc_io, &cmd);
0389     if (err)
0390         return err;
0391 
0392     /* retrieve response parameters */
0393     rsp_params = (struct dpsw_rsp_if_get_link_state *)cmd.params;
0394     state->rate = le32_to_cpu(rsp_params->rate);
0395     state->options = le64_to_cpu(rsp_params->options);
0396     state->up = dpsw_get_field(rsp_params->up, UP);
0397 
0398     return 0;
0399 }
0400 
0401 /**
0402  * dpsw_if_set_tci() - Set default VLAN Tag Control Information (TCI)
0403  * @mc_io:  Pointer to MC portal's I/O object
0404  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0405  * @token:  Token of DPSW object
0406  * @if_id:  Interface Identifier
0407  * @cfg:    Tag Control Information Configuration
0408  *
0409  * Return:  Completion status. '0' on Success; Error code otherwise.
0410  */
0411 int dpsw_if_set_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
0412             const struct dpsw_tci_cfg *cfg)
0413 {
0414     struct fsl_mc_command cmd = { 0 };
0415     struct dpsw_cmd_if_set_tci *cmd_params;
0416     u16 tmp_conf = 0;
0417 
0418     /* prepare command */
0419     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_TCI,
0420                       cmd_flags,
0421                       token);
0422     cmd_params = (struct dpsw_cmd_if_set_tci *)cmd.params;
0423     cmd_params->if_id = cpu_to_le16(if_id);
0424     dpsw_set_field(tmp_conf, VLAN_ID, cfg->vlan_id);
0425     dpsw_set_field(tmp_conf, DEI, cfg->dei);
0426     dpsw_set_field(tmp_conf, PCP, cfg->pcp);
0427     cmd_params->conf = cpu_to_le16(tmp_conf);
0428 
0429     /* send command to mc*/
0430     return mc_send_command(mc_io, &cmd);
0431 }
0432 
0433 /**
0434  * dpsw_if_get_tci() - Get default VLAN Tag Control Information (TCI)
0435  * @mc_io:  Pointer to MC portal's I/O object
0436  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0437  * @token:  Token of DPSW object
0438  * @if_id:  Interface Identifier
0439  * @cfg:    Tag Control Information Configuration
0440  *
0441  * Return:  Completion status. '0' on Success; Error code otherwise.
0442  */
0443 int dpsw_if_get_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
0444             struct dpsw_tci_cfg *cfg)
0445 {
0446     struct fsl_mc_command cmd = { 0 };
0447     struct dpsw_cmd_if_get_tci *cmd_params;
0448     struct dpsw_rsp_if_get_tci *rsp_params;
0449     int err;
0450 
0451     /* prepare command */
0452     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_TCI,
0453                       cmd_flags,
0454                       token);
0455     cmd_params = (struct dpsw_cmd_if_get_tci *)cmd.params;
0456     cmd_params->if_id = cpu_to_le16(if_id);
0457 
0458     /* send command to mc*/
0459     err = mc_send_command(mc_io, &cmd);
0460     if (err)
0461         return err;
0462 
0463     /* retrieve response parameters */
0464     rsp_params = (struct dpsw_rsp_if_get_tci *)cmd.params;
0465     cfg->pcp = rsp_params->pcp;
0466     cfg->dei = rsp_params->dei;
0467     cfg->vlan_id = le16_to_cpu(rsp_params->vlan_id);
0468 
0469     return 0;
0470 }
0471 
0472 /**
0473  * dpsw_if_set_stp() - Function sets Spanning Tree Protocol (STP) state.
0474  * @mc_io:  Pointer to MC portal's I/O object
0475  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0476  * @token:  Token of DPSW object
0477  * @if_id:  Interface Identifier
0478  * @cfg:    STP State configuration parameters
0479  *
0480  * The following STP states are supported -
0481  * blocking, listening, learning, forwarding and disabled.
0482  *
0483  * Return:  Completion status. '0' on Success; Error code otherwise.
0484  */
0485 int dpsw_if_set_stp(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
0486             const struct dpsw_stp_cfg *cfg)
0487 {
0488     struct fsl_mc_command cmd = { 0 };
0489     struct dpsw_cmd_if_set_stp *cmd_params;
0490 
0491     /* prepare command */
0492     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_STP,
0493                       cmd_flags,
0494                       token);
0495     cmd_params = (struct dpsw_cmd_if_set_stp *)cmd.params;
0496     cmd_params->if_id = cpu_to_le16(if_id);
0497     cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
0498     dpsw_set_field(cmd_params->state, STATE, cfg->state);
0499 
0500     /* send command to mc*/
0501     return mc_send_command(mc_io, &cmd);
0502 }
0503 
0504 /**
0505  * dpsw_if_get_counter() - Get specific counter of particular interface
0506  * @mc_io:  Pointer to MC portal's I/O object
0507  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0508  * @token:  Token of DPSW object
0509  * @if_id:  Interface Identifier
0510  * @type:   Counter type
0511  * @counter:    return value
0512  *
0513  * Return:  Completion status. '0' on Success; Error code otherwise.
0514  */
0515 int dpsw_if_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0516             u16 if_id, enum dpsw_counter type, u64 *counter)
0517 {
0518     struct fsl_mc_command cmd = { 0 };
0519     struct dpsw_cmd_if_get_counter *cmd_params;
0520     struct dpsw_rsp_if_get_counter *rsp_params;
0521     int err;
0522 
0523     /* prepare command */
0524     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_COUNTER,
0525                       cmd_flags,
0526                       token);
0527     cmd_params = (struct dpsw_cmd_if_get_counter *)cmd.params;
0528     cmd_params->if_id = cpu_to_le16(if_id);
0529     dpsw_set_field(cmd_params->type, COUNTER_TYPE, type);
0530 
0531     /* send command to mc*/
0532     err = mc_send_command(mc_io, &cmd);
0533     if (err)
0534         return err;
0535 
0536     /* retrieve response parameters */
0537     rsp_params = (struct dpsw_rsp_if_get_counter *)cmd.params;
0538     *counter = le64_to_cpu(rsp_params->counter);
0539 
0540     return 0;
0541 }
0542 
0543 /**
0544  * dpsw_if_enable() - Enable Interface
0545  * @mc_io:  Pointer to MC portal's I/O object
0546  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0547  * @token:  Token of DPSW object
0548  * @if_id:  Interface Identifier
0549  *
0550  * Return:  Completion status. '0' on Success; Error code otherwise.
0551  */
0552 int dpsw_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
0553 {
0554     struct fsl_mc_command cmd = { 0 };
0555     struct dpsw_cmd_if *cmd_params;
0556 
0557     /* prepare command */
0558     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ENABLE,
0559                       cmd_flags,
0560                       token);
0561     cmd_params = (struct dpsw_cmd_if *)cmd.params;
0562     cmd_params->if_id = cpu_to_le16(if_id);
0563 
0564     /* send command to mc*/
0565     return mc_send_command(mc_io, &cmd);
0566 }
0567 
0568 /**
0569  * dpsw_if_disable() - Disable Interface
0570  * @mc_io:  Pointer to MC portal's I/O object
0571  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0572  * @token:  Token of DPSW object
0573  * @if_id:  Interface Identifier
0574  *
0575  * Return:  Completion status. '0' on Success; Error code otherwise.
0576  */
0577 int dpsw_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
0578 {
0579     struct fsl_mc_command cmd = { 0 };
0580     struct dpsw_cmd_if *cmd_params;
0581 
0582     /* prepare command */
0583     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_DISABLE,
0584                       cmd_flags,
0585                       token);
0586     cmd_params = (struct dpsw_cmd_if *)cmd.params;
0587     cmd_params->if_id = cpu_to_le16(if_id);
0588 
0589     /* send command to mc*/
0590     return mc_send_command(mc_io, &cmd);
0591 }
0592 
0593 /**
0594  * dpsw_if_get_attributes() - Function obtains attributes of interface
0595  * @mc_io:  Pointer to MC portal's I/O object
0596  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0597  * @token:  Token of DPSW object
0598  * @if_id:  Interface Identifier
0599  * @attr:   Returned interface attributes
0600  *
0601  * Return:  Completion status. '0' on Success; Error code otherwise.
0602  */
0603 int dpsw_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0604                u16 if_id, struct dpsw_if_attr *attr)
0605 {
0606     struct dpsw_rsp_if_get_attr *rsp_params;
0607     struct fsl_mc_command cmd = { 0 };
0608     struct dpsw_cmd_if *cmd_params;
0609     int err;
0610 
0611     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_ATTR, cmd_flags,
0612                       token);
0613     cmd_params = (struct dpsw_cmd_if *)cmd.params;
0614     cmd_params->if_id = cpu_to_le16(if_id);
0615 
0616     err = mc_send_command(mc_io, &cmd);
0617     if (err)
0618         return err;
0619 
0620     rsp_params = (struct dpsw_rsp_if_get_attr *)cmd.params;
0621     attr->num_tcs = rsp_params->num_tcs;
0622     attr->rate = le32_to_cpu(rsp_params->rate);
0623     attr->options = le32_to_cpu(rsp_params->options);
0624     attr->qdid = le16_to_cpu(rsp_params->qdid);
0625     attr->enabled = dpsw_get_field(rsp_params->conf, ENABLED);
0626     attr->accept_all_vlan = dpsw_get_field(rsp_params->conf,
0627                            ACCEPT_ALL_VLAN);
0628     attr->admit_untagged = dpsw_get_field(rsp_params->conf,
0629                           ADMIT_UNTAGGED);
0630 
0631     return 0;
0632 }
0633 
0634 /**
0635  * dpsw_if_set_max_frame_length() - Set Maximum Receive frame length.
0636  * @mc_io:      Pointer to MC portal's I/O object
0637  * @cmd_flags:      Command flags; one or more of 'MC_CMD_FLAG_'
0638  * @token:      Token of DPSW object
0639  * @if_id:      Interface Identifier
0640  * @frame_length:   Maximum Frame Length
0641  *
0642  * Return:  Completion status. '0' on Success; Error code otherwise.
0643  */
0644 int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0645                  u16 if_id, u16 frame_length)
0646 {
0647     struct fsl_mc_command cmd = { 0 };
0648     struct dpsw_cmd_if_set_max_frame_length *cmd_params;
0649 
0650     /* prepare command */
0651     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_MAX_FRAME_LENGTH,
0652                       cmd_flags,
0653                       token);
0654     cmd_params = (struct dpsw_cmd_if_set_max_frame_length *)cmd.params;
0655     cmd_params->if_id = cpu_to_le16(if_id);
0656     cmd_params->frame_length = cpu_to_le16(frame_length);
0657 
0658     /* send command to mc*/
0659     return mc_send_command(mc_io, &cmd);
0660 }
0661 
0662 /**
0663  * dpsw_vlan_add() - Adding new VLAN to DPSW.
0664  * @mc_io:  Pointer to MC portal's I/O object
0665  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0666  * @token:  Token of DPSW object
0667  * @vlan_id:    VLAN Identifier
0668  * @cfg:    VLAN configuration
0669  *
0670  * Only VLAN ID and FDB ID are required parameters here.
0671  * 12 bit VLAN ID is defined in IEEE802.1Q.
0672  * Adding a duplicate VLAN ID is not allowed.
0673  * FDB ID can be shared across multiple VLANs. Shared learning
0674  * is obtained by calling dpsw_vlan_add for multiple VLAN IDs
0675  * with same fdb_id
0676  *
0677  * Return:  Completion status. '0' on Success; Error code otherwise.
0678  */
0679 int dpsw_vlan_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0680           u16 vlan_id, const struct dpsw_vlan_cfg *cfg)
0681 {
0682     struct fsl_mc_command cmd = { 0 };
0683     struct dpsw_vlan_add *cmd_params;
0684 
0685     /* prepare command */
0686     cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD,
0687                       cmd_flags,
0688                       token);
0689     cmd_params = (struct dpsw_vlan_add *)cmd.params;
0690     cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
0691     cmd_params->vlan_id = cpu_to_le16(vlan_id);
0692 
0693     /* send command to mc*/
0694     return mc_send_command(mc_io, &cmd);
0695 }
0696 
0697 /**
0698  * dpsw_vlan_add_if() - Adding a set of interfaces to an existing VLAN.
0699  * @mc_io:  Pointer to MC portal's I/O object
0700  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0701  * @token:  Token of DPSW object
0702  * @vlan_id:    VLAN Identifier
0703  * @cfg:    Set of interfaces to add
0704  *
0705  * It adds only interfaces not belonging to this VLAN yet,
0706  * otherwise an error is generated and an entire command is
0707  * ignored. This function can be called numerous times always
0708  * providing required interfaces delta.
0709  *
0710  * Return:  Completion status. '0' on Success; Error code otherwise.
0711  */
0712 int dpsw_vlan_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0713              u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
0714 {
0715     struct dpsw_cmd_vlan_add_if *cmd_params;
0716     struct fsl_mc_command cmd = { 0 };
0717 
0718     /* prepare command */
0719     cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF,
0720                       cmd_flags,
0721                       token);
0722     cmd_params = (struct dpsw_cmd_vlan_add_if *)cmd.params;
0723     cmd_params->vlan_id = cpu_to_le16(vlan_id);
0724     cmd_params->options = cpu_to_le16(cfg->options);
0725     cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
0726     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
0727 
0728     /* send command to mc*/
0729     return mc_send_command(mc_io, &cmd);
0730 }
0731 
0732 /**
0733  * dpsw_vlan_add_if_untagged() - Defining a set of interfaces that should be
0734  *              transmitted as untagged.
0735  * @mc_io:  Pointer to MC portal's I/O object
0736  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0737  * @token:  Token of DPSW object
0738  * @vlan_id:    VLAN Identifier
0739  * @cfg:    Set of interfaces that should be transmitted as untagged
0740  *
0741  * These interfaces should already belong to this VLAN.
0742  * By default all interfaces are transmitted as tagged.
0743  * Providing un-existing interface or untagged interface that is
0744  * configured untagged already generates an error and the entire
0745  * command is ignored.
0746  *
0747  * Return:  Completion status. '0' on Success; Error code otherwise.
0748  */
0749 int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0750                   u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
0751 {
0752     struct fsl_mc_command cmd = { 0 };
0753     struct dpsw_cmd_vlan_manage_if *cmd_params;
0754 
0755     /* prepare command */
0756     cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF_UNTAGGED,
0757                       cmd_flags,
0758                       token);
0759     cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
0760     cmd_params->vlan_id = cpu_to_le16(vlan_id);
0761     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
0762 
0763     /* send command to mc*/
0764     return mc_send_command(mc_io, &cmd);
0765 }
0766 
0767 /**
0768  * dpsw_vlan_remove_if() - Remove interfaces from an existing VLAN.
0769  * @mc_io:  Pointer to MC portal's I/O object
0770  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0771  * @token:  Token of DPSW object
0772  * @vlan_id:    VLAN Identifier
0773  * @cfg:    Set of interfaces that should be removed
0774  *
0775  * Interfaces must belong to this VLAN, otherwise an error
0776  * is returned and an the command is ignored
0777  *
0778  * Return:  Completion status. '0' on Success; Error code otherwise.
0779  */
0780 int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0781             u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
0782 {
0783     struct fsl_mc_command cmd = { 0 };
0784     struct dpsw_cmd_vlan_manage_if *cmd_params;
0785 
0786     /* prepare command */
0787     cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF,
0788                       cmd_flags,
0789                       token);
0790     cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
0791     cmd_params->vlan_id = cpu_to_le16(vlan_id);
0792     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
0793 
0794     /* send command to mc*/
0795     return mc_send_command(mc_io, &cmd);
0796 }
0797 
0798 /**
0799  * dpsw_vlan_remove_if_untagged() - Define a set of interfaces that should be
0800  *      converted from transmitted as untagged to transmit as tagged.
0801  * @mc_io:  Pointer to MC portal's I/O object
0802  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0803  * @token:  Token of DPSW object
0804  * @vlan_id:    VLAN Identifier
0805  * @cfg:    Set of interfaces that should be removed
0806  *
0807  * Interfaces provided by API have to belong to this VLAN and
0808  * configured untagged, otherwise an error is returned and the
0809  * command is ignored
0810  *
0811  * Return:  Completion status. '0' on Success; Error code otherwise.
0812  */
0813 int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0814                  u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
0815 {
0816     struct fsl_mc_command cmd = { 0 };
0817     struct dpsw_cmd_vlan_manage_if *cmd_params;
0818 
0819     /* prepare command */
0820     cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF_UNTAGGED,
0821                       cmd_flags,
0822                       token);
0823     cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
0824     cmd_params->vlan_id = cpu_to_le16(vlan_id);
0825     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
0826 
0827     /* send command to mc*/
0828     return mc_send_command(mc_io, &cmd);
0829 }
0830 
0831 /**
0832  * dpsw_vlan_remove() - Remove an entire VLAN
0833  * @mc_io:  Pointer to MC portal's I/O object
0834  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0835  * @token:  Token of DPSW object
0836  * @vlan_id:    VLAN Identifier
0837  *
0838  * Return:  Completion status. '0' on Success; Error code otherwise.
0839  */
0840 int dpsw_vlan_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0841              u16 vlan_id)
0842 {
0843     struct fsl_mc_command cmd = { 0 };
0844     struct dpsw_cmd_vlan_remove *cmd_params;
0845 
0846     /* prepare command */
0847     cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE,
0848                       cmd_flags,
0849                       token);
0850     cmd_params = (struct dpsw_cmd_vlan_remove *)cmd.params;
0851     cmd_params->vlan_id = cpu_to_le16(vlan_id);
0852 
0853     /* send command to mc*/
0854     return mc_send_command(mc_io, &cmd);
0855 }
0856 
0857 /**
0858  * dpsw_fdb_add() - Add FDB to switch and Returns handle to FDB table for
0859  *      the reference
0860  * @mc_io:  Pointer to MC portal's I/O object
0861  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0862  * @token:  Token of DPSW object
0863  * @fdb_id: Returned Forwarding Database Identifier
0864  * @cfg:    FDB Configuration
0865  *
0866  * Return:  Completion status. '0' on Success; Error code otherwise.
0867  */
0868 int dpsw_fdb_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *fdb_id,
0869          const struct dpsw_fdb_cfg *cfg)
0870 {
0871     struct dpsw_cmd_fdb_add *cmd_params;
0872     struct dpsw_rsp_fdb_add *rsp_params;
0873     struct fsl_mc_command cmd = { 0 };
0874     int err;
0875 
0876     cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD,
0877                       cmd_flags,
0878                       token);
0879     cmd_params = (struct dpsw_cmd_fdb_add *)cmd.params;
0880     cmd_params->fdb_ageing_time = cpu_to_le16(cfg->fdb_ageing_time);
0881     cmd_params->num_fdb_entries = cpu_to_le16(cfg->num_fdb_entries);
0882 
0883     err = mc_send_command(mc_io, &cmd);
0884     if (err)
0885         return err;
0886 
0887     rsp_params = (struct dpsw_rsp_fdb_add *)cmd.params;
0888     *fdb_id = le16_to_cpu(rsp_params->fdb_id);
0889 
0890     return 0;
0891 }
0892 
0893 /**
0894  * dpsw_fdb_remove() - Remove FDB from switch
0895  * @mc_io:  Pointer to MC portal's I/O object
0896  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0897  * @token:  Token of DPSW object
0898  * @fdb_id: Forwarding Database Identifier
0899  *
0900  * Return:  Completion status. '0' on Success; Error code otherwise.
0901  */
0902 int dpsw_fdb_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id)
0903 {
0904     struct dpsw_cmd_fdb_remove *cmd_params;
0905     struct fsl_mc_command cmd = { 0 };
0906 
0907     /* prepare command */
0908     cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE,
0909                       cmd_flags,
0910                       token);
0911     cmd_params = (struct dpsw_cmd_fdb_remove *)cmd.params;
0912     cmd_params->fdb_id = cpu_to_le16(fdb_id);
0913 
0914     return mc_send_command(mc_io, &cmd);
0915 }
0916 
0917 /**
0918  * dpsw_fdb_add_unicast() - Function adds an unicast entry into MAC lookup table
0919  * @mc_io:  Pointer to MC portal's I/O object
0920  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0921  * @token:  Token of DPSW object
0922  * @fdb_id: Forwarding Database Identifier
0923  * @cfg:    Unicast entry configuration
0924  *
0925  * Return:  Completion status. '0' on Success; Error code otherwise.
0926  */
0927 int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0928              u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
0929 {
0930     struct fsl_mc_command cmd = { 0 };
0931     struct dpsw_cmd_fdb_unicast_op *cmd_params;
0932     int i;
0933 
0934     /* prepare command */
0935     cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_UNICAST,
0936                       cmd_flags,
0937                       token);
0938     cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
0939     cmd_params->fdb_id = cpu_to_le16(fdb_id);
0940     cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
0941     for (i = 0; i < 6; i++)
0942         cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
0943     dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
0944 
0945     /* send command to mc*/
0946     return mc_send_command(mc_io, &cmd);
0947 }
0948 
0949 /**
0950  * dpsw_fdb_dump() - Dump the content of FDB table into memory.
0951  * @mc_io:  Pointer to MC portal's I/O object
0952  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0953  * @token:  Token of DPSW object
0954  * @fdb_id: Forwarding Database Identifier
0955  * @iova_addr:  Data will be stored here as an array of struct fdb_dump_entry
0956  * @iova_size:  Memory size allocated at iova_addr
0957  * @num_entries:Number of entries written at iova_addr
0958  *
0959  * Return:  Completion status. '0' on Success; Error code otherwise.
0960  *
0961  * The memory allocated at iova_addr must be initialized with zero before
0962  * command execution. If the FDB table does not fit into memory MC will stop
0963  * after the memory is filled up.
0964  * The struct fdb_dump_entry array must be parsed until the end of memory
0965  * area or until an entry with mac_addr set to zero is found.
0966  */
0967 int dpsw_fdb_dump(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id,
0968           u64 iova_addr, u32 iova_size, u16 *num_entries)
0969 {
0970     struct dpsw_cmd_fdb_dump *cmd_params;
0971     struct dpsw_rsp_fdb_dump *rsp_params;
0972     struct fsl_mc_command cmd = { 0 };
0973     int err;
0974 
0975     /* prepare command */
0976     cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_DUMP,
0977                       cmd_flags,
0978                       token);
0979     cmd_params = (struct dpsw_cmd_fdb_dump *)cmd.params;
0980     cmd_params->fdb_id = cpu_to_le16(fdb_id);
0981     cmd_params->iova_addr = cpu_to_le64(iova_addr);
0982     cmd_params->iova_size = cpu_to_le32(iova_size);
0983 
0984     /* send command to mc */
0985     err = mc_send_command(mc_io, &cmd);
0986     if (err)
0987         return err;
0988 
0989     rsp_params = (struct dpsw_rsp_fdb_dump *)cmd.params;
0990     *num_entries = le16_to_cpu(rsp_params->num_entries);
0991 
0992     return 0;
0993 }
0994 
0995 /**
0996  * dpsw_fdb_remove_unicast() - removes an entry from MAC lookup table
0997  * @mc_io:  Pointer to MC portal's I/O object
0998  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0999  * @token:  Token of DPSW object
1000  * @fdb_id: Forwarding Database Identifier
1001  * @cfg:    Unicast entry configuration
1002  *
1003  * Return:  Completion status. '0' on Success; Error code otherwise.
1004  */
1005 int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1006                 u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
1007 {
1008     struct fsl_mc_command cmd = { 0 };
1009     struct dpsw_cmd_fdb_unicast_op *cmd_params;
1010     int i;
1011 
1012     /* prepare command */
1013     cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_UNICAST,
1014                       cmd_flags,
1015                       token);
1016     cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
1017     cmd_params->fdb_id = cpu_to_le16(fdb_id);
1018     for (i = 0; i < 6; i++)
1019         cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1020     cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
1021     dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
1022 
1023     /* send command to mc*/
1024     return mc_send_command(mc_io, &cmd);
1025 }
1026 
1027 /**
1028  * dpsw_fdb_add_multicast() - Add a set of egress interfaces to multi-cast group
1029  * @mc_io:  Pointer to MC portal's I/O object
1030  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1031  * @token:  Token of DPSW object
1032  * @fdb_id: Forwarding Database Identifier
1033  * @cfg:    Multicast entry configuration
1034  *
1035  * If group doesn't exist, it will be created.
1036  * It adds only interfaces not belonging to this multicast group
1037  * yet, otherwise error will be generated and the command is
1038  * ignored.
1039  * This function may be called numerous times always providing
1040  * required interfaces delta.
1041  *
1042  * Return:  Completion status. '0' on Success; Error code otherwise.
1043  */
1044 int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1045                u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
1046 {
1047     struct fsl_mc_command cmd = { 0 };
1048     struct dpsw_cmd_fdb_multicast_op *cmd_params;
1049     int i;
1050 
1051     /* prepare command */
1052     cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_MULTICAST,
1053                       cmd_flags,
1054                       token);
1055     cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
1056     cmd_params->fdb_id = cpu_to_le16(fdb_id);
1057     cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1058     dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
1059     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1060     for (i = 0; i < 6; i++)
1061         cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1062 
1063     /* send command to mc*/
1064     return mc_send_command(mc_io, &cmd);
1065 }
1066 
1067 /**
1068  * dpsw_fdb_remove_multicast() - Removing interfaces from an existing multicast
1069  *              group.
1070  * @mc_io:  Pointer to MC portal's I/O object
1071  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1072  * @token:  Token of DPSW object
1073  * @fdb_id: Forwarding Database Identifier
1074  * @cfg:    Multicast entry configuration
1075  *
1076  * Interfaces provided by this API have to exist in the group,
1077  * otherwise an error will be returned and an entire command
1078  * ignored. If there is no interface left in the group,
1079  * an entire group is deleted
1080  *
1081  * Return:  Completion status. '0' on Success; Error code otherwise.
1082  */
1083 int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1084                   u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
1085 {
1086     struct fsl_mc_command cmd = { 0 };
1087     struct dpsw_cmd_fdb_multicast_op *cmd_params;
1088     int i;
1089 
1090     /* prepare command */
1091     cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_MULTICAST,
1092                       cmd_flags,
1093                       token);
1094     cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
1095     cmd_params->fdb_id = cpu_to_le16(fdb_id);
1096     cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1097     dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
1098     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1099     for (i = 0; i < 6; i++)
1100         cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1101 
1102     /* send command to mc*/
1103     return mc_send_command(mc_io, &cmd);
1104 }
1105 
1106 /**
1107  * dpsw_ctrl_if_get_attributes() - Obtain control interface attributes
1108  * @mc_io:  Pointer to MC portal's I/O object
1109  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1110  * @token:  Token of DPSW object
1111  * @attr:   Returned control interface attributes
1112  *
1113  * Return:  '0' on Success; Error code otherwise.
1114  */
1115 int dpsw_ctrl_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
1116                 u16 token, struct dpsw_ctrl_if_attr *attr)
1117 {
1118     struct dpsw_rsp_ctrl_if_get_attr *rsp_params;
1119     struct fsl_mc_command cmd = { 0 };
1120     int err;
1121 
1122     cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_GET_ATTR,
1123                       cmd_flags, token);
1124 
1125     err = mc_send_command(mc_io, &cmd);
1126     if (err)
1127         return err;
1128 
1129     rsp_params = (struct dpsw_rsp_ctrl_if_get_attr *)cmd.params;
1130     attr->rx_fqid = le32_to_cpu(rsp_params->rx_fqid);
1131     attr->rx_err_fqid = le32_to_cpu(rsp_params->rx_err_fqid);
1132     attr->tx_err_conf_fqid = le32_to_cpu(rsp_params->tx_err_conf_fqid);
1133 
1134     return 0;
1135 }
1136 
1137 /**
1138  * dpsw_ctrl_if_set_pools() - Set control interface buffer pools
1139  * @mc_io:  Pointer to MC portal's I/O object
1140  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1141  * @token:  Token of DPSW object
1142  * @cfg:    Buffer pools configuration
1143  *
1144  * Return:  '0' on Success; Error code otherwise.
1145  */
1146 int dpsw_ctrl_if_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1147                const struct dpsw_ctrl_if_pools_cfg *cfg)
1148 {
1149     struct dpsw_cmd_ctrl_if_set_pools *cmd_params;
1150     struct fsl_mc_command cmd = { 0 };
1151     int i;
1152 
1153     cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_POOLS,
1154                       cmd_flags, token);
1155     cmd_params = (struct dpsw_cmd_ctrl_if_set_pools *)cmd.params;
1156     cmd_params->num_dpbp = cfg->num_dpbp;
1157     for (i = 0; i < DPSW_MAX_DPBP; i++) {
1158         cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
1159         cmd_params->buffer_size[i] =
1160             cpu_to_le16(cfg->pools[i].buffer_size);
1161         cmd_params->backup_pool_mask |=
1162             DPSW_BACKUP_POOL(cfg->pools[i].backup_pool, i);
1163     }
1164 
1165     return mc_send_command(mc_io, &cmd);
1166 }
1167 
1168 /**
1169  * dpsw_ctrl_if_set_queue() - Set Rx queue configuration
1170  * @mc_io:  Pointer to MC portal's I/O object
1171  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1172  * @token:  Token of dpsw object
1173  * @qtype:  dpsw_queue_type of the targeted queue
1174  * @cfg:    Rx queue configuration
1175  *
1176  * Return:  '0' on Success; Error code otherwise.
1177  */
1178 int dpsw_ctrl_if_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1179                enum dpsw_queue_type qtype,
1180                const struct dpsw_ctrl_if_queue_cfg *cfg)
1181 {
1182     struct dpsw_cmd_ctrl_if_set_queue *cmd_params;
1183     struct fsl_mc_command cmd = { 0 };
1184 
1185     cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_QUEUE,
1186                       cmd_flags,
1187                       token);
1188     cmd_params = (struct dpsw_cmd_ctrl_if_set_queue *)cmd.params;
1189     cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1190     cmd_params->dest_priority = cfg->dest_cfg.priority;
1191     cmd_params->qtype = qtype;
1192     cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
1193     cmd_params->options = cpu_to_le32(cfg->options);
1194     dpsw_set_field(cmd_params->dest_type,
1195                DEST_TYPE,
1196                cfg->dest_cfg.dest_type);
1197 
1198     return mc_send_command(mc_io, &cmd);
1199 }
1200 
1201 /**
1202  * dpsw_get_api_version() - Get Data Path Switch API version
1203  * @mc_io:  Pointer to MC portal's I/O object
1204  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1205  * @major_ver:  Major version of data path switch API
1206  * @minor_ver:  Minor version of data path switch API
1207  *
1208  * Return:  '0' on Success; Error code otherwise.
1209  */
1210 int dpsw_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
1211              u16 *major_ver, u16 *minor_ver)
1212 {
1213     struct fsl_mc_command cmd = { 0 };
1214     struct dpsw_rsp_get_api_version *rsp_params;
1215     int err;
1216 
1217     cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_API_VERSION,
1218                       cmd_flags,
1219                       0);
1220 
1221     err = mc_send_command(mc_io, &cmd);
1222     if (err)
1223         return err;
1224 
1225     rsp_params = (struct dpsw_rsp_get_api_version *)cmd.params;
1226     *major_ver = le16_to_cpu(rsp_params->version_major);
1227     *minor_ver = le16_to_cpu(rsp_params->version_minor);
1228 
1229     return 0;
1230 }
1231 
1232 /**
1233  * dpsw_if_get_port_mac_addr() - Retrieve MAC address associated to the physical port
1234  * @mc_io:  Pointer to MC portal's I/O object
1235  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1236  * @token:  Token of DPSW object
1237  * @if_id:  Interface Identifier
1238  * @mac_addr:   MAC address of the physical port, if any, otherwise 0
1239  *
1240  * Return:  Completion status. '0' on Success; Error code otherwise.
1241  */
1242 int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1243                   u16 if_id, u8 mac_addr[6])
1244 {
1245     struct dpsw_rsp_if_get_mac_addr *rsp_params;
1246     struct fsl_mc_command cmd = { 0 };
1247     struct dpsw_cmd_if *cmd_params;
1248     int err, i;
1249 
1250     /* prepare command */
1251     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_PORT_MAC_ADDR,
1252                       cmd_flags,
1253                       token);
1254     cmd_params = (struct dpsw_cmd_if *)cmd.params;
1255     cmd_params->if_id = cpu_to_le16(if_id);
1256 
1257     /* send command to mc*/
1258     err = mc_send_command(mc_io, &cmd);
1259     if (err)
1260         return err;
1261 
1262     /* retrieve response parameters */
1263     rsp_params = (struct dpsw_rsp_if_get_mac_addr *)cmd.params;
1264     for (i = 0; i < 6; i++)
1265         mac_addr[5 - i] = rsp_params->mac_addr[i];
1266 
1267     return 0;
1268 }
1269 
1270 /**
1271  * dpsw_ctrl_if_enable() - Enable control interface
1272  * @mc_io:  Pointer to MC portal's I/O object
1273  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1274  * @token:  Token of DPSW object
1275  *
1276  * Return:  '0' on Success; Error code otherwise.
1277  */
1278 int dpsw_ctrl_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
1279 {
1280     struct fsl_mc_command cmd = { 0 };
1281 
1282     cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_ENABLE, cmd_flags,
1283                       token);
1284 
1285     return mc_send_command(mc_io, &cmd);
1286 }
1287 
1288 /**
1289  * dpsw_ctrl_if_disable() - Function disables control interface
1290  * @mc_io:  Pointer to MC portal's I/O object
1291  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1292  * @token:  Token of DPSW object
1293  *
1294  * Return:  '0' on Success; Error code otherwise.
1295  */
1296 int dpsw_ctrl_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
1297 {
1298     struct fsl_mc_command cmd = { 0 };
1299 
1300     cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_DISABLE,
1301                       cmd_flags,
1302                       token);
1303 
1304     return mc_send_command(mc_io, &cmd);
1305 }
1306 
1307 /**
1308  * dpsw_set_egress_flood() - Set egress parameters associated with an FDB ID
1309  * @mc_io:  Pointer to MC portal's I/O object
1310  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1311  * @token:  Token of DPSW object
1312  * @cfg:    Egress flooding configuration
1313  *
1314  * Return:  '0' on Success; Error code otherwise.
1315  */
1316 int dpsw_set_egress_flood(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1317               const struct dpsw_egress_flood_cfg *cfg)
1318 {
1319     struct dpsw_cmd_set_egress_flood *cmd_params;
1320     struct fsl_mc_command cmd = { 0 };
1321 
1322     cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_EGRESS_FLOOD, cmd_flags, token);
1323     cmd_params = (struct dpsw_cmd_set_egress_flood *)cmd.params;
1324     cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
1325     cmd_params->flood_type = cfg->flood_type;
1326     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1327 
1328     return mc_send_command(mc_io, &cmd);
1329 }
1330 
1331 /**
1332  * dpsw_if_set_learning_mode() - Configure the learning mode on an interface.
1333  * If this API is used, it will take precedence over the FDB configuration.
1334  * @mc_io:  Pointer to MC portal's I/O object
1335  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1336  * @token:  Token of DPSW object
1337  * @if_id:  InterfaceID
1338  * @mode:   Learning mode
1339  *
1340  * Return:  Completion status. '0' on Success; Error code otherwise.
1341  */
1342 int dpsw_if_set_learning_mode(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1343                   u16 if_id, enum dpsw_learning_mode mode)
1344 {
1345     struct dpsw_cmd_if_set_learning_mode *cmd_params;
1346     struct fsl_mc_command cmd = { 0 };
1347 
1348     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LEARNING_MODE,
1349                       cmd_flags,
1350                       token);
1351     cmd_params = (struct dpsw_cmd_if_set_learning_mode *)cmd.params;
1352     cmd_params->if_id = cpu_to_le16(if_id);
1353     dpsw_set_field(cmd_params->mode, LEARNING_MODE, mode);
1354 
1355     return mc_send_command(mc_io, &cmd);
1356 }
1357 
1358 /**
1359  * dpsw_acl_add() - Create an ACL table
1360  * @mc_io:  Pointer to MC portal's I/O object
1361  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1362  * @token:  Token of DPSW object
1363  * @acl_id: Returned ACL ID, for future references
1364  * @cfg:    ACL configuration
1365  *
1366  * Create Access Control List table. Multiple ACLs can be created and
1367  * co-exist in L2 switch
1368  *
1369  * Return:  '0' on Success; Error code otherwise.
1370  */
1371 int dpsw_acl_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *acl_id,
1372          const struct dpsw_acl_cfg *cfg)
1373 {
1374     struct dpsw_cmd_acl_add *cmd_params;
1375     struct dpsw_rsp_acl_add *rsp_params;
1376     struct fsl_mc_command cmd = { 0 };
1377     int err;
1378 
1379     cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD, cmd_flags, token);
1380     cmd_params = (struct dpsw_cmd_acl_add *)cmd.params;
1381     cmd_params->max_entries = cpu_to_le16(cfg->max_entries);
1382 
1383     err = mc_send_command(mc_io, &cmd);
1384     if (err)
1385         return err;
1386 
1387     rsp_params = (struct dpsw_rsp_acl_add *)cmd.params;
1388     *acl_id = le16_to_cpu(rsp_params->acl_id);
1389 
1390     return 0;
1391 }
1392 
1393 /**
1394  * dpsw_acl_remove() - Remove an ACL table from L2 switch.
1395  * @mc_io:  Pointer to MC portal's I/O object
1396  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1397  * @token:  Token of DPSW object
1398  * @acl_id: ACL ID
1399  *
1400  * Return:  '0' on Success; Error code otherwise.
1401  */
1402 int dpsw_acl_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1403             u16 acl_id)
1404 {
1405     struct dpsw_cmd_acl_remove *cmd_params;
1406     struct fsl_mc_command cmd = { 0 };
1407 
1408     cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE, cmd_flags,
1409                       token);
1410     cmd_params = (struct dpsw_cmd_acl_remove *)cmd.params;
1411     cmd_params->acl_id = cpu_to_le16(acl_id);
1412 
1413     return mc_send_command(mc_io, &cmd);
1414 }
1415 
1416 /**
1417  * dpsw_acl_add_if() - Associate interface/interfaces with an ACL table.
1418  * @mc_io:  Pointer to MC portal's I/O object
1419  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1420  * @token:  Token of DPSW object
1421  * @acl_id: ACL ID
1422  * @cfg:    Interfaces list
1423  *
1424  * Return:  '0' on Success; Error code otherwise.
1425  */
1426 int dpsw_acl_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1427             u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
1428 {
1429     struct dpsw_cmd_acl_if *cmd_params;
1430     struct fsl_mc_command cmd = { 0 };
1431 
1432     cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_IF, cmd_flags,
1433                       token);
1434     cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
1435     cmd_params->acl_id = cpu_to_le16(acl_id);
1436     cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1437     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1438 
1439     return mc_send_command(mc_io, &cmd);
1440 }
1441 
1442 /**
1443  * dpsw_acl_remove_if() - De-associate interface/interfaces from an ACL table
1444  * @mc_io:  Pointer to MC portal's I/O object
1445  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1446  * @token:  Token of DPSW object
1447  * @acl_id: ACL ID
1448  * @cfg:    Interfaces list
1449  *
1450  * Return:  '0' on Success; Error code otherwise.
1451  */
1452 int dpsw_acl_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1453                u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
1454 {
1455     struct dpsw_cmd_acl_if *cmd_params;
1456     struct fsl_mc_command cmd = { 0 };
1457 
1458     /* prepare command */
1459     cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_IF, cmd_flags,
1460                       token);
1461     cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
1462     cmd_params->acl_id = cpu_to_le16(acl_id);
1463     cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1464     build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1465 
1466     /* send command to mc*/
1467     return mc_send_command(mc_io, &cmd);
1468 }
1469 
1470 /**
1471  * dpsw_acl_prepare_entry_cfg() - Setup an ACL entry
1472  * @key:        Key
1473  * @entry_cfg_buf:  Zeroed 256 bytes of memory before mapping it to DMA
1474  *
1475  * This function has to be called before adding or removing acl_entry
1476  *
1477  */
1478 void dpsw_acl_prepare_entry_cfg(const struct dpsw_acl_key *key,
1479                 u8 *entry_cfg_buf)
1480 {
1481     struct dpsw_prep_acl_entry *ext_params;
1482     int i;
1483 
1484     ext_params = (struct dpsw_prep_acl_entry *)entry_cfg_buf;
1485 
1486     for (i = 0; i < 6; i++) {
1487         ext_params->match_l2_dest_mac[i] = key->match.l2_dest_mac[5 - i];
1488         ext_params->match_l2_source_mac[i] = key->match.l2_source_mac[5 - i];
1489         ext_params->mask_l2_dest_mac[i] = key->mask.l2_dest_mac[5 - i];
1490         ext_params->mask_l2_source_mac[i] = key->mask.l2_source_mac[5 - i];
1491     }
1492 
1493     ext_params->match_l2_tpid = cpu_to_le16(key->match.l2_tpid);
1494     ext_params->match_l2_vlan_id = cpu_to_le16(key->match.l2_vlan_id);
1495     ext_params->match_l3_dest_ip = cpu_to_le32(key->match.l3_dest_ip);
1496     ext_params->match_l3_source_ip = cpu_to_le32(key->match.l3_source_ip);
1497     ext_params->match_l4_dest_port = cpu_to_le16(key->match.l4_dest_port);
1498     ext_params->match_l4_source_port = cpu_to_le16(key->match.l4_source_port);
1499     ext_params->match_l2_ether_type = cpu_to_le16(key->match.l2_ether_type);
1500     ext_params->match_l2_pcp_dei = key->match.l2_pcp_dei;
1501     ext_params->match_l3_dscp = key->match.l3_dscp;
1502 
1503     ext_params->mask_l2_tpid = cpu_to_le16(key->mask.l2_tpid);
1504     ext_params->mask_l2_vlan_id = cpu_to_le16(key->mask.l2_vlan_id);
1505     ext_params->mask_l3_dest_ip = cpu_to_le32(key->mask.l3_dest_ip);
1506     ext_params->mask_l3_source_ip = cpu_to_le32(key->mask.l3_source_ip);
1507     ext_params->mask_l4_dest_port = cpu_to_le16(key->mask.l4_dest_port);
1508     ext_params->mask_l4_source_port = cpu_to_le16(key->mask.l4_source_port);
1509     ext_params->mask_l2_ether_type = cpu_to_le16(key->mask.l2_ether_type);
1510     ext_params->mask_l2_pcp_dei = key->mask.l2_pcp_dei;
1511     ext_params->mask_l3_dscp = key->mask.l3_dscp;
1512     ext_params->match_l3_protocol = key->match.l3_protocol;
1513     ext_params->mask_l3_protocol = key->mask.l3_protocol;
1514 }
1515 
1516 /**
1517  * dpsw_acl_add_entry() - Add a rule to the ACL table.
1518  * @mc_io:  Pointer to MC portal's I/O object
1519  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1520  * @token:  Token of DPSW object
1521  * @acl_id: ACL ID
1522  * @cfg:    Entry configuration
1523  *
1524  * warning: This function has to be called after dpsw_acl_prepare_entry_cfg()
1525  *
1526  * Return:  '0' on Success; Error code otherwise.
1527  */
1528 int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1529                u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
1530 {
1531     struct dpsw_cmd_acl_entry *cmd_params;
1532     struct fsl_mc_command cmd = { 0 };
1533 
1534     cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_ENTRY, cmd_flags,
1535                       token);
1536     cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
1537     cmd_params->acl_id = cpu_to_le16(acl_id);
1538     cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
1539     cmd_params->precedence = cpu_to_le32(cfg->precedence);
1540     cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1541     dpsw_set_field(cmd_params->result_action,
1542                RESULT_ACTION,
1543                cfg->result.action);
1544 
1545     return mc_send_command(mc_io, &cmd);
1546 }
1547 
1548 /**
1549  * dpsw_acl_remove_entry() - Removes an entry from ACL.
1550  * @mc_io:  Pointer to MC portal's I/O object
1551  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1552  * @token:  Token of DPSW object
1553  * @acl_id: ACL ID
1554  * @cfg:    Entry configuration
1555  *
1556  * warning: This function has to be called after dpsw_acl_set_entry_cfg()
1557  *
1558  * Return:  '0' on Success; Error code otherwise.
1559  */
1560 int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1561               u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
1562 {
1563     struct dpsw_cmd_acl_entry *cmd_params;
1564     struct fsl_mc_command cmd = { 0 };
1565 
1566     /* prepare command */
1567     cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_ENTRY,
1568                       cmd_flags,
1569                       token);
1570     cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
1571     cmd_params->acl_id = cpu_to_le16(acl_id);
1572     cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
1573     cmd_params->precedence = cpu_to_le32(cfg->precedence);
1574     cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1575     dpsw_set_field(cmd_params->result_action,
1576                RESULT_ACTION,
1577                cfg->result.action);
1578 
1579     /* send command to mc*/
1580     return mc_send_command(mc_io, &cmd);
1581 }
1582 
1583 /**
1584  * dpsw_set_reflection_if() - Set target interface for traffic mirrored
1585  * @mc_io:  Pointer to MC portal's I/O object
1586  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1587  * @token:  Token of DPSW object
1588  * @if_id:  Interface Id
1589  *
1590  * Only one mirroring destination is allowed per switch
1591  *
1592  * Return:  Completion status. '0' on Success; Error code otherwise.
1593  */
1594 int dpsw_set_reflection_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1595                u16 if_id)
1596 {
1597     struct dpsw_cmd_set_reflection_if *cmd_params;
1598     struct fsl_mc_command cmd = { 0 };
1599 
1600     cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_REFLECTION_IF,
1601                       cmd_flags,
1602                       token);
1603     cmd_params = (struct dpsw_cmd_set_reflection_if *)cmd.params;
1604     cmd_params->if_id = cpu_to_le16(if_id);
1605 
1606     return mc_send_command(mc_io, &cmd);
1607 }
1608 
1609 /**
1610  * dpsw_if_add_reflection() - Setup mirroring rule
1611  * @mc_io:  Pointer to MC portal's I/O object
1612  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1613  * @token:  Token of DPSW object
1614  * @if_id:  Interface Identifier
1615  * @cfg:    Reflection configuration
1616  *
1617  * Return:  Completion status. '0' on Success; Error code otherwise.
1618  */
1619 int dpsw_if_add_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1620                u16 if_id, const struct dpsw_reflection_cfg *cfg)
1621 {
1622     struct dpsw_cmd_if_reflection *cmd_params;
1623     struct fsl_mc_command cmd = { 0 };
1624 
1625     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ADD_REFLECTION,
1626                       cmd_flags,
1627                       token);
1628     cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
1629     cmd_params->if_id = cpu_to_le16(if_id);
1630     cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
1631     dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);
1632 
1633     return mc_send_command(mc_io, &cmd);
1634 }
1635 
1636 /**
1637  * dpsw_if_remove_reflection() - Remove mirroring rule
1638  * @mc_io:  Pointer to MC portal's I/O object
1639  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1640  * @token:  Token of DPSW object
1641  * @if_id:  Interface Identifier
1642  * @cfg:    Reflection configuration
1643  *
1644  * Return:  Completion status. '0' on Success; Error code otherwise.
1645  */
1646 int dpsw_if_remove_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1647                   u16 if_id, const struct dpsw_reflection_cfg *cfg)
1648 {
1649     struct dpsw_cmd_if_reflection *cmd_params;
1650     struct fsl_mc_command cmd = { 0 };
1651 
1652     cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_REMOVE_REFLECTION,
1653                       cmd_flags,
1654                       token);
1655     cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
1656     cmd_params->if_id = cpu_to_le16(if_id);
1657     cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
1658     dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);
1659 
1660     return mc_send_command(mc_io, &cmd);
1661 }