Skip to content

Commit

Permalink
dpaa2-switch: reuse dpaa2_switch_acl_entry_add() for STP frames trap
Browse files Browse the repository at this point in the history
Since we added the dpaa2_switch_acl_entry_add() function in the previous
patches to hide all the details of actually adding the ACL entry by
issuing a firmware command, let's use it also for adding a CPU trap for
the STP frames.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ioana Ciornei authored and David S. Miller committed Apr 13, 2021
1 parent 4ba28c1 commit 1661795
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 46 deletions.
4 changes: 2 additions & 2 deletions drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ static int dpaa2_switch_flower_parse_key(struct flow_cls_offload *cls,
return 0;
}

static int dpaa2_switch_acl_entry_add(struct dpaa2_switch_acl_tbl *acl_tbl,
struct dpaa2_switch_acl_entry *entry)
int dpaa2_switch_acl_entry_add(struct dpaa2_switch_acl_tbl *acl_tbl,
struct dpaa2_switch_acl_entry *entry)
{
struct dpsw_acl_entry_cfg *acl_entry_cfg = &entry->cfg;
struct ethsw_core *ethsw = acl_tbl->ethsw;
Expand Down
51 changes: 7 additions & 44 deletions drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2942,54 +2942,17 @@ static int dpaa2_switch_init(struct fsl_mc_device *sw_dev)
static int dpaa2_switch_port_trap_mac_addr(struct ethsw_port_priv *port_priv,
const char *mac)
{
struct net_device *netdev = port_priv->netdev;
struct dpsw_acl_entry_cfg acl_entry_cfg;
struct dpsw_acl_fields *acl_h;
struct dpsw_acl_fields *acl_m;
struct dpsw_acl_key acl_key;
struct device *dev;
u8 *cmd_buff;
int err;

dev = port_priv->netdev->dev.parent;
acl_h = &acl_key.match;
acl_m = &acl_key.mask;

memset(&acl_entry_cfg, 0, sizeof(acl_entry_cfg));
memset(&acl_key, 0, sizeof(acl_key));
struct dpaa2_switch_acl_entry acl_entry = {0};

/* Match on the destination MAC address */
ether_addr_copy(acl_h->l2_dest_mac, mac);
eth_broadcast_addr(acl_m->l2_dest_mac);

cmd_buff = kzalloc(DPAA2_ETHSW_PORT_ACL_CMD_BUF_SIZE, GFP_KERNEL);
if (!cmd_buff)
return -ENOMEM;
dpsw_acl_prepare_entry_cfg(&acl_key, cmd_buff);
ether_addr_copy(acl_entry.key.match.l2_dest_mac, mac);
eth_broadcast_addr(acl_entry.key.mask.l2_dest_mac);

memset(&acl_entry_cfg, 0, sizeof(acl_entry_cfg));
acl_entry_cfg.precedence = 0;
acl_entry_cfg.result.action = DPSW_ACL_ACTION_REDIRECT_TO_CTRL_IF;
acl_entry_cfg.key_iova = dma_map_single(dev, cmd_buff,
DPAA2_ETHSW_PORT_ACL_CMD_BUF_SIZE,
DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(dev, acl_entry_cfg.key_iova))) {
netdev_err(netdev, "DMA mapping failed\n");
return -EFAULT;
}
/* Trap to CPU */
acl_entry.cfg.precedence = 0;
acl_entry.cfg.result.action = DPSW_ACL_ACTION_REDIRECT_TO_CTRL_IF;

err = dpsw_acl_add_entry(port_priv->ethsw_data->mc_io, 0,
port_priv->ethsw_data->dpsw_handle,
port_priv->acl_tbl->id, &acl_entry_cfg);

dma_unmap_single(dev, acl_entry_cfg.key_iova, sizeof(cmd_buff),
DMA_TO_DEVICE);
if (err) {
netdev_err(netdev, "dpsw_acl_add_entry() failed %d\n", err);
return err;
}

return 0;
return dpaa2_switch_acl_entry_add(port_priv->acl_tbl, &acl_entry);
}

static int dpaa2_switch_port_init(struct ethsw_port_priv *port_priv, u16 port)
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,7 @@ int dpaa2_switch_cls_matchall_replace(struct dpaa2_switch_acl_tbl *acl_tbl,

int dpaa2_switch_cls_matchall_destroy(struct dpaa2_switch_acl_tbl *acl_tbl,
struct tc_cls_matchall_offload *cls);

int dpaa2_switch_acl_entry_add(struct dpaa2_switch_acl_tbl *acl_tbl,
struct dpaa2_switch_acl_entry *entry);
#endif /* __ETHSW_H */

0 comments on commit 1661795

Please sign in to comment.