Skip to contentSkip to conversation

net: dsa: motorcomm: Add limited ACL flow statistics support

PATCH New David Yang 1 participant 1 message Nov 28

Subsystems (4)
lore
Share & tools
lore

David Yang

author maintainer
#0 lore raw

PATCH v2 1/1 net: dsa: motorcomm: Add limited ACL flow statistics support

The hardware supports flow statistics, which might be used to implement .cls_flower_stats(). However, the number of flow counters is limited, and you must choose between byte and packet mode. Spend one only when needed. Let the counters here run in packet mode but keep the code for byte mode, in case you want to change your mind or a new API is available later.

---
v2:
- do not assign counter for police rules
- reject explicit delay request
- update lastused only when the counter changes
v1: https://lore.kernel.org/r/[email protected]

 drivers/net/dsa/motorcomm/chip.c |   1 +
 drivers/net/dsa/motorcomm/chip.h |   3 +
 drivers/net/dsa/motorcomm/tc.c   | 157 ++++++++++++++++++++++++++++++-
 drivers/net/dsa/motorcomm/tc.h   |  18 +++-
 4 files changed, 174 insertions(+), 5 deletions(-)
drivers/net/dsa/motorcomm/chip.c +1 -0
index a21d4bb5e141..1281396941e5 100644
@@ -2629,6 +2629,7 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
 	.port_policer_add	= yt921x_dsa_port_policer_add,
 	.port_setup_tc		= yt921x_dsa_port_setup_tc,
 	/* acl */
+	.cls_flower_stats	= yt921x_dsa_cls_flower_stats,
 	.cls_flower_del		= yt921x_dsa_cls_flower_del,
 	.cls_flower_add		= yt921x_dsa_cls_flower_add,
 	/* hsr */
drivers/net/dsa/motorcomm/chip.h +3 -0
index fc315f1d8f87..fe6cf03a09c8 100644
@@ -424,6 +424,8 @@ enum yt921x_fdb_entry_status {
 /* Custom meters only, not including dedicated port meters (11) */
 #define YT921X_METER_NUM	64
 
+#define YT921X_FLOWSTAT_NUM	64
+
 #define YT921X_LAG_NUM		2
 #define YT921X_LAG_PORT_NUM	4
 
@@ -527,6 +529,7 @@ struct yt921x_priv {
 	u16 eee_ports_mask;
 
 	DECLARE_BITMAP(meters_map, YT921X_METER_NUM);
+	DECLARE_BITMAP(flowstats_map, YT921X_FLOWSTAT_NUM);
 
 	u8 acl_masks[YT921X_ACL_BLK_NUM];
 	struct yt921x_acl_blk *acl_blks[YT921X_ACL_BLK_NUM];
drivers/net/dsa/motorcomm/tc.c +153 -4

254 lines not on this page · raw message

drivers/net/dsa/motorcomm/tc.h +17 -1
index cc53f148d690..9e50285d66f6 100644
@@ -299,6 +299,16 @@ enum yt921x_udf_type {
 #define  YT921X_METER_CTRLa_EIR_M		GENMASK(17, 0)
 #define   YT921X_METER_CTRLa_EIR(x)			FIELD_PREP(YT921X_METER_CTRLa_EIR_M, (x))
 #define YT921X_METERn_STAT(x)		(0x221000 + 8 * (x))
+#define YT921X_FLOWSTATn_STAT(x)	(0x221400 + 8 * (x))
+#define YT921X_FLOWSTATn_CTRL(x)	(0x221c00 + 4 * (x))
+#define  YT921X_FLOWSTAT_CTRL_EN		BIT(3)
+#define  YT921X_FLOWSTAT_CTRL_PKT_MODE		BIT(2)	/* 0: byte mode */
+#define  YT921X_FLOWSTAT_CTRL_TYPE_M		GENMASK(1, 0)
+#define   YT921X_FLOWSTAT_CTRL_TYPE(x)			FIELD_PREP(YT921X_FLOWSTAT_CTRL_TYPE_M, (x))
+#define   YT921X_FLOWSTAT_CTRL_TYPE_FLOW		YT921X_FLOWSTAT_CTRL_TYPE(0)
+#define   YT921X_FLOWSTAT_CTRL_TYPE_CPU_CODE		YT921X_FLOWSTAT_CTRL_TYPE(1)
+#define   YT921X_FLOWSTAT_CTRL_TYPE_DROP_CODE		YT921X_FLOWSTAT_CTRL_TYPE(2)
+#define   YT921X_FLOWSTAT_CTRL_TYPE_PORT		YT921X_FLOWSTAT_CTRL_TYPE(3)
 
 #define YT921X_MIRROR			0x300300
 #define  YT921X_MIRROR_IGR_PORTS_M		GENMASK(26, 16)
@@ -349,7 +359,10 @@ struct yt921x_acl_rule {
 	enum tc_setup_type type;
 
 	u32 action[3];
-	bool sw_assisted;
+	u64 laststat;
+
+	bool sw_assisted:1;
+	bool stat_pkt_mode:1;
 
 	u8 mask;
 	struct yt921x_acl_entry entries[YT921X_ACL_ENT_PER_BLK];
@@ -368,6 +381,9 @@ int
 yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port,
 			 enum tc_setup_type type, void *type_data);
 int
+yt921x_dsa_cls_flower_stats(struct dsa_switch *ds, int port,
+			    struct flow_cls_offload *cls, bool ingress);
+int
 yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port,
 			  struct flow_cls_offload *cls, bool ingress);
 int
Signature · 1 line
2.53.0