net: sparx5: add tc matchall port policer offload
Subsystems (4)
Daniel Machon
maintainerv3 cover net: sparx5: add tc matchall port policer offload
This series adds offload of tc matchall filters with a police action to the ingress port policers of Sparx5 and lan969x, which are both served by the sparx5 driver.
In hardware, each ingress port has four single-rate leaky bucket policers. A policer drops the frames that exceed its rate and burst. The four policers of a port share the pass and drop statistics counters of the port.
The driver uses one policer per port, because with more than one, the statistics reported to tc could not be attributed to the right policer. This matches lan966x and ocelot. The policer meters each frame without preamble and inter-frame gap, so the configured rate is a data rate, as tc police expects and as on lan966x and ocelot.
Since the policer meters all ingress frames on the port, only filters on chain 0 with protocol all are offloaded, and filters on shared blocks are rejected. A police action that is already offloaded as a port policer on another port is rejected too, since in software it is a single bucket for all of its users. Only drop is supported as the exceed action, and the police overhead parameter is not supported.
Patch #1 drops a redundant prefix from the existing POL_UPD_INT_CFG register macros.
Patch #2 adds the registers used by the port policer.
Patch #3 tracks whether the ingress block of a port is shared, and adds the per-port policer state.
Patch #4 adds the hardware programming of the port policer.
Patch #5 adds the tc matchall offload.
---
Changes in v3:
- No changes, resubmitted because of missing sashiko-nipa check on v2.
- Link to v2: https://lore.kernel.org/r/20261102-b4-lan966x-pci-fdma-sparx5-lan969x-port-policers-v2-0-3bd47ec1b227@microchip.com
Changes in v2:
- Patch #4: meter the data rate, not the line rate, by setting the gap
to 0 instead of 20 bytes. Fix the commit message, which wrongly said
that lan966x and ocelot meter the line rate.
- Patch #4: take queue_stats_lock around the existing ethtool read of
port stat counter 0, since reading the LSB latches the MSB.
- Patch #4: correct the comment on the traffic type mask.
- Patch #4: reject a packets-per-second police as unsupported before
checking for a missing byte rate, so the right message is reported.
- Patch #5: reject a police action that is already offloaded as a port
policer on another port.
- Link to v1: https://lore.kernel.org/r/20261009-b4-lan966x-pci-fdma-sparx5-lan969x-port-policers-v1-0-4916708a7ea2@microchip.com
---
Daniel Machon (5):
net: sparx5: Drop redundant POL_ prefix from POL_UPD_INT_CFG
net: sparx5: Add registers used by the port policer
net: sparx5: Track shared tc blocks and per-port policer state
net: sparx5: Add hardware programming for the port policer
net: sparx5: Offload tc port policers via matchall
.../microchip/sparx5/lan969x/lan969x_regs.c | 7 + .../net/ethernet/microchip/sparx5/sparx5_ethtool.c | 6 + .../net/ethernet/microchip/sparx5/sparx5_main.c | 6 +- .../net/ethernet/microchip/sparx5/sparx5_main.h | 39 +- .../ethernet/microchip/sparx5/sparx5_main_regs.h | 117 +++++- .../net/ethernet/microchip/sparx5/sparx5_police.c | 431 ++++++++++++++++++++- drivers/net/ethernet/microchip/sparx5/sparx5_qos.c | 4 + .../net/ethernet/microchip/sparx5/sparx5_regs.c | 7 + .../net/ethernet/microchip/sparx5/sparx5_regs.h | 7 + drivers/net/ethernet/microchip/sparx5/sparx5_tc.c | 14 +- .../ethernet/microchip/sparx5/sparx5_tc_matchall.c | 39 ++ 11 files changed, 663 insertions(+), 14 deletions(-)
---
base-commit: 7b6ab4dbc156e2f96419715130b3d5738a306c93
change-id: 20260930-b4-lan966x-pci-fdma-sparx5-lan969x-port-policers-474610756e26
Best regards,
Signature · 1 line
Daniel Machon <[email protected]>
Daniel Machon
maintainerPATCH v3 1/5 net: sparx5: Drop redundant POL_ prefix from POL_UPD_INT_CFG
The macros for the ANA_AC_POL:POL_UPD_INT_CFG register are named ANA_AC_POL_POL_UPD_INT_CFG*, repeating the POL_ prefix that is already part of the target name.
Rename them to ANA_AC_POL_UPD_INT_CFG*, so that the port policer registers added in the next patch can use the same short form.
No functional change.
--- drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 6 +++--- drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +3 -3
@@ -616,10 +616,10 @@ static int sparx5_init_coreclock(struct sparx5 *sparx5) sparx5, HSCH_TAS_STATEMACHINE_CFG); -spx5_rmw (ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_SET (pol_upd_int), -ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT , +spx5_rmw (ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT_SET (pol_upd_int), +ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT , sparx5, -ANA_AC_POL_POL_UPD_INT_CFG ); +ANA_AC_POL_UPD_INT_CFG );return 0 ; }
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +6 -6
@@ -939,15 +939,15 @@ extern const struct sparx5_regs *regs;FIELD_GET (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_MAC_ETYPE_STICKY , x) /* ANA_AC_POL:POL_ALL_CFG:POL_UPD_INT_CFG */ -#define ANA_AC_POL_POL_UPD_INT_CFG \ +#define ANA_AC_POL_UPD_INT_CFG \ __REG(TARGET_ANA_AC_POL, 0, 1, regs->gaddr[GA_ANA_AC_POL_POL_ALL_CFG], \ 0, 1, 1160, 1148, 0, 1, 4) -#define ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT GENMASK(9, 0) -#define ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_SET (x)\ - FIELD_PREP(ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT, x) -#define ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_GET (x)\ - FIELD_GET(ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT, x) +#define ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT GENMASK(9, 0) +#define ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT_SET (x)\ + FIELD_PREP(ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT, x) +#define ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT_GET (x)\ + FIELD_GET(ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT, x)/* ANA_AC_POL:COMMON_BDLB:DLB_CTRL */ #define ANA_AC_POL_BDLB_DLB_CTRL \
Signature · 1 line
2.34.1
Re: [PATCH net-next v3 1/5] net: sparx5: Drop redundant POL_ prefix from POL_UPD_INT_CFG
Quoted 50 lines · Daniel Machon
The macros for the ANA_AC_POL:POL_UPD_INT_CFG register are named ANA_AC_POL_POL_UPD_INT_CFG*, repeating the
POL_prefix that is already part of the target name.Rename them to ANA_AC_POL_UPD_INT_CFG*, so that the port policer registers added in the next patch can use the same short form.
No functional change.
Signed-off-by Daniel Machon <[email protected]>--- drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 6 +++--- drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-)drivers/net/ethernet/microchip/sparx5/sparx5_main.c +3
-3@@ -616,10 +616,10 @@ static int sparx5_init_coreclock(struct sparx5 *sparx5) sparx5, HSCH_TAS_STATEMACHINE_CFG); -spx5_rmw (ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_SET (pol_upd_int), -ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT , +spx5_rmw (ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT_SET (pol_upd_int), +ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT , sparx5, -ANA_AC_POL_POL_UPD_INT_CFG ); +ANA_AC_POL_UPD_INT_CFG );return 0 ; }drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +1
-4@@ -939,15 +939,15 @@ extern const struct sparx5_regs *regs;FIELD_GET (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_MAC_ETYPE_STICKY , x) /* ANA_AC_POL:POL_ALL_CFG:POL_UPD_INT_CFG */ -#define ANA_AC_POL_POL_UPD_INT_CFG \ +#define ANA_AC_POL_UPD_INT_CFG \ __REG(TARGET_ANA_AC_POL, 0, 1, regs->gaddr[GA_ANA_AC_POL_POL_ALL_CFG], \ 0, 1, 1160, 1148, 0, 1, 4) -#define ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT GENMASK(9, 0) -#define ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_SET (x)\ - FIELD_PREP(ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT, x)
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h extern const struct sparx5_regs *regs; · line 953
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +5
-2-#define ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_GET (x)\ - FIELD_GET(ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT, x) +#define ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT GENMASK(9, 0) +#define ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT_SET (x)\ + FIELD_PREP(ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT, x) +#define ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT_GET (x)\ + FIELD_GET(ANA_AC_POL_UPD_INT_CFG_POL_UPD_INT, x)/* ANA_AC_POL:COMMON_BDLB:DLB_CTRL */ #define ANA_AC_POL_BDLB_DLB_CTRL \
Daniel Machon
maintainerPATCH v3 2/5 net: sparx5: Add registers used by the port policer
In reply to Daniel MachonAdd the registers used to configure the ingress port policers and to read back their statistics, on both sparx5 and lan969x: the POL_PORT_CFG and POL_PORT_CTRL groups of ANA_AC_POL, the shared POL_ALL_CFG register, and the MSB part of the ANA_AC port statistics counters.
--- .../microchip/sparx5/lan969x/lan969x_regs.c | 7 ++ .../ethernet/microchip/sparx5/sparx5_main_regs.h | 105 +++++++++++++++++++++ .../net/ethernet/microchip/sparx5/sparx5_regs.c | 7 ++ .../net/ethernet/microchip/sparx5/sparx5_regs.h | 7 ++ 4 files changed, 126 insertions(+)
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c +7 -0
@@ -28,6 +28,9 @@ const unsigned int lan969x_rcnt[RCNT_LAST] = { [RC_ANA_AC_OWN_UPSID] = 1, [RC_ANA_ACL_VCAP_S2_CFG] = 35, [RC_ANA_ACL_OWN_UPSID] = 1, + [RC_ANA_AC_POL_PORT_THRES_CFG_0] = 140, + [RC_ANA_AC_POL_PORT_THRES_CFG_1] = 140, + [RC_ANA_AC_POL_PORT_RATE_CFG] = 140, [RC_ANA_CL_OWN_UPSID] = 1, [RC_ANA_L2_OWN_UPSID] = 1, [RC_ASM_PORT_CFG] = 32,
@@ -70,6 +73,8 @@ const unsigned int lan969x_gaddr[GADDR_LAST] = { [GA_ANA_ACL_CNT_B] = 4096, [GA_ANA_ACL_STICKY] = 10852, [GA_ANA_AC_POL_POL_ALL_CFG] = 17504, + [GA_ANA_AC_POL_POL_PORT_CFG] = 0, + [GA_ANA_AC_POL_POL_PORT_CTRL] = 16384, [GA_ANA_AC_POL_COMMON_BDLB] = 19464, [GA_ANA_AC_POL_COMMON_BUM_SLB] = 19472, [GA_ANA_AC_SDLB_LBGRP_TBL] = 31788,
@@ -121,6 +126,7 @@ const unsigned int lan969x_gcnt[GCNT_LAST] = { [GC_ANA_ACL_KEY_SEL] = 99, [GC_ANA_ACL_CNT_A] = 1024, [GC_ANA_ACL_CNT_B] = 1024, + [GC_ANA_AC_POL_POL_PORT_CTRL] = 35, [GC_ANA_AC_SDLB_LBGRP_TBL] = 5, [GC_ANA_AC_SDLB_LBSET_TBL] = 496, [GC_ANA_CL_PORT] = 35,
@@ -186,6 +192,7 @@ const unsigned int lan969x_fsize[FSIZE_LAST] = { [FW_ANA_AC_TSN_SF_STATUS_TSN_SFID] = 8, [FW_ANA_AC_SG_ACCESS_CTRL_SGID] = 8, [FW_ANA_AC_PORT_SGE_CFG_MASK] = 17, + [FW_ANA_AC_POL_PORT_RATE_CFG_PORT_RATE] = 19, [FW_ANA_AC_SDLB_XLB_START_LBSET_START] = 9, [FW_ANA_AC_SDLB_LBGRP_MISC_THRES_SHIFT] = 3, [FW_ANA_AC_SDLB_LBGRP_STATE_TBL_PUP_LBSET_NEXT] = 9,
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +105 -0
123 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_regs.c +7 -0
@@ -28,6 +28,9 @@ const unsigned int sparx5_rcnt[RCNT_LAST] = { [RC_ANA_AC_OWN_UPSID] = 3, [RC_ANA_ACL_VCAP_S2_CFG] = 70, [RC_ANA_ACL_OWN_UPSID] = 3, + [RC_ANA_AC_POL_PORT_THRES_CFG_0] = 280, + [RC_ANA_AC_POL_PORT_THRES_CFG_1] = 280, + [RC_ANA_AC_POL_PORT_RATE_CFG] = 280, [RC_ANA_CL_OWN_UPSID] = 3, [RC_ANA_L2_OWN_UPSID] = 3, [RC_ASM_PORT_CFG] = 67,
@@ -70,6 +73,8 @@ const unsigned int sparx5_gaddr[GADDR_LAST] = { [GA_ANA_ACL_CNT_B] = 16384, [GA_ANA_ACL_STICKY] = 36408, [GA_ANA_AC_POL_POL_ALL_CFG] = 75968, + [GA_ANA_AC_POL_POL_PORT_CFG] = 65536, + [GA_ANA_AC_POL_POL_PORT_CTRL] = 73728, [GA_ANA_AC_POL_COMMON_BDLB] = 79048, [GA_ANA_AC_POL_COMMON_BUM_SLB] = 79056, [GA_ANA_AC_SDLB_LBGRP_TBL] = 295468,
@@ -121,6 +126,7 @@ const unsigned int sparx5_gcnt[GCNT_LAST] = { [GC_ANA_ACL_KEY_SEL] = 134, [GC_ANA_ACL_CNT_A] = 4096, [GC_ANA_ACL_CNT_B] = 4096, + [GC_ANA_AC_POL_POL_PORT_CTRL] = 70, [GC_ANA_AC_SDLB_LBGRP_TBL] = 10, [GC_ANA_AC_SDLB_LBSET_TBL] = 4616, [GC_ANA_CL_PORT] = 70,
@@ -186,6 +192,7 @@ const unsigned int sparx5_fsize[FSIZE_LAST] = { [FW_ANA_AC_TSN_SF_STATUS_TSN_SFID] = 10, [FW_ANA_AC_SG_ACCESS_CTRL_SGID] = 10, [FW_ANA_AC_PORT_SGE_CFG_MASK] = 16, + [FW_ANA_AC_POL_PORT_RATE_CFG_PORT_RATE] = 20, [FW_ANA_AC_SDLB_XLB_START_LBSET_START] = 13, [FW_ANA_AC_SDLB_LBGRP_MISC_THRES_SHIFT] = 5, [FW_ANA_AC_SDLB_LBGRP_STATE_TBL_PUP_LBSET_NEXT] = 13,
drivers/net/ethernet/microchip/sparx5/sparx5_regs.h +7 -0
@@ -36,6 +36,9 @@ enum sparx5_rcnt_enum {RC_ANA_AC_OWN_UPSID ,RC_ANA_ACL_VCAP_S2_CFG ,RC_ANA_ACL_OWN_UPSID , +RC_ANA_AC_POL_PORT_THRES_CFG_0 , +RC_ANA_AC_POL_PORT_THRES_CFG_1 , +RC_ANA_AC_POL_PORT_RATE_CFG ,RC_ANA_CL_OWN_UPSID ,RC_ANA_L2_OWN_UPSID , RC_ASM_PORT_CFG,
@@ -79,6 +82,8 @@ enum sparx5_gaddr_enum {GA_ANA_ACL_CNT_B ,GA_ANA_ACL_STICKY ,GA_ANA_AC_POL_POL_ALL_CFG , +GA_ANA_AC_POL_POL_PORT_CFG , +GA_ANA_AC_POL_POL_PORT_CTRL ,GA_ANA_AC_POL_COMMON_BDLB ,GA_ANA_AC_POL_COMMON_BUM_SLB , GA_ANA_AC_SDLB_LBGRP_TBL,
@@ -131,6 +136,7 @@ enum sparx5_gcnt_enum {GC_ANA_ACL_KEY_SEL ,GC_ANA_ACL_CNT_A ,GC_ANA_ACL_CNT_B , +GC_ANA_AC_POL_POL_PORT_CTRL ,GC_ANA_AC_SDLB_LBGRP_TBL ,GC_ANA_AC_SDLB_LBSET_TBL , GC_ANA_CL_PORT,
@@ -199,6 +205,7 @@ enum sparx5_fsize_enum {FW_ANA_AC_TSN_SF_STATUS_TSN_SFID ,FW_ANA_AC_SG_ACCESS_CTRL_SGID ,FW_ANA_AC_PORT_SGE_CFG_MASK , +FW_ANA_AC_POL_PORT_RATE_CFG_PORT_RATE ,FW_ANA_AC_SDLB_XLB_START_LBSET_START ,FW_ANA_AC_SDLB_LBGRP_MISC_THRES_SHIFT , FW_ANA_AC_SDLB_LBGRP_STATE_TBL_PUP_LBSET_NEXT,
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH v3 3/5 net: sparx5: Track shared tc blocks and per-port policer state
In reply to Daniel MachonA police action on a shared tc block applies one aggregate rate to all ports bound to the block, which a per-port policer cannot implement. The port policer offload therefore needs to know whether the ingress block of a port is shared.
Add struct sparx5_port_tc to each port, holding a flag that records whether the ingress block is shared, and the state of the four policers of the port.
--- drivers/net/ethernet/microchip/sparx5/sparx5_main.h | 16 ++++++++++++++++ drivers/net/ethernet/microchip/sparx5/sparx5_tc.c | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +16 -0
@@ -207,6 +207,21 @@ struct sparx5_port_config {u32 sd_sgpio; }; +#define SPX5_POLICERS_PER_PORT 4/* Number of ingress port policers */ + +struct sparx5_port_policer { +struct flow_stats prev; +struct flow_stats stats; +/* Port policers hold the client reference (cookie) */ +unsigned long policer; +}; + +struct sparx5_port_tc { +/* Ingress uses a shared filter block */ +bool ingress_block_shared; +struct sparx5_port_policer port_policer[SPX5_POLICERS_PER_PORT ]; +}; +struct sparx5_port {struct net_device *ndev;struct sparx5 *sparx5;
@@ -230,6 +245,7 @@ struct sparx5_port {enum sparx5_vlan_port_type vlan_type;u32 custom_etype;bool vlan_aware; +struct sparx5_port_tc tc;struct hrtimer inj_timer;/* ptp */ u8 ptp_cmd;
drivers/net/ethernet/microchip/sparx5/sparx5_tc.c +12 -2
@@ -47,7 +47,9 @@ static int sparx5_tc_block_cb_egress(enum tc_setup_type type,static int sparx5_tc_setup_block (struct net_device *ndev,struct flow_block_offload *fbo) { +struct sparx5_port *port =netdev_priv (ndev);flow_setup_cb_t *cb; +int err;if (fbo->binder_type ==FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ) cb = sparx5_tc_block_cb_ingress;
@@ -56,8 +58,16 @@ static int sparx5_tc_setup_block(struct net_device *ndev,else return -EOPNOTSUPP ; -return flow_block_cb_setup_simple (fbo, &sparx5_block_cb_list, - cb, ndev, ndev, false); + err =flow_block_cb_setup_simple (fbo, &sparx5_block_cb_list, + cb, ndev, ndev, false); +if (err) +return err; + +if (fbo->binder_type ==FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ) + port->tc.ingress_block_shared = + fbo->command ==FLOW_BLOCK_BIND && fbo->block_shared; + +return 0 ; } static void sparx5_tc_get_layer_and_idx(struct sparx5 *sparx5, u32 parent,
Signature · 1 line
2.34.1
Daniel Machon
maintainerPATCH v3 4/5 net: sparx5: Add hardware programming for the port policer
In reply to Daniel MachonEach ingress port has four single-rate leaky bucket policers in ANA_AC_POL. A policer is configured with a rate, in units of 25040 bit/s, and a burst, in units of 8192 bytes, and drops the frames that exceed it. The four policers of a port share the pass and drop statistics counters of the port, which are 40 bits wide. Before use, all policers must be initialized through the force-init bits in POL_ALL_CFG.
Add support for programming a port policer, and for reading back its pass and drop counts. Do not include preamble and inter-frame gap in the metered frame size, so that the configured rate is a data rate, as tc police expects and as on lan966x and ocelot. Since the statistics counters are shared, use only one policer per port. Initialize the policers and select the events counted by the shared counters at probe.
Read the counters from the periodic stats worker as well, and accumulate them into 64-bit totals, so that a wrap of the 40-bit counters is not lost between two reads of the tc stats. Take queue_stats_lock around the existing ethtool read of the shared counter 0, since reading the LSB of a counter latches its MSB.
The port policer is not reachable from tc yet; the next patch adds that.
--- .../net/ethernet/microchip/sparx5/sparx5_ethtool.c | 6 + .../net/ethernet/microchip/sparx5/sparx5_main.h | 22 +- .../net/ethernet/microchip/sparx5/sparx5_police.c | 404 ++++++++++++++++++++- drivers/net/ethernet/microchip/sparx5/sparx5_qos.c | 4 + 4 files changed, 432 insertions(+), 4 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c +6 -0
@@ -231,9 +231,14 @@ static void sparx5_get_ana_ac_stats_stats(struct sparx5 *sparx5, int portno) {u64 *portstats = &sparx5->stats[portno * sparx5->num_stats]; +/* Serialize with the port policer, which reads the LSB and MSB of the +* port stat counters as a pair. +*/ +mutex_lock (&sparx5->queue_stats_lock);sparx5_update_counter (&portstats[spx5_stats_ana_ac_port_stat_lsb_cnt],spx5_rd (sparx5,ANA_AC_PORT_STAT_LSB_CNT (portno,SPX5_PORT_POLICER_DROPS ))); +mutex_unlock (&sparx5->queue_stats_lock); } static void sparx5_get_dev_phy_stats(u64 *portstats, void __iomem *inst, u32
@@ -1116,6 +1121,7 @@ static void sparx5_update_port_stats(struct sparx5 *sparx5, int portno)sparx5_get_asm_stats (sparx5, portno);sparx5_get_ana_ac_stats_stats (sparx5, portno);sparx5_get_queue_sys_stats (sparx5, portno); +sparx5_port_policer_stats_poll (sparx5->ports[portno]); }static void sparx5_update_stats (struct sparx5 *sparx5)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +19 -3
@@ -19,6 +19,7 @@#include <linux/hrtimer.h> #include <linux/debugfs.h> #include <net/flow_offload.h> +#include <net/pkt_cls.h> #include <fdma_api.h>
@@ -210,8 +211,11 @@ struct sparx5_port_config {#define SPX5_POLICERS_PER_PORT 4/* Number of ingress port policers */ struct sparx5_port_policer { -struct flow_stats prev; +/* Last raw values of the 40-bit hardware counters */ +struct flow_stats raw; +/* 64-bit totals, and the totals last reported to tc */ struct flow_stats stats; +struct flow_stats prev;/* Port policers hold the client reference (cookie) */ unsigned long policer; };
@@ -298,6 +302,10 @@ struct sparx5_mall_mirror_entry {struct sparx5_port *port; }; +struct sparx5_mall_port_policer_entry { +struct flow_action_police police; +}; +struct sparx5_mall_entry {struct list_head list;struct sparx5_port *port;
@@ -306,6 +314,7 @@ struct sparx5_mall_entry {bool ingress;union {struct sparx5_mall_mirror_entry mirror; +struct sparx5_mall_port_policer_entry port_policer; }; };
@@ -655,8 +664,8 @@ void sparx5_sdlb_group_init(struct sparx5 *sparx5, u64 max_rate, u32 min_burst,/* sparx5_police.c */ enum { -/* More policer types will be added later */ -SPX5_POL_SERVICE +SPX5_POL_SERVICE , +SPX5_POL_PORT , };struct sparx5_policer {
@@ -669,6 +678,13 @@ struct sparx5_policer { };int sparx5_policer_conf_set (struct sparx5 *sparx5,struct sparx5_policer *pol); +int sparx5_port_policer_init (struct sparx5 *sparx5); +int sparx5_add_port_policer (struct sparx5_mall_entry *entry, +struct netlink_ext_ack *extack); +int sparx5_delete_port_policer (struct sparx5_mall_entry *entry); +int sparx5_update_port_policer_stats (struct net_device *ndev, +struct tc_cls_matchall_offload *tmo); +void sparx5_port_policer_stats_poll (struct sparx5_port *port);/* sparx5_psfp.c */ #define SPX5_PSFP_GCE_CNT 4
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +403 -1
425 lines not on this page · raw message
drivers/net/ethernet/microchip/sparx5/sparx5_qos.c +4 -0
@@ -449,6 +449,10 @@ int sparx5_qos_init(struct sparx5 *sparx5) {int ret; + ret =sparx5_port_policer_init (sparx5); +if (ret) +return ret; + ret =sparx5_leak_groups_init (sparx5);if (ret <0 )return ret;
Signature · 1 line
2.34.1
Re: [PATCH net-next v3 4/5] net: sparx5: Add hardware programming for the port policer
Quoted 38 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +36
-0+int sparx5_add_port_policer (struct sparx5_mall_entry *entry, +struct netlink_ext_ack *extack) +{ +struct flow_action_police *police = &entry->port_policer.police; +struct sparx5_port *port = entry->port; +struct sparx5 *sparx5 = port->sparx5; +struct sparx5_policer pol = {0 }; +int idx, err; + +if (!entry->ingress) { +NL_SET_ERR_MSG_MOD (extack, +"Policer is not supported on egress" ); +return -EOPNOTSUPP ; + } + +if (entry->port->tc.ingress_block_shared) { +NL_SET_ERR_MSG_MOD (extack, +"Policer is not supported on shared ingress blocks" ); +return -EOPNOTSUPP ; + } + +if (police->exceed.act_id !=FLOW_ACTION_DROP ) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + +if (police->notexceed.act_id !=FLOW_ACTION_PIPE && + police->notexceed.act_id !=FLOW_ACTION_ACCEPT ) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + +if (police->peakrate_bytes_ps || police->avrate || + police->overhead) {
drivers/net/ethernet/microchip/sparx5/sparx5_police.c int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol) · line 349
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +10
-0+NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + +if (police->rate_pkt_ps) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + }
Curious if we can have distinct messages for several unrelated checks sharing the extack "Policer parameters are not supported";
Quoted 19 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +19
-0+ +if (!police->rate_bytes_ps) { +NL_SET_ERR_MSG_MOD (extack, +"Policer requires a rate" ); +return -EOPNOTSUPP ; + } + +if (police->burst >ANA_AC_POL_PORT_THRES_CFG_0_PORT_THRES0 * +SPX5_POLICER_BYTE_BURST_UNIT ) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + +if (police->rate_bytes_ps > +div_u64 ((u64 )ANA_AC_POL_PORT_RATE_CFG_PORT_RATE * +SPX5_POLICER_RATE_UNIT ,BITS_PER_BYTE )) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" );
drivers/net/ethernet/microchip/sparx5/sparx5_police.c int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol) · line 378
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +10
-0+return -EOPNOTSUPP ; + } + + idx =sparx5_alloc_port_policer_idx (port, entry->cookie); +if (idx <0 ) { +NL_SET_ERR_MSG_MOD (extack, +"Only one port policer per port is supported" ); +return idx; + } +
Any reason why police->mtu isn't checked? In software, frames longer than the police MTU always take the exceed action. Is this intentionally skipped here?
Quoted 16 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +16
-0+ pol.type =SPX5_POL_PORT ; + pol.rate = police->rate_bytes_ps *BITS_PER_BYTE ; + pol.burst = police->burst; + pol.idx = port->portno *SPX5_POLICERS_PER_PORT + idx; + +sparx5_init_port_policer_stats (port, idx); + + err =sparx5_policer_conf_set (sparx5, &pol); +if (err) +return err; + + port->tc.port_policer[idx].policer = entry->cookie; + +return 0 ; +} +
Daniel Machon
maintainerRe: [PATCH net-next v3 4/5] net: sparx5: Add hardware programming for the port policer
Hi Mohsin,
Thanks for reviewing.
Quoted 43 lines
Quoted 43 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +41
-0+int sparx5_add_port_policer (struct sparx5_mall_entry *entry, +struct netlink_ext_ack *extack) +{ +struct flow_action_police *police = &entry->port_policer.police; +struct sparx5_port *port = entry->port; +struct sparx5 *sparx5 = port->sparx5; +struct sparx5_policer pol = {0 }; +int idx, err; + +if (!entry->ingress) { +NL_SET_ERR_MSG_MOD (extack, +"Policer is not supported on egress" ); +return -EOPNOTSUPP ; + } + +if (entry->port->tc.ingress_block_shared) { +NL_SET_ERR_MSG_MOD (extack, +"Policer is not supported on shared ingress blocks" ); +return -EOPNOTSUPP ; + } + +if (police->exceed.act_id !=FLOW_ACTION_DROP ) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + +if (police->notexceed.act_id !=FLOW_ACTION_PIPE && + police->notexceed.act_id !=FLOW_ACTION_ACCEPT ) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + +if (police->peakrate_bytes_ps || police->avrate || + police->overhead) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } +
Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol) · line 349
Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +5
-0+if (police->rate_pkt_ps) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + }Curious if we can have distinct messages for several unrelated checks sharing the extack "Policer parameters are not supported";
So the rationale here is that the checks with their own message are about where the policer is attached (egress, shared block, another port, a second policer), or a missing rate, while the shared message covers police parameters the hardware cannot offload.
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +25
-0+ +if (!police->rate_bytes_ps) { +NL_SET_ERR_MSG_MOD (extack, +"Policer requires a rate" ); +return -EOPNOTSUPP ; + } + +if (police->burst >ANA_AC_POL_PORT_THRES_CFG_0_PORT_THRES0 * +SPX5_POLICER_BYTE_BURST_UNIT ) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + +if (police->rate_bytes_ps > +div_u64 ((u64 )ANA_AC_POL_PORT_RATE_CFG_PORT_RATE * +SPX5_POLICER_RATE_UNIT ,BITS_PER_BYTE )) { +NL_SET_ERR_MSG_MOD (extack, +"Policer parameters are not supported" ); +return -EOPNOTSUPP ; + } + + idx =sparx5_alloc_port_policer_idx (port, entry->cookie); +if (idx <0 ) { + NL_SET_ERR_MSG_MOD(extack,
Quoted 8 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol) · line 378
Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +4
-0+ "Only one port policer per port is supported"); +return idx; + } +Any reason why
police->mtuisn't checked? In software, frames longer than the police MTU always take the exceed action. Is this intentionally skipped here?
Yes, it is intentional. The port policer has no frame length limit of its own, so it cannot enforce the mtu. It seems to be very common for other drivers to ignore this too.
Quoted 18 lines
Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +6
-0+ pol.type =SPX5_POL_PORT ; + pol.rate = police->rate_bytes_ps *BITS_PER_BYTE ; + pol.burst = police->burst; + pol.idx = port->portno *SPX5_POLICERS_PER_PORT + idx; + +sparx5_init_port_policer_stats (port, idx);drivers/net/ethernet/microchip/sparx5/sparx5_police.c int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol) · line 394
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +10
-0+ + err =sparx5_policer_conf_set (sparx5, &pol); +if (err) +return err; + + port->tc.port_policer[idx].policer = entry->cookie; + +return 0 ; +} +
/Daniel
Daniel Machon
maintainerPATCH v3 5/5 net: sparx5: Offload tc port policers via matchall
In reply to Daniel MachonOffload a tc matchall filter with a police action to the port policer:
tc qdisc add dev <eth> clsact
tc filter add dev <eth> ingress matchall skip_sw \
action police rate <bps> burst <bytes> conform-exceed drop
The port policer meters all ingress frames on the port, so offload the filter only on ingress, on chain 0, with protocol all, and on a block that is not shared. Only drop is supported as the exceed action, and only one policer per port. A police action shared between ports is a single bucket in software, which the per-port policers cannot express, so reject a police action that is already offloaded as a port policer on another port. Report the pass and drop counts through the matchall stats.
--- .../net/ethernet/microchip/sparx5/sparx5_main.h | 3 ++ .../net/ethernet/microchip/sparx5/sparx5_police.c | 27 +++++++++++++++ .../ethernet/microchip/sparx5/sparx5_tc_matchall.c | 39 ++++++++++++++++++++++ 3 files changed, 69 insertions(+)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +3 -0
@@ -218,6 +218,8 @@ struct sparx5_port_policer {struct flow_stats prev;/* Port policers hold the client reference (cookie) */ unsigned long policer; +/* tc police action, the same for every filter bound to it */ +unsigned long act_cookie; };struct sparx5_port_tc {
@@ -304,6 +306,7 @@ struct sparx5_mall_mirror_entry {struct sparx5_mall_port_policer_entry {struct flow_action_police police; +unsigned long act_cookie; };struct sparx5_mall_entry {
drivers/net/ethernet/microchip/sparx5/sparx5_police.c +27 -0
@@ -301,6 +301,25 @@ int sparx5_update_port_policer_stats(struct net_device *ndev,return 0 ; } +static bool sparx5_port_policer_act_in_use (struct sparx5_port *port, +unsigned long act_cookie) +{ +struct sparx5 *sparx5 = port->sparx5; +struct sparx5_port *other; +int i; + +for (i =0 ; i < sparx5->data->consts->n_ports; i++) { + other = sparx5->ports[i]; +if (!other || other == port) +continue ; +if (other->tc.port_policer[0 ].policer && + other->tc.port_policer[0 ].act_cookie == act_cookie) +return true; + } + +return false; +} +int sparx5_add_port_policer (struct sparx5_mall_entry *entry,struct netlink_ext_ack *extack) {
@@ -322,6 +341,13 @@ int sparx5_add_port_policer(struct sparx5_mall_entry *entry,return -EOPNOTSUPP ; } +if (sparx5_port_policer_act_in_use (port, + entry->port_policer.act_cookie)) { +NL_SET_ERR_MSG_MOD (extack, +"Police action shared between ports is not supported" ); +return -EOPNOTSUPP ; + } +if (police->exceed.act_id !=FLOW_ACTION_DROP ) {NL_SET_ERR_MSG_MOD (extack,"Policer parameters are not supported" );
@@ -388,6 +414,7 @@ int sparx5_add_port_policer(struct sparx5_mall_entry *entry,return err; port->tc.port_policer[idx].policer = entry->cookie; + port->tc.port_policer[idx].act_cookie = entry->port_policer.act_cookie;return 0 ; }
drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c +39 -0
@@ -43,6 +43,14 @@ sparx5_tc_matchall_parse_mirror_action(struct sparx5_mall_entry *entry, entry->mirror.port =netdev_priv (action->dev); } +static void +sparx5_tc_matchall_parse_port_policer_action (struct sparx5_mall_entry *entry, +struct flow_action_entry *action) +{ + entry->port_policer.police = action->police; + entry->port_policer.act_cookie = action->cookie; +} +static int sparx5_tc_matchall_replace (struct net_device *ndev,struct tc_cls_matchall_offload *tmo,bool ingress)
@@ -98,6 +106,30 @@ static int sparx5_tc_matchall_replace(struct net_device *ndev, }/* Get baseline stats for this port */ sparx5_mirror_stats (mall_entry, &tmo->stats); +break ; +case FLOW_ACTION_POLICE : +if (tmo->common.protocol !=htons (ETH_P_ALL )) { +NL_SET_ERR_MSG_MOD (tmo->common.extack, +"Policer is only supported with protocol all" ); +kfree (mall_entry); +return -EOPNOTSUPP ; + } + +if (tmo->common.chain_index) { +NL_SET_ERR_MSG_MOD (tmo->common.extack, +"Policer is only supported on chain 0" ); +kfree (mall_entry); +return -EOPNOTSUPP ; + } + +sparx5_tc_matchall_parse_port_policer_action (mall_entry, + action); + err =sparx5_add_port_policer (mall_entry, tmo->common.extack); +if (err) { +kfree (mall_entry); +return err; + } +break ;case FLOW_ACTION_GOTO : err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev,
@@ -151,6 +183,11 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev,if (entry->type ==FLOW_ACTION_MIRRED ) {sparx5_mirror_del (entry); + }else if (entry->type ==FLOW_ACTION_POLICE ) { + err =sparx5_delete_port_policer (entry); +if (err) +NL_SET_ERR_MSG_MOD (tmo->common.extack, +"Could not delete port policer" ); }else if (entry->type ==FLOW_ACTION_GOTO ) { err =vcap_enable_lookups (sparx5->vcap_ctrl, ndev,0 ,0 , tmo->cookie, false);
@@ -180,6 +217,8 @@ static int sparx5_tc_matchall_stats(struct net_device *ndev,if (entry->type ==FLOW_ACTION_MIRRED ) {sparx5_mirror_stats (entry, &tmo->stats); + }else if (entry->type ==FLOW_ACTION_POLICE ) { +sparx5_update_port_policer_stats (ndev, tmo); }else {NL_SET_ERR_MSG_MOD (tmo->common.extack,"Unsupported action" );return -EOPNOTSUPP ;
Signature · 1 line
2.34.1
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 5 Nov 2026 14:19:34 +0100 you wrote:
This series adds offload of tc matchall filters with a police action to the ingress port policers of Sparx5 and lan969x, which are both served by the sparx5 driver.
In hardware, each ingress port has four single-rate leaky bucket policers. A policer drops the frames that exceed its rate and burst. The four policers of a port share the pass and drop statistics counters of the port.
[...]
Here is the summary with links:
- [net-next,v3,1/5] net: sparx5: Drop redundant POL_ prefix from POL_UPD_INT_CFG
https://git.kernel.org/netdev/net-next/c/de6c6d0fe1a2 - [net-next,v3,2/5] net: sparx5: Add registers used by the port policer https://git.kernel.org/netdev/net-next/c/08543a66f15a - [net-next,v3,3/5] net: sparx5: Track shared tc blocks and per-port policer state https://git.kernel.org/netdev/net-next/c/54d7dad1a3bb - [net-next,v3,4/5] net: sparx5: Add hardware programming for the port policer https://git.kernel.org/netdev/net-next/c/b18f7b93e0f7 - [net-next,v3,5/5] net: sparx5: Offload tc port policers via matchall https://git.kernel.org/netdev/net-next/c/a53151fbbcd6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html