From: Roger Quadros <rogerq@kernel.org>
To: Siddharth Vadapalli <s-vadapalli@ti.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Russell King <linux@armlinux.org.uk>,
danishanwar@ti.com
Cc: srk@ti.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Roger Quadros <rogerq@kernel.org>
Subject: [PATCH net-next 6/9] net: ethernet: ti: cpsw_ale: add cpsw_ale_policer_set/clr_entry()
Date: Wed, 19 Mar 2025 15:38:32 +0200 [thread overview]
Message-ID: <20250319-am65-cpsw-rx-class-v1-6-2bfded07490e@kernel.org> (raw)
In-Reply-To: <20250319-am65-cpsw-rx-class-v1-0-2bfded07490e@kernel.org>
Add cpsw_ale_policer_set/clr_entry() helpers.
So far Raw Ethernet matching based on Source/Destination address
and VLAN Priority (PCP) is supported.
Signed-off-by: Roger Quadros <rogerq@kernel.org>
---
drivers/net/ethernet/ti/cpsw_ale.c | 84 ++++++++++++++++++++++++++++++++++++++
drivers/net/ethernet/ti/cpsw_ale.h | 28 +++++++++++++
2 files changed, 112 insertions(+)
diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index 630e3a555190..f5ca18d4ea6a 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -1746,3 +1746,87 @@ void cpsw_ale_classifier_setup_default(struct cpsw_ale *ale, int num_rx_ch)
1);
}
}
+
+#define HOST_PORT_NUM 0
+
+/* Clear Policer and associated ALE table entries */
+void cpsw_ale_policer_clr_entry(struct cpsw_ale *ale, u32 policer_idx,
+ struct cpsw_ale_policer_cfg *cfg)
+{
+ cpsw_ale_policer_reset_entry(ale, policer_idx);
+
+ /* We do not delete ALE entries that were added in set_entry
+ * as they might still be in use by the port e.g. VLAN id
+ * or port MAC address
+ */
+
+ /* clear BLOCKED in case we set it */
+ if ((cfg->match_flags & CPSW_ALE_POLICER_MATCH_MACSRC) && cfg->drop)
+ cpsw_ale_add_ucast(ale, cfg->src_addr, HOST_PORT_NUM, 0, 0);
+
+ if ((cfg->match_flags & CPSW_ALE_POLICER_MATCH_MACDST) && cfg->drop)
+ cpsw_ale_add_ucast(ale, cfg->dst_addr, HOST_PORT_NUM, 0, 0);
+}
+
+int cpsw_ale_policer_set_entry(struct cpsw_ale *ale, u32 policer_idx,
+ struct cpsw_ale_policer_cfg *cfg)
+{
+ int ale_idx;
+ u16 ale_flags = cfg->drop ? ALE_BLOCKED : 0;
+
+ /* A single policer can support multiple match types simultaneously
+ * There can be only one ALE entry per address
+ */
+ cpsw_ale_policer_reset_entry(ale, policer_idx);
+ cpsw_ale_policer_read_idx(ale, policer_idx);
+
+ if (cfg->match_flags & CPSW_ALE_POLICER_MATCH_MACSRC) {
+ ale_idx = cpsw_ale_add_ucast(ale, cfg->src_addr, HOST_PORT_NUM, ale_flags, 0);
+ if (ale_idx < 0)
+ return -ENOENT;
+
+ /* update policer entry */
+ regmap_field_write(ale->fields[POL_SRC_INDEX], ale_idx);
+ regmap_field_write(ale->fields[POL_SRC_MEN], 1);
+ }
+
+ if (cfg->match_flags & CPSW_ALE_POLICER_MATCH_MACDST) {
+ ale_idx = cpsw_ale_add_ucast(ale, cfg->dst_addr, HOST_PORT_NUM, ale_flags, 0);
+ if (ale_idx < 0)
+ return -ENOENT;
+
+ /* update policer entry */
+ regmap_field_write(ale->fields[POL_DST_INDEX], ale_idx);
+ regmap_field_write(ale->fields[POL_DST_MEN], 1);
+ }
+
+ if (cfg->match_flags & CPSW_ALE_POLICER_MATCH_OVLAN) {
+/* FIXME: VLAN ID based flow routing not yet working, Only PCP matching for now
+ * u32 port_mask, unreg_mcast = 0;
+ *
+ * port_mask = BIT(cfg->port_id) | ALE_PORT_HOST;
+ * if (!cfg->vid)
+ * unreg_mcast = port_mask;
+ * ale_idx = cpsw_ale_vlan_add_modify(ale, cfg->vid, port_mask,
+ * unreg_mcast, port_mask, 0);
+ * if (ale_idx < 0)
+ * return -ENOENT;
+ *
+ * regmap_field_write(ale->fields[POL_OVLAN_INDEX], ale_idx);
+ * regmap_field_write(ale->fields[POL_OVLAN_MEN], 1);
+ */
+
+ regmap_field_write(ale->fields[POL_PRI_VAL], cfg->vlan_prio);
+ regmap_field_write(ale->fields[POL_PRI_MEN], 1);
+ }
+
+ cpsw_ale_policer_write_idx(ale, policer_idx);
+
+ /* Map to thread id provided by the config */
+ if (!cfg->drop) {
+ cpsw_ale_policer_thread_idx_enable(ale, policer_idx,
+ cfg->thread_id, true);
+ }
+
+ return 0;
+}
diff --git a/drivers/net/ethernet/ti/cpsw_ale.h b/drivers/net/ethernet/ti/cpsw_ale.h
index ce59fec75774..11d333bf5a52 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.h
+++ b/drivers/net/ethernet/ti/cpsw_ale.h
@@ -159,6 +159,30 @@ enum cpsw_ale_port_state {
/* Policer */
#define CPSW_ALE_POLICER_ENTRY_WORDS 8
+/* Policer match flags */
+#define CPSW_ALE_POLICER_MATCH_PORT BIT(0)
+#define CPSW_ALE_POLICER_MATCH_PRI BIT(1)
+#define CPSW_ALE_POLICER_MATCH_OUI BIT(2)
+#define CPSW_ALE_POLICER_MATCH_MACDST BIT(3)
+#define CPSW_ALE_POLICER_MATCH_MACSRC BIT(4)
+#define CPSW_ALE_POLICER_MATCH_OVLAN BIT(5)
+#define CPSW_ALE_POLICER_MATCH_IVLAN BIT(6)
+#define CPSW_ALE_POLICER_MATCH_ETHTYPE BIT(7)
+#define CPSW_ALE_POLICER_MATCH_IPSRC BIT(8)
+#define CPSW_ALE_POLICER_MATCH_IPDST BIT(9)
+
+struct cpsw_ale_policer_cfg {
+ u32 match_flags;
+ u16 ether_type;
+ u16 vid;
+ u8 vlan_prio;
+ u8 src_addr[ETH_ALEN];
+ u8 dst_addr[ETH_ALEN];
+ bool drop;
+ u64 thread_id;
+ int port_id;
+};
+
struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params);
void cpsw_ale_start(struct cpsw_ale *ale);
@@ -199,5 +223,9 @@ void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask,
bool add);
void cpsw_ale_classifier_setup_default(struct cpsw_ale *ale, int num_rx_ch);
void cpsw_ale_policer_reset(struct cpsw_ale *ale);
+int cpsw_ale_policer_set_entry(struct cpsw_ale *ale, u32 policer_idx,
+ struct cpsw_ale_policer_cfg *cfg);
+void cpsw_ale_policer_clr_entry(struct cpsw_ale *ale, u32 policer_idx,
+ struct cpsw_ale_policer_cfg *cfg);
#endif
--
2.34.1
next prev parent reply other threads:[~2025-03-19 13:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-19 13:38 [PATCH net-next 0/9] net: ethernet: ti: am65-cpsw: add network flow classification support Roger Quadros
2025-03-19 13:38 ` [PATCH net-next 1/9] net: ethernet: ti: cpsw_ale: Update Policer fields for more ALE size/ports Roger Quadros
2025-03-19 13:38 ` [PATCH net-next 2/9] net: ethernet: ti: cpsw_ale: return ALE index in cpsw_ale_add_vlan() Roger Quadros
2025-03-19 13:38 ` [PATCH net-next 3/9] net: ethernet: ti: cpsw_ale: return ALE index in cpsw_ale_vlan_add_modify() Roger Quadros
2025-03-19 13:38 ` [PATCH net-next 4/9] net: ethernet: ti: cpsw_ale: return ALE index in cpsw_ale_add_ucast() Roger Quadros
2025-03-19 13:38 ` [PATCH net-next 5/9] net: ethernet: ti: cpsw_ale: add cpsw_ale_policer_reset_entry() Roger Quadros
2025-03-19 13:38 ` Roger Quadros [this message]
2025-03-25 14:21 ` [PATCH net-next 6/9] net: ethernet: ti: cpsw_ale: add cpsw_ale_policer_set/clr_entry() Jakub Kicinski
2025-04-02 12:37 ` Roger Quadros
2025-03-25 14:22 ` Jakub Kicinski
2025-03-19 13:38 ` [PATCH net-next 7/9] net: ethernet: ti: cpsw_ale: add policer save restore for PM sleep Roger Quadros
2025-03-19 13:38 ` [PATCH net-next 8/9] net: ethernet: ti: am65-cpsw: add network flow classification support Roger Quadros
2025-03-25 14:24 ` Jakub Kicinski
2025-03-19 13:38 ` [PATCH net-next 9/9] net: ethernet: ti: am65-cpsw: remove cpsw_ale_classifier_setup_default() Roger Quadros
2025-03-25 14:19 ` [PATCH net-next 0/9] net: ethernet: ti: am65-cpsw: add network flow classification support Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250319-am65-cpsw-rx-class-v1-6-2bfded07490e@kernel.org \
--to=rogerq@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=danishanwar@ti.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=s-vadapalli@ti.com \
--cc=srk@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox