diff mbox series

[net-next,5/5] dpaa2-switch: reuse dpaa2_switch_acl_entry_add() for STP frames trap

Message ID 20210413132448.4141787-6-ciorneiioana@gmail.com (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series dpaa2-switch: add tc hardware offload on ingress traffic | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 78 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Ioana Ciornei April 13, 2021, 1:24 p.m. UTC
From: Ioana Ciornei <ioana.ciornei@nxp.com>

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>
---
 .../freescale/dpaa2/dpaa2-switch-flower.c     |  4 +-
 .../ethernet/freescale/dpaa2/dpaa2-switch.c   | 51 +++----------------
 .../ethernet/freescale/dpaa2/dpaa2-switch.h   |  3 ++
 3 files changed, 12 insertions(+), 46 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
index b4807ddc2011..f9451ec5f2cb 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-flower.c
@@ -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;
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
index adf9e5880d89..5250d51d783c 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
@@ -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)
diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.h b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.h
index 8575eed02d15..bdef71f234cb 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.h
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.h
@@ -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 */