Skip to contentSkip to conversation

Add support for PSFP in Sparx5

PATCH Applied Daniel Machon 3 participants 24 messages Feb 2, 2023 – Feb 6, 2023

Subsystems (3)
lore
Share & tools
lore

Daniel Machon

author maintainer
#0 lore raw

cover Add support for PSFP in Sparx5

================================================================================
Add support for Per-Stream Filtering and Policing (802.1Q-2018, 8.6.5.1).
================================================================================

The VCAP CLM (VCAP IS0 ingress classifier) classifies streams, identified by ISDX (Ingress Service Index, frame metadata), and maps ISDX to streams.

Flow meters are also classified by ISDX, and implemented using service policers (Service Dual Leacky Buckets, SDLB). Leacky buckets are linked together in a leak chain of a leak group. Leak groups a preconfigured to serve buckets within a certain rate interval.

Stream gates are time-based policers used by PSFP. Frames are dropped based on the gate state (OPEN/ CLOSE), whose state will be altered based on the Gate Control List (GCL) and current PTP time. Apart from time-based policing, stream gates can alter egress queue selection for the frames that pass through the Gate. This is done through Internal Priority Selector (IPS). Stream gates are mapped from stream filters.

Support for tc actions gate and police, have been added to the VCAP IS0 set of supported actions.

Examples:

// tc filter with gate action

$ tc filter add dev eth1 ingress chain 1100000 prio 1 handle 1001 protocol \
802.1q flower skip_sw vlan_id 100 action gate base-time 0 sched-entry open \
700000 7 8m sched-entry close 300000 action goto chain 1200000

// tc filter with police action

$ tc filter add dev eth1 ingress chain 1100000 prio 1 handle 1002 protocol \
802.1q flower skip_sw vlan_id 100 action police rate 1gbit burst 8096      \
conform-exceed drop action goto chain 1200000

================================================================================
Patches
================================================================================

Patch #1:  Adds new register needed for PSFP.
Patch #2:  Adds resource pools to control PSFP needed chip resources.
Patch #3:  Adds support for SDLB's needed for flow-meters.
Patch #4:  Adds support for service policers.
Patch #5:  Adds support for PSFP flow-meters, using service policers.
Patch #6:  Adds a new function to calculate basetime, required by flow-meters.
Patch #7:  Adds support for PSFP stream gates.
Patch #8:  Adds support for PSFP stream filters.
Patch #9:  Adds a function to initialize flow-meters, stream gates and stream

filters.
Patch #10: Adds the required flower code to configure PSFP using the tc command.

Daniel Machon (10):
net: microchip: add registers needed for PSFP
net: microchip: sparx5: add resource pools
net: microchip: sparx5: add support for Service Dual Leacky Buckets
net: microchip: sparx5: add support for service policers
net: microchip: sparx5: add support for PSFP flow-meters
net: microchip: sparx5: add function for calculating PTP basetime
net: microchip: sparx5: add support for PSFP stream gates
net: microchip: sparx5: add support for PSFP stream filters
net: microchip: sparx5: initialize PSFP
sparx5: add support for configuring PSFP via tc

 .../net/ethernet/microchip/sparx5/Makefile    |   3 +-
 .../ethernet/microchip/sparx5/sparx5_main.c   |   5 +-
 .../ethernet/microchip/sparx5/sparx5_main.h   | 125 ++++
 .../microchip/sparx5/sparx5_main_regs.h       | 581 +++++++++++++++++-
 .../ethernet/microchip/sparx5/sparx5_police.c |  53 ++
 .../ethernet/microchip/sparx5/sparx5_pool.c   |  81 +++
 .../ethernet/microchip/sparx5/sparx5_psfp.c   | 332 ++++++++++
 .../ethernet/microchip/sparx5/sparx5_ptp.c    |   3 +-
 .../ethernet/microchip/sparx5/sparx5_qos.c    |  59 ++
 .../ethernet/microchip/sparx5/sparx5_sdlb.c   | 335 ++++++++++
 .../microchip/sparx5/sparx5_tc_flower.c       | 238 ++++++-
 .../net/ethernet/microchip/vcap/vcap_api.c    |   3 +-
 .../ethernet/microchip/vcap/vcap_api_client.h |   3 +
 13 files changed, 1808 insertions(+), 13 deletions(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_police.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_pool.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c

--
2.34.1

author maintainer
#1 lore raw

PATCH 1/10 net: microchip: add registers needed for PSFP

Add registers needed for PSFP. This patch also renames a single register, shortening its name (SYS_CLK_PER_100PS). Uses have been update accordingly.

---
 .../ethernet/microchip/sparx5/sparx5_main.c   |   5 +-
 .../microchip/sparx5/sparx5_main_regs.h       | 581 +++++++++++++++++-
 2 files changed, 579 insertions(+), 7 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +3 -2
index 300fb7247bb3..c213a4414e65 100644
@@ -205,6 +205,7 @@ static const struct sparx5_main_io_resource sparx5_main_iomap[] =  {
 	{ TARGET_EACL,               0x112c0000, 2 }, /* 0x6112c0000 */
 	{ TARGET_ANA_CL,             0x11400000, 2 }, /* 0x611400000 */
 	{ TARGET_ANA_L3,             0x11480000, 2 }, /* 0x611480000 */
+	{ TARGET_ANA_AC_SDLB,        0x11500000, 2 }, /* 0x611500000 */
 	{ TARGET_HSCH,               0x11580000, 2 }, /* 0x611580000 */
 	{ TARGET_REW,                0x11600000, 2 }, /* 0x611600000 */
 	{ TARGET_ANA_L2,             0x11800000, 2 }, /* 0x611800000 */
@@ -501,8 +502,8 @@ static int sparx5_init_coreclock(struct sparx5 *sparx5)
 
 	clk_period = sparx5_clk_period(freq);
 
-	spx5_rmw(HSCH_SYS_CLK_PER_SYS_CLK_PER_100PS_SET(clk_period / 100),
-		 HSCH_SYS_CLK_PER_SYS_CLK_PER_100PS,
+	spx5_rmw(HSCH_SYS_CLK_PER_100PS_SET(clk_period / 100),
+		 HSCH_SYS_CLK_PER_100PS,
 		 sparx5,
 		 HSCH_SYS_CLK_PER);
 
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +576 -5

617 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 2/10 net: microchip: sparx5: add resource pools

In reply to Daniel Machon

Add resource pools and accessor functions. These pools can be queried by the driver, whenever a finite resource is required. Some resources can be reused, in which case an index and a reference count is used to keep track of users.

---
 .../net/ethernet/microchip/sparx5/Makefile    |  3 +-
 .../ethernet/microchip/sparx5/sparx5_main.h   | 12 +++
 .../ethernet/microchip/sparx5/sparx5_pool.c   | 81 +++++++++++++++++++
 3 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_pool.c
drivers/net/ethernet/microchip/sparx5/Makefile +2 -1
index d0ed7090aa54..6bb4609107b4 100644
@@ -9,7 +9,8 @@ sparx5-switch-y  := sparx5_main.o sparx5_packet.o \
  sparx5_netdev.o sparx5_phylink.o sparx5_port.o sparx5_mactable.o sparx5_vlan.o \
  sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o \
  sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \
- sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o sparx5_tc_matchall.o
+ sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \
+ sparx5_tc_matchall.o sparx5_pool.o
 
 sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o
 sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +12 -0
index 4a574cdcb584..4d0556e2ff24 100644
@@ -413,6 +413,18 @@ int sparx5_pgid_alloc_glag(struct sparx5 *spx5, u16 *idx);
 int sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx);
 int sparx5_pgid_free(struct sparx5 *spx5, u16 idx);
 
+/* sparx5_pool.c */
+struct sparx5_pool_entry {
+	u16 ref_cnt;
+	u32 idx; /* tc index */
+};
+
+u32 sparx5_pool_idx_to_id(u32 idx);
+int sparx5_pool_put(struct sparx5_pool_entry *pool, int size, u32 id);
+int sparx5_pool_get(struct sparx5_pool_entry *pool, int size, u32 *id);
+int sparx5_pool_get_with_idx(struct sparx5_pool_entry *pool, int size, u32 idx,
+			     u32 *id);
+
 /* Clock period in picoseconds */
 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
 {
drivers/net/ethernet/microchip/sparx5/sparx5_pool.c new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH 3/10 net: microchip: sparx5: add support for Service Dual Leacky Buckets

In reply to Daniel Machon

Add support for Service Dual Leacky Buckets (SDLB), used to implement PSFP flow-meters. Buckets are linked together in a leak chain of a leak group. Leak groups a preconfigured to serve buckets within a certain rate interval.

---
 .../net/ethernet/microchip/sparx5/Makefile    |   2 +-
 .../ethernet/microchip/sparx5/sparx5_main.h   |  31 ++
 .../ethernet/microchip/sparx5/sparx5_sdlb.c   | 335 ++++++++++++++++++
 3 files changed, 367 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
index 6bb4609107b4..b3de8490db38 100644
@@ -10,7 +10,7 @@ sparx5-switch-y  := sparx5_main.o sparx5_packet.o \
  sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o \
  sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \
  sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \
- sparx5_tc_matchall.o sparx5_pool.o
+ sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o
 
 sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o
 sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +31 -0
index 4d0556e2ff24..daaaa670365b 100644
@@ -425,6 +425,37 @@ int sparx5_pool_get(struct sparx5_pool_entry *pool, int size, u32 *id);
 int sparx5_pool_get_with_idx(struct sparx5_pool_entry *pool, int size, u32 idx,
 			     u32 *id);
 
+/* sparx5_sdlb.c */
+#define SPX5_SDLB_PUP_TOKEN_DISABLE 0x1FFF
+#define SPX5_SDLB_PUP_TOKEN_MAX (SPX5_SDLB_PUP_TOKEN_DISABLE - 1)
+#define SPX5_SDLB_GROUP_RATE_MAX 25000000000ULL
+#define SPX5_SDLB_2CYCLES_TYPE2_THRES_OFFSET 13
+#define SPX5_SDLB_CNT 4096
+#define SPX5_SDLB_GROUP_CNT 10
+#define SPX5_CLK_PER_100PS_DEFAULT 16
+
+struct sparx5_sdlb_group {
+	u64 max_rate;
+	u32 min_burst;
+	u32 frame_size;
+	u32 pup_interval;
+	u32 nsets;
+};
+
+extern struct sparx5_sdlb_group sdlb_groups[SPX5_SDLB_GROUP_CNT];
+int sparx5_sdlb_pup_token_get(struct sparx5 *sparx5, u32 pup_interval,
+			      u64 rate);
+
+int sparx5_sdlb_clk_hz_get(struct sparx5 *sparx5);
+int sparx5_sdlb_group_get_by_rate(struct sparx5 *sparx5, u32 rate, u32 burst);
+int sparx5_sdlb_group_get_by_index(struct sparx5 *sparx5, u32 idx, u32 *group);
+
+int sparx5_sdlb_group_add(struct sparx5 *sparx5, u32 group, u32 idx);
+int sparx5_sdlb_group_del(struct sparx5 *sparx5, u32 group, u32 idx);
+
+void sparx5_sdlb_group_init(struct sparx5 *sparx5, u64 max_rate, u32 min_burst,
+			    u32 frame_size, u32 idx);
+
 /* Clock period in picoseconds */
 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
 {
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +335 -0

335 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#11 lore raw

PATCH 5/10 net: microchip: sparx5: add support for PSFP flow-meters

In reply to Daniel Machon

Add support for configuring PSFP flow-meters (IEEE 802.1Q-2018, 8.6.5.1.3).

The VCAP CLM (VCAP IS0 ingress classifier) classifies streams, identified by ISDX (Ingress Service Index, frame metadata), and maps ISDX to flow-meters. SDLB's provide the flow-meter parameters.

---
 .../net/ethernet/microchip/sparx5/Makefile    |  2 +-
 .../ethernet/microchip/sparx5/sparx5_main.h   |  9 ++
 .../ethernet/microchip/sparx5/sparx5_psfp.c   | 88 +++++++++++++++++++
 3 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
index 9f35b0dc3212..1cb1cc3f1a85 100644
@@ -10,7 +10,7 @@ sparx5-switch-y  := sparx5_main.o sparx5_packet.o \
  sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o \
  sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \
  sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \
- sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o sparx5_police.o
+ sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o sparx5_police.o sparx5_psfp.o
 
 sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o
 sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +9 -0
index c8bb50bbdcdf..709cad534f50 100644
@@ -472,6 +472,15 @@ struct sparx5_policer {
 
 int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol);
 
+/* sparx5_psfp.c */
+struct sparx5_psfp_fm {
+	struct sparx5_policer pol;
+};
+
+int sparx5_psfp_fm_add(struct sparx5 *sparx5, u32 uidx,
+		       struct sparx5_psfp_fm *fm, u32 *id);
+int sparx5_psfp_fm_del(struct sparx5 *sparx5, u32 id);
+
 /* Clock period in picoseconds */
 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
 {
drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#13 lore raw

PATCH 6/10 net: microchip: sparx5: add function for calculating PTP basetime

In reply to Daniel Machon

Add a new function for calculating PTP basetime, required by the stream gate scheduler to calculate gate state (open / close).

---
 .../ethernet/microchip/sparx5/sparx5_main.h   |  5 ++
 .../ethernet/microchip/sparx5/sparx5_ptp.c    |  3 +-
 .../ethernet/microchip/sparx5/sparx5_qos.c    | 57 +++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +5 -0
index 709cad534f50..fd71b2ede49a 100644
@@ -396,6 +396,7 @@ int sparx5_ptp_txtstamp_request(struct sparx5_port *port,
 void sparx5_ptp_txtstamp_release(struct sparx5_port *port,
 				 struct sk_buff *skb);
 irqreturn_t sparx5_ptp_irq_handler(int irq, void *args);
+int sparx5_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
 
 /* sparx5_vcap_impl.c */
 int sparx5_vcap_init(struct sparx5 *sparx5);
@@ -481,6 +482,10 @@ int sparx5_psfp_fm_add(struct sparx5 *sparx5, u32 uidx,
 		       struct sparx5_psfp_fm *fm, u32 *id);
 int sparx5_psfp_fm_del(struct sparx5 *sparx5, u32 id);
 
+/* sparx5_qos.c */
+void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time,
+			  const ktime_t org_base_time, ktime_t *new_base_time);
+
 /* Clock period in picoseconds */
 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
 {
drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c +1 -2
index 0ed1ea7727c5..af85d66248b2 100644
@@ -476,8 +476,7 @@ static int sparx5_ptp_settime64(struct ptp_clock_info *ptp,
 	return 0;
 }
 
-static int sparx5_ptp_gettime64(struct ptp_clock_info *ptp,
-				struct timespec64 *ts)
+int sparx5_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts)
 {
 	struct sparx5_phc *phc = container_of(ptp, struct sparx5_phc, info);
 	struct sparx5 *sparx5 = phc->sparx5;
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +57 -0

63 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#15 lore raw

PATCH 7/10 net: microchip: sparx5: add support for PSFP stream gates

In reply to Daniel Machon

Add support for configuring PSFP stream gates (IEEE 802.1Q-2018, 8.6.5.1.2).

Stream gates are time-based policers used by PSFP. Frames are dropped based on the gate state (OPEN/ CLOSE), whose state will be altered based on the Gate Control List (GCL) and current PTP time. Apart from time-based policing, stream gates can alter egress queue selection for the frames that pass through the Gate. This is done through Internal Priority Selector (IPS). Stream gates are mapped from stream filters.

---
 .../ethernet/microchip/sparx5/sparx5_main.h   |  31 ++++
 .../ethernet/microchip/sparx5/sparx5_psfp.c   | 148 ++++++++++++++++++
 2 files changed, 179 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +31 -0
index fd71b2ede49a..5a2d893749fd 100644
@@ -474,14 +474,45 @@ struct sparx5_policer {
 int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol);
 
 /* sparx5_psfp.c */
+#define SPX5_PSFP_GCE_CNT 4
+#define SPX5_PSFP_SG_CNT 1024
+#define SPX5_PSFP_SG_MIN_CYCLE_TIME_NS (1 * NSEC_PER_USEC)
+#define SPX5_PSFP_SG_MAX_CYCLE_TIME_NS ((1 * NSEC_PER_SEC) - 1)
+#define SPX5_PSFP_SG_MAX_IPV (SPX5_PRIOS - 1)
+#define SPX5_PSFP_SG_OPEN (SPX5_PSFP_SG_CNT - 1)
+#define SPX5_PSFP_SG_CYCLE_TIME_DEFAULT 1000000
+#define SPX5_PSFP_SF_MAX_SDU 16383
+
 struct sparx5_psfp_fm {
 	struct sparx5_policer pol;
 };
 
+struct sparx5_psfp_gce {
+	bool gate_state;            /* StreamGateState */
+	u32 interval;               /* TimeInterval */
+	u32 ipv;                    /* InternalPriorityValue */
+	u32 maxoctets;              /* IntervalOctetMax */
+};
+
+struct sparx5_psfp_sg {
+	bool gate_state;            /* PSFPAdminGateStates */
+	bool gate_enabled;          /* PSFPGateEnabled */
+	u32 ipv;                    /* PSFPAdminIPV */
+	struct timespec64 basetime; /* PSFPAdminBaseTime */
+	u32 cycletime;              /* PSFPAdminCycleTime */
+	u32 cycletimeext;           /* PSFPAdminCycleTimeExtension */
+	u32 num_entries;            /* PSFPAdminControlListLength */
+	struct sparx5_psfp_gce gce[SPX5_PSFP_GCE_CNT];
+};
+
 int sparx5_psfp_fm_add(struct sparx5 *sparx5, u32 uidx,
 		       struct sparx5_psfp_fm *fm, u32 *id);
 int sparx5_psfp_fm_del(struct sparx5 *sparx5, u32 id);
 
+int sparx5_psfp_sg_add(struct sparx5 *sparx5, u32 uidx,
+		       struct sparx5_psfp_sg *sg, u32 *id);
+int sparx5_psfp_sg_del(struct sparx5 *sparx5, u32 id);
+
 /* sparx5_qos.c */
 void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time,
 			  const ktime_t org_base_time, ktime_t *new_base_time);
drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c +148 -0

169 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#17 lore raw

PATCH 8/10 net: microchip: sparx5: add support for PSFP stream filters

In reply to Daniel Machon

Add support for configuring PSFP stream filters (IEEE 802.1Q-2018, 8.6.5.1.1).

The VCAP CLM (VCAP IS0 ingress classifier) classifies streams, identified by ISDX (Ingress Service Index, frame metadata), and maps ISDX to streams.

---
 .../ethernet/microchip/sparx5/sparx5_main.h   | 17 ++++
 .../ethernet/microchip/sparx5/sparx5_psfp.c   | 78 +++++++++++++++++++
 2 files changed, 95 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +17 -0
index 5a2d893749fd..cffed893fb7b 100644
@@ -505,6 +505,14 @@ struct sparx5_psfp_sg {
 	struct sparx5_psfp_gce gce[SPX5_PSFP_GCE_CNT];
 };
 
+struct sparx5_psfp_sf {
+	bool sblock_osize_ena;
+	bool sblock_osize;
+	u32 max_sdu;
+	u32 sgid; /* Gate id */
+	u32 fmid; /* Flow meter id */
+};
+
 int sparx5_psfp_fm_add(struct sparx5 *sparx5, u32 uidx,
 		       struct sparx5_psfp_fm *fm, u32 *id);
 int sparx5_psfp_fm_del(struct sparx5 *sparx5, u32 id);
@@ -513,6 +521,15 @@ int sparx5_psfp_sg_add(struct sparx5 *sparx5, u32 uidx,
 		       struct sparx5_psfp_sg *sg, u32 *id);
 int sparx5_psfp_sg_del(struct sparx5 *sparx5, u32 id);
 
+int sparx5_psfp_sf_add(struct sparx5 *sparx5, const struct sparx5_psfp_sf *sf,
+		       u32 *id);
+int sparx5_psfp_sf_del(struct sparx5 *sparx5, u32 id);
+
+u32 sparx5_psfp_isdx_get_sf(struct sparx5 *sparx5, u32 isdx);
+u32 sparx5_psfp_isdx_get_fm(struct sparx5 *sparx5, u32 isdx);
+u32 sparx5_psfp_sf_get_sg(struct sparx5 *sparx5, u32 sfid);
+void sparx5_isdx_conf_set(struct sparx5 *sparx5, u32 isdx, u32 sfid, u32 fmid);
+
 /* sparx5_qos.c */
 void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time,
 			  const ktime_t org_base_time, ktime_t *new_base_time);
drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c +78 -0

108 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#19 lore raw

PATCH 9/10 net: microchip: sparx5: initialize PSFP

In reply to Daniel Machon

Initialize the SDLB's, stream gates and stream filters.

---
 .../ethernet/microchip/sparx5/sparx5_main.h    |  3 +++
 .../ethernet/microchip/sparx5/sparx5_psfp.c    | 18 ++++++++++++++++++
 .../net/ethernet/microchip/sparx5/sparx5_qos.c |  2 ++
 3 files changed, 23 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +3 -0
index cffed893fb7b..72e7928912eb 100644
@@ -456,6 +456,7 @@ int sparx5_sdlb_group_del(struct sparx5 *sparx5, u32 group, u32 idx);
 
 void sparx5_sdlb_group_init(struct sparx5 *sparx5, u64 max_rate, u32 min_burst,
 			    u32 frame_size, u32 idx);
+
 /* sparx5_police.c */
 enum {
 	/* More policer types will be added later */
@@ -530,6 +531,8 @@ u32 sparx5_psfp_isdx_get_fm(struct sparx5 *sparx5, u32 isdx);
 u32 sparx5_psfp_sf_get_sg(struct sparx5 *sparx5, u32 sfid);
 void sparx5_isdx_conf_set(struct sparx5 *sparx5, u32 isdx, u32 sfid, u32 fmid);
 
+void sparx5_psfp_init(struct sparx5 *sparx5);
+
 /* sparx5_qos.c */
 void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time,
 			  const ktime_t org_base_time, ktime_t *new_base_time);
drivers/net/ethernet/microchip/sparx5/sparx5_psfp.c +18 -0
index b70601a5e4c5..8dee1ab1fa75 100644
@@ -312,3 +312,21 @@ int sparx5_psfp_fm_del(struct sparx5 *sparx5, u32 id)
 
 	return sparx5_sdlb_conf_set(sparx5, &fm);
 }
+
+void sparx5_psfp_init(struct sparx5 *sparx5)
+{
+	const struct sparx5_sdlb_group *group;
+	int i;
+
+	for (i = 0; i < SPX5_SDLB_GROUP_CNT; i++) {
+		group = &sdlb_groups[i];
+		sparx5_sdlb_group_init(sparx5, group->max_rate,
+				       group->min_burst, group->frame_size, i);
+	}
+
+	spx5_wr(ANA_AC_SG_CYCLETIME_UPDATE_PERIOD_SG_CT_UPDATE_ENA_SET(1),
+		sparx5, ANA_AC_SG_CYCLETIME_UPDATE_PERIOD);
+
+	spx5_rmw(ANA_L2_FWD_CFG_ISDX_LOOKUP_ENA_SET(1),
+		 ANA_L2_FWD_CFG_ISDX_LOOKUP_ENA, sparx5, ANA_L2_FWD_CFG);
+}
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +2 -0
index ebfdbbf0a1ce..5f34febaee6b 100644
@@ -450,6 +450,8 @@ int sparx5_qos_init(struct sparx5 *sparx5)
 	if (ret < 0)
 		return ret;
 
+	sparx5_psfp_init(sparx5);
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
author maintainer
#21 lore raw

PATCH 10/10 sparx5: add support for configuring PSFP via tc

In reply to Daniel Machon

Add support for tc actions gate and police, in order to implement support for configuring PSFP through tc.

---
 .../microchip/sparx5/sparx5_tc_flower.c       | 237 +++++++++++++++++-
 .../net/ethernet/microchip/vcap/vcap_api.c    |   3 +-
 .../ethernet/microchip/vcap/vcap_api_client.h |   3 +
 3 files changed, 240 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c +235 -2
index 217ff127e3c7..f962304272c2 100644
@@ -4,6 +4,7 @@
  * Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries.
  */
 
+#include <net/tc_act/tc_gate.h>
 #include <net/tcp.h>
 
 #include "sparx5_tc.h"
@@ -989,19 +990,156 @@ static int sparx5_tc_add_rule_link(struct vcap_control *vctrl,
 	return err;
 }
 
+static int sparx5_tc_flower_parse_act_gate(struct sparx5_psfp_sg *sg,
+					   struct flow_action_entry *act,
+					   struct netlink_ext_ack *extack)
+{
+	int i;
+
+	if (act->gate.prio < -1 || act->gate.prio > SPX5_PSFP_SG_MAX_IPV) {
+		NL_SET_ERR_MSG_MOD(extack, "Invalid gate priority");
+		return -EINVAL;
+	}
+
+	if (act->gate.cycletime < SPX5_PSFP_SG_MIN_CYCLE_TIME_NS ||
+	    act->gate.cycletime > SPX5_PSFP_SG_MAX_CYCLE_TIME_NS) {
+		NL_SET_ERR_MSG_MOD(extack, "Invalid gate cycletime");
+		return -EINVAL;
+	}
+
+	if (act->gate.cycletimeext > SPX5_PSFP_SG_MAX_CYCLE_TIME_NS) {
+		NL_SET_ERR_MSG_MOD(extack, "Invalid gate cycletimeext");
+		return -EINVAL;
+	}
+
+	if (act->gate.num_entries >= SPX5_PSFP_GCE_CNT) {
+		NL_SET_ERR_MSG_MOD(extack, "Invalid number of gate entries");
+		return -EINVAL;
+	}
+
+	sg->gate_state = true;
+	sg->ipv = act->gate.prio;
+	sg->num_entries = act->gate.num_entries;
+	sg->cycletime = act->gate.cycletime;
+	sg->cycletimeext = act->gate.cycletimeext;
+
+	for (i = 0; i < sg->num_entries; i++) {
+		sg->gce[i].gate_state = !!act->gate.entries[i].gate_state;
+		sg->gce[i].interval = act->gate.entries[i].interval;
+		sg->gce[i].ipv = act->gate.entries[i].ipv;
+		sg->gce[i].maxoctets = act->gate.entries[i].maxoctets;
+	}
+
+	return 0;
+}
+
+static int sparx5_tc_flower_parse_act_police(struct sparx5_policer *pol,
+					     struct flow_action_entry *act,
+					     struct netlink_ext_ack *extack)
+{
+	pol->type = SPX5_POL_SERVICE;
+	pol->rate = div_u64(act->police.rate_bytes_ps, 1000) * 8;
+	pol->burst = act->police.burst;
+	pol->idx = act->hw_index;
+
+	/* rate is now in kbit */
+	if (pol->rate > DIV_ROUND_UP(SPX5_SDLB_GROUP_RATE_MAX, 1000)) {
+		NL_SET_ERR_MSG_MOD(extack, "Maximum rate exceeded");
+		return -EINVAL;
+	}
+
+	if (act->police.exceed.act_id != FLOW_ACTION_DROP) {
+		NL_SET_ERR_MSG_MOD(extack, "Offload not supported when exceed action is not drop");
+		return -EOPNOTSUPP;
+	}
+
+	if (act->police.notexceed.act_id != FLOW_ACTION_PIPE &&
+	    act->police.notexceed.act_id != FLOW_ACTION_ACCEPT) {
+		NL_SET_ERR_MSG_MOD(extack, "Offload not supported when conform action is not pipe or ok");
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static int sparx5_tc_flower_psfp_setup(struct sparx5 *sparx5,
+				       struct vcap_rule *vrule, int sg_idx,
+				       int pol_idx, struct sparx5_psfp_sg *sg,
+				       struct sparx5_psfp_fm *fm,
+				       struct sparx5_psfp_sf *sf)
+{
+	u32 psfp_sfid = 0, psfp_fmid = 0, psfp_sgid = 0;
+	int ret;
+
+	/* Must always have a stream gate - max sdu (filter option) is evaluated
+	 * after frames have passed the gate, so in case of only a policer, we
+	 * allocate a stream gate that is always open.
+	 */
+	if (sg_idx < 0) {
+		sg_idx = sparx5_pool_idx_to_id(SPX5_PSFP_SG_OPEN);
+		sg->ipv = 0; /* Disabled */
+		sg->cycletime = SPX5_PSFP_SG_CYCLE_TIME_DEFAULT;
+		sg->num_entries = 1;
+		sg->gate_state = 1; /* Open */
+		sg->gate_enabled = 1;
+		sg->gce[0].gate_state = 1;
+		sg->gce[0].interval = SPX5_PSFP_SG_CYCLE_TIME_DEFAULT;
+		sg->gce[0].ipv = 0;
+		sg->gce[0].maxoctets = 0; /* Disabled */
+	}
+
+	ret = sparx5_psfp_sg_add(sparx5, sg_idx, sg, &psfp_sgid);
+	if (ret < 0)
+		return ret;
+
+	if (pol_idx >= 0) {
+		/* Add new flow-meter */
+		ret = sparx5_psfp_fm_add(sparx5, pol_idx, fm, &psfp_fmid);
+		if (ret < 0)
+			return ret;
+	}
+
+	/* Map stream filter to stream gate */
+	sf->sgid = psfp_sgid;
+
+	/* Add new stream-filter and map it to a steam gate */
+	ret = sparx5_psfp_sf_add(sparx5, sf, &psfp_sfid);
+	if (ret < 0)
+		return ret;
+
+	/* Streams are classified by ISDX - map ISDX 1:1 to sfid for now. */
+	sparx5_isdx_conf_set(sparx5, psfp_sfid, psfp_sfid, psfp_fmid);
+
+	ret = vcap_rule_add_action_bit(vrule, VCAP_AF_ISDX_ADD_REPLACE_SEL,
+				       VCAP_BIT_1);
+	if (ret)
+		return ret;
+
+	ret = vcap_rule_add_action_u32(vrule, VCAP_AF_ISDX_VAL, psfp_sfid);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static int sparx5_tc_flower_replace(struct net_device *ndev,
 				    struct flow_cls_offload *fco,
 				    struct vcap_admin *admin,
 				    bool ingress)
 {
+	struct sparx5_psfp_sf sf = { .max_sdu = SPX5_PSFP_SF_MAX_SDU };
+	struct netlink_ext_ack *extack = fco->common.extack;
+	int err, idx, tc_sg_idx = -1, tc_pol_idx = -1;
 	struct sparx5_port *port = netdev_priv(ndev);
 	struct sparx5_multiple_rules multi = {};
+	struct sparx5 *sparx5 = port->sparx5;
+	struct sparx5_psfp_sg sg = { 0 };
+	struct sparx5_psfp_fm fm = { 0 };
 	struct flow_action_entry *act;
 	struct vcap_control *vctrl;
 	struct flow_rule *frule;
 	struct vcap_rule *vrule;
 	u16 l3_proto;
-	int err, idx;
 
 	vctrl = port->sparx5->vcap_ctrl;
 
@@ -1033,6 +1171,26 @@ static int sparx5_tc_flower_replace(struct net_device *ndev,
 	frule = flow_cls_offload_flow_rule(fco);
 	flow_action_for_each(idx, act, &frule->action) {
 		switch (act->id) {
+		case FLOW_ACTION_GATE: {
+			err = sparx5_tc_flower_parse_act_gate(&sg, act, extack);
+			if (err < 0)
+				goto out;
+
+			tc_sg_idx = act->hw_index;
+
+			break;
+		}
+		case FLOW_ACTION_POLICE: {
+			err = sparx5_tc_flower_parse_act_police(&fm.pol, act,
+								extack);
+			if (err < 0)
+				goto out;
+
+			tc_pol_idx = fm.pol.idx;
+			sf.max_sdu = act->police.mtu;
+
+			break;
+		}
 		case FLOW_ACTION_TRAP:
 			if (admin->vtype != VCAP_TYPE_IS2 &&
 			    admin->vtype != VCAP_TYPE_ES2) {
@@ -1079,6 +1237,14 @@ static int sparx5_tc_flower_replace(struct net_device *ndev,
 		}
 	}
 
+	/* Setup PSFP */
+	if (tc_sg_idx >= 0 || tc_pol_idx >= 0) {
+		err = sparx5_tc_flower_psfp_setup(sparx5, vrule, tc_sg_idx,
+						  tc_pol_idx, &sg, &fm, &sf);
+		if (err)
+			goto out;
+	}
+
 	err = sparx5_tc_select_protocol_keyset(ndev, vrule, admin, l3_proto,
 					       &multi);
 	if (err) {
@@ -1107,19 +1273,86 @@ static int sparx5_tc_flower_replace(struct net_device *ndev,
 	return err;
 }
 
+static void sparx5_tc_free_psfp_resources(struct sparx5 *sparx5,
+					  struct vcap_rule *vrule)
+{
+	struct vcap_client_actionfield *afield;
+	u32 isdx, sfid, sgid, fmid;
+
+	/* Check if VCAP_AF_ISDX_VAL action is set for this rule - and if
+	 * it is used for stream and/or flow-meter classification.
+	 */
+	afield = vcap_find_actionfield(vrule, VCAP_AF_ISDX_VAL);
+	if (!afield)
+		return;
+
+	isdx = afield->data.u32.value;
+	sfid = sparx5_psfp_isdx_get_sf(sparx5, isdx);
+
+	if (!sfid)
+		return;
+
+	fmid = sparx5_psfp_isdx_get_fm(sparx5, isdx);
+	sgid = sparx5_psfp_sf_get_sg(sparx5, sfid);
+
+	if (fmid && sparx5_psfp_fm_del(sparx5, fmid) < 0)
+		pr_err("%s:%d Could not delete invalid fmid: %d", __func__,
+		       __LINE__, fmid);
+
+	if (sgid && sparx5_psfp_sg_del(sparx5, sgid) < 0)
+		pr_err("%s:%d Could not delete invalid sgid: %d", __func__,
+		       __LINE__, sgid);
+
+	if (sparx5_psfp_sf_del(sparx5, sfid) < 0)
+		pr_err("%s:%d Could not delete invalid sfid: %d", __func__,
+		       __LINE__, sfid);
+
+	sparx5_isdx_conf_set(sparx5, isdx, 0, 0);
+}
+
+static int sparx5_tc_free_rule_resources(struct net_device *ndev,
+					 struct vcap_control *vctrl,
+					 int rule_id)
+{
+	struct sparx5_port *port = netdev_priv(ndev);
+	struct sparx5 *sparx5 = port->sparx5;
+	struct vcap_rule *vrule;
+	int ret = 0;
+
+	vrule = vcap_get_rule(vctrl, rule_id);
+	if (!vrule || IS_ERR(vrule))
+		return -EINVAL;
+
+	sparx5_tc_free_psfp_resources(sparx5, vrule);
+
+	vcap_free_rule(vrule);
+	return ret;
+}
+
 static int sparx5_tc_flower_destroy(struct net_device *ndev,
 				    struct flow_cls_offload *fco,
 				    struct vcap_admin *admin)
 {
 	struct sparx5_port *port = netdev_priv(ndev);
+	int err = -ENOENT, count = 0, rule_id;
 	struct vcap_control *vctrl;
-	int err = -ENOENT, rule_id;
 
 	vctrl = port->sparx5->vcap_ctrl;
 	while (true) {
 		rule_id = vcap_lookup_rule_by_cookie(vctrl, fco->cookie);
 		if (rule_id <= 0)
 			break;
+		if (count == 0) {
+			/* Resources are attached to the first rule of
+			 * a set of rules. Only works if the rules are
+			 * in the correct order.
+			 */
+			err = sparx5_tc_free_rule_resources(ndev, vctrl,
+							    rule_id);
+			if (err)
+				pr_err("%s:%d: could not free resources %d\n",
+				       __func__, __LINE__, rule_id);
+		}
 		err = vcap_del_rule(vctrl, ndev, rule_id);
 		if (err) {
 			pr_err("%s:%d: could not delete rule %d\n",
drivers/net/ethernet/microchip/vcap/vcap_api.c +2 -1
index 660d7cd92fcc..6307d59f23da 100644
@@ -2755,7 +2755,7 @@ int vcap_rule_get_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
 EXPORT_SYMBOL_GPL(vcap_rule_get_key_u32);
 
 /* Find a client action field in a rule */
-static struct vcap_client_actionfield *
+struct vcap_client_actionfield *
 vcap_find_actionfield(struct vcap_rule *rule, enum vcap_action_field act)
 {
 	struct vcap_rule_internal *ri = (struct vcap_rule_internal *)rule;
@@ -2766,6 +2766,7 @@ vcap_find_actionfield(struct vcap_rule *rule, enum vcap_action_field act)
 			return caf;
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(vcap_find_actionfield);
 
 /* Check if the actionfield is already in the rule */
 static bool vcap_actionfield_unique(struct vcap_rule *rule,
drivers/net/ethernet/microchip/vcap/vcap_api_client.h +3 -0
index de29540fd190..417af9754bcc 100644
@@ -268,4 +268,7 @@ int vcap_rule_mod_action_u32(struct vcap_rule *rule,
 /* Get a 32 bit key field value and mask from the rule */
 int vcap_rule_get_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
 			  u32 *value, u32 *mask);
+
+struct vcap_client_actionfield *
+vcap_find_actionfield(struct vcap_rule *rule, enum vcap_action_field act);
 #endif /* __VCAP_API_CLIENT__ */
Signature · 1 line
2.34.1
author maintainer
#9 lore raw

PATCH 4/10 net: microchip: sparx5: add support for service policers

In reply to Daniel Machon

Add initial API for configuring policers. This patch add support for service policers.

---
 .../net/ethernet/microchip/sparx5/Makefile    |  2 +-
 .../ethernet/microchip/sparx5/sparx5_main.h   | 16 ++++++
 .../ethernet/microchip/sparx5/sparx5_police.c | 53 +++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_police.c
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
index b3de8490db38..9f35b0dc3212 100644
@@ -10,7 +10,7 @@ sparx5-switch-y  := sparx5_main.o sparx5_packet.o \
  sparx5_switchdev.o sparx5_calendar.o sparx5_ethtool.o sparx5_fdma.o \
  sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \
  sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \
- sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o
+ sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o sparx5_police.o
 
 sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o
 sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +16 -0
index daaaa670365b..c8bb50bbdcdf 100644
@@ -455,6 +455,22 @@ int sparx5_sdlb_group_del(struct sparx5 *sparx5, u32 group, u32 idx);
 
 void sparx5_sdlb_group_init(struct sparx5 *sparx5, u64 max_rate, u32 min_burst,
 			    u32 frame_size, u32 idx);
+/* sparx5_police.c */
+enum {
+	/* More policer types will be added later */
+	SPX5_POL_SERVICE
+};
+
+struct sparx5_policer {
+	u32 type;
+	u32 idx;
+	u64 rate;
+	u32 burst;
+	u32 group;
+	u8 event_mask;
+};
+
+int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol);
 
 /* Clock period in picoseconds */
 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
drivers/net/ethernet/microchip/sparx5/sparx5_police.c new file +53 -0

53 lines not on this page · raw message

Signature · 7 lines
2.34.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 9/10
#20 lore raw

Re: [PATCH net-next 09/10] net: microchip: sparx5: initialize PSFP

In reply to Daniel Machon
Quoted 3 lines · Daniel Machon

Initialize the SDLB's, stream gates and stream filters.

Quoted 11 lines
---
 .../ethernet/microchip/sparx5/sparx5_main.h    |  3 +++
 .../ethernet/microchip/sparx5/sparx5_psfp.c    | 18 ++++++++++++++++++
 .../net/ethernet/microchip/sparx5/sparx5_qos.c |  2 ++
 3 files changed, 23 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +0 -0
index cffed893fb7b..72e7928912eb 100644

drivers/net/ethernet/microchip/sparx5/sparx5_main.h int sparx5_sdlb_group_del(struct sparx5 *sparx5, u32 group, u32 idx); · line 459

Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +1 -0
@@ -456,6 +456,7 @@ int sparx5_sdlb_group_del(struct sparx5 *sparx5, u32 group, u32 idx);
 
 void sparx5_sdlb_group_init(struct sparx5 *sparx5, u64 max_rate, u32 min_burst,
 			    u32 frame_size, u32 idx);
+

nit: This hunk appears to belong in patch 4/9
No need to respin because of this, afaic.

Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +0 -0
 /* sparx5_police.c */
 enum {
 	/* More policer types will be added later */

...

Reviewed-by on v1 2/10
#4 lore raw

Re: [PATCH net-next 02/10] net: microchip: sparx5: add resource pools

In reply to Daniel Machon
Quoted 6 lines · Daniel Machon

Add resource pools and accessor functions. These pools can be queried by the driver, whenever a finite resource is required. Some resources can be reused, in which case an index and a reference count is used to keep track of users.

Reviewed-by on v1 3/10
#6 lore raw

Re: [PATCH net-next 03/10] net: microchip: sparx5: add support for Service Dual Leacky Buckets

In reply to Daniel Machon
Quoted 6 lines · Daniel Machon

Add support for Service Dual Leacky Buckets (SDLB), used to implement PSFP flow-meters. Buckets are linked together in a leak chain of a leak group. Leak groups a preconfigured to serve buckets within a certain rate interval.

...

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +0 -0
new file mode 100644
index 000000000000..f5267218caeb

...

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +9 -0
+static u32 sparx5_sdlb_group_get_next(struct sparx5 *sparx5, u32 group,
+				      u32 lb)
+{
+	u32 val;
+
+	val = spx5_rd(sparx5, ANA_AC_SDLB_XLB_NEXT(lb));
+
+	return ANA_AC_SDLB_XLB_NEXT_LBSET_NEXT_GET(val);
+}

...

drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c line 119

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +7 -0
+static u32 sparx5_sdlb_group_get_last(struct sparx5 *sparx5, u32 group)
+{
+	u32 itr, next;
+
+	itr = sparx5_sdlb_group_get_first(sparx5, group);
+
+	for (;;) {

Unbounded loops like this give me some apprehension. Will they always terminate?

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +7 -0
+		next = sparx5_sdlb_group_get_next(sparx5, group, itr);
+		if (itr == next)
+			return itr;
+
+		itr = next;
+	}
+}

...

Quoted 41 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +41 -0
+static int sparx5_sdlb_group_get_adjacent(struct sparx5 *sparx5, u32 group,
+					  u32 idx, u32 *prev, u32 *next,
+					  u32 *first)
+{
+	u32 itr;
+
+	*first = sparx5_sdlb_group_get_first(sparx5, group);
+	*prev = *first;
+	*next = *first;
+	itr = *first;
+
+	for (;;) {
+		*next = sparx5_sdlb_group_get_next(sparx5, group, itr);
+
+		if (itr == idx)
+			return 0; /* Found it */
+
+		if (itr == *next)
+			return -EINVAL; /* Was not found */
+
+		*prev = itr;
+		itr = *next;
+	}
+}
+
+static int sparx5_sdlb_group_get_count(struct sparx5 *sparx5, u32 group)
+{
+	u32 itr, next;
+	int count = 0;
+
+	itr = sparx5_sdlb_group_get_first(sparx5, group);
+
+	for (;;) {
+		next = sparx5_sdlb_group_get_next(sparx5, group, itr);
+		if (itr == next)
+			return count;
+
+		itr = next;
+		count++;
+	}
+}

...

Quoted 27 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +27 -0
+int sparx5_sdlb_group_get_by_index(struct sparx5 *sparx5, u32 idx, u32 *group)
+{
+	u32 itr, next;
+	int i;
+
+	for (i = 0; i < SPX5_SDLB_GROUP_CNT; i++) {
+		if (sparx5_sdlb_group_is_empty(sparx5, i))
+			continue;
+
+		itr = sparx5_sdlb_group_get_first(sparx5, i);
+
+		for (;;) {
+			next = sparx5_sdlb_group_get_next(sparx5, i, itr);
+
+			if (itr == idx) {
+				*group = i;
+				return 0; /* Found it */
+			}
+			if (itr == next)
+				break; /* Was not found */
+
+			itr = next;
+		}
+	}
+
+	return -EINVAL;
+}

...

Reviewed-by on v1 5/10
#12 lore raw

Re: [PATCH net-next 05/10] net: microchip: sparx5: add support for PSFP flow-meters

In reply to Daniel Machon
Quoted 8 lines · Daniel Machon

Add support for configuring PSFP flow-meters (IEEE 802.1Q-2018, 8.6.5.1.3).

The VCAP CLM (VCAP IS0 ingress classifier) classifies streams, identified by ISDX (Ingress Service Index, frame metadata), and maps ISDX to flow-meters. SDLB's provide the flow-meter parameters.

Reviewed-by on v1 7/10
#16 lore raw

Re: [PATCH net-next 07/10] net: microchip: sparx5: add support for PSFP stream gates

In reply to Daniel Machon
Quoted 11 lines · Daniel Machon

Add support for configuring PSFP stream gates (IEEE 802.1Q-2018, 8.6.5.1.2).

Stream gates are time-based policers used by PSFP. Frames are dropped based on the gate state (OPEN/ CLOSE), whose state will be altered based on the Gate Control List (GCL) and current PTP time. Apart from time-based policing, stream gates can alter egress queue selection for the frames that pass through the Gate. This is done through Internal Priority Selector (IPS). Stream gates are mapped from stream filters.

Reviewed-by on v1 8/10
#18 lore raw

Re: [PATCH net-next 08/10] net: microchip: sparx5: add support for PSFP stream filters

In reply to Daniel Machon
Quoted 8 lines · Daniel Machon

Add support for configuring PSFP stream filters (IEEE 802.1Q-2018, 8.6.5.1.1).

The VCAP CLM (VCAP IS0 ingress classifier) classifies streams, identified by ISDX (Ingress Service Index, frame metadata), and maps ISDX to streams.

author maintainer
#7 lore raw

Re: [PATCH net-next 03/10] net: microchip: sparx5: add support for Service Dual Leacky Buckets

In reply to Simon Horman

Hi Simon,

Thanks for reviewing my patches, appreciate it!

Quoted 10 lines

drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c line 119

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +7 -0
+static u32 sparx5_sdlb_group_get_last(struct sparx5 *sparx5, u32 group)
+{
+     u32 itr, next;
+
+     itr = sparx5_sdlb_group_get_first(sparx5, group);
+
+     for (;;) {

Unbounded loops like this give me some apprehension. Will they always terminate?

Yes, it will always terminate - unless the add() del() functions are buggy to begin with.

The end of the leak chain is marked by an index pointing to itself, and this is the exit condition I am looking for in the unbounded loop.

Quoted 84 lines
Quoted 8 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +7 -0
+             next = sparx5_sdlb_group_get_next(sparx5, group, itr);
+             if (itr == next)
+                     return itr;
+
+             itr = next;
+     }
+}

...

Quoted 41 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +41 -0
+static int sparx5_sdlb_group_get_adjacent(struct sparx5 *sparx5, u32 group,
+                                       u32 idx, u32 *prev, u32 *next,
+                                       u32 *first)
+{
+     u32 itr;
+
+     *first = sparx5_sdlb_group_get_first(sparx5, group);
+     *prev = *first;
+     *next = *first;
+     itr = *first;
+
+     for (;;) {
+             *next = sparx5_sdlb_group_get_next(sparx5, group, itr);
+
+             if (itr == idx)
+                     return 0; /* Found it */
+
+             if (itr == *next)
+                     return -EINVAL; /* Was not found */
+
+             *prev = itr;
+             itr = *next;
+     }
+}
+
+static int sparx5_sdlb_group_get_count(struct sparx5 *sparx5, u32 group)
+{
+     u32 itr, next;
+     int count = 0;
+
+     itr = sparx5_sdlb_group_get_first(sparx5, group);
+
+     for (;;) {
+             next = sparx5_sdlb_group_get_next(sparx5, group, itr);
+             if (itr == next)
+                     return count;
+
+             itr = next;
+             count++;
+     }
+}

...

Quoted 27 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +27 -0
+int sparx5_sdlb_group_get_by_index(struct sparx5 *sparx5, u32 idx, u32 *group)
+{
+     u32 itr, next;
+     int i;
+
+     for (i = 0; i < SPX5_SDLB_GROUP_CNT; i++) {
+             if (sparx5_sdlb_group_is_empty(sparx5, i))
+                     continue;
+
+             itr = sparx5_sdlb_group_get_first(sparx5, i);
+
+             for (;;) {
+                     next = sparx5_sdlb_group_get_next(sparx5, i, itr);
+
+                     if (itr == idx) {
+                             *group = i;
+                             return 0; /* Found it */
+                     }
+                     if (itr == next)
+                             break; /* Was not found */
+
+                     itr = next;
+             }
+     }
+
+     return -EINVAL;
+}

...

#23 lore raw
In reply to Daniel Machon
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Thu, 2 Feb 2023 11:43:45 +0100 you wrote:

================================================================================
Add support for Per-Stream Filtering and Policing (802.1Q-2018, 8.6.5.1).
================================================================================

The VCAP CLM (VCAP IS0 ingress classifier) classifies streams, identified by ISDX (Ingress Service Index, frame metadata), and maps ISDX to streams.

[...]

Here is the summary with links:
- [net-next,01/10] net: microchip: add registers needed for PSFP

    https://git.kernel.org/netdev/net-next/c/edad83e2ba1e
  - [net-next,02/10] net: microchip: sparx5: add resource pools
    https://git.kernel.org/netdev/net-next/c/bb535c0dbb6f
  - [net-next,03/10] net: microchip: sparx5: add support for Service Dual Leacky Buckets
    https://git.kernel.org/netdev/net-next/c/9bf508898983
  - [net-next,04/10] net: microchip: sparx5: add support for service policers
    https://git.kernel.org/netdev/net-next/c/1db82abf1969
  - [net-next,05/10] net: microchip: sparx5: add support for PSFP flow-meters
    https://git.kernel.org/netdev/net-next/c/d2185e79ba8f
  - [net-next,06/10] net: microchip: sparx5: add function for calculating PTP basetime
    https://git.kernel.org/netdev/net-next/c/9e02131ec272
  - [net-next,07/10] net: microchip: sparx5: add support for PSFP stream gates
    https://git.kernel.org/netdev/net-next/c/c70a5e2c3d18
  - [net-next,08/10] net: microchip: sparx5: add support for PSFP stream filters
    https://git.kernel.org/netdev/net-next/c/ae3e691f3442
  - [net-next,09/10] net: microchip: sparx5: initialize PSFP
    https://git.kernel.org/netdev/net-next/c/e116b19db202
  - [net-next,10/10] sparx5: add support for configuring PSFP via tc
    https://git.kernel.org/netdev/net-next/c/6ebf182bfdf1

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#8 lore raw

Re: [PATCH net-next 03/10] net: microchip: sparx5: add support for Service Dual Leacky Buckets

In reply to [email protected]
Quoted 15 lines · On Sun, Feb 05, 2023 at 08:11:02PM +0000, [email protected] wrote:

Hi Simon,

Thanks for reviewing my patches, appreciate it!

Quoted 10 lines

drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c line 119

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c new file +7 -0
+static u32 sparx5_sdlb_group_get_last(struct sparx5 *sparx5, u32 group)
+{
+     u32 itr, next;
+
+     itr = sparx5_sdlb_group_get_first(sparx5, group);
+
+     for (;;) {

Unbounded loops like this give me some apprehension. Will they always terminate?

Quoted 5 lines

Yes, it will always terminate - unless the add() del() functions are buggy to begin with.

The end of the leak chain is marked by an index pointing to itself, and this is the exit condition I am looking for in the unbounded loop.

Thanks for confirming, much appreciated.