Commit 1db82abf authored by Daniel Machon's avatar Daniel Machon Committed by David S. Miller

net: microchip: sparx5: add support for service policers

Add initial API for configuring policers. This patch add support for
service policers.
Signed-off-by: default avatarDaniel Machon <daniel.machon@microchip.com>
Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9bf50889
......@@ -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
......
......@@ -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)
......
// SPDX-License-Identifier: GPL-2.0+
/* Microchip Sparx5 Switch driver
*
* Copyright (c) 2023 Microchip Technology Inc. and its subsidiaries.
*/
#include "sparx5_main_regs.h"
#include "sparx5_main.h"
static int sparx5_policer_service_conf_set(struct sparx5 *sparx5,
struct sparx5_policer *pol)
{
u32 idx, pup_tokens, max_pup_tokens, burst, thres;
struct sparx5_sdlb_group *g;
u64 rate;
g = &sdlb_groups[pol->group];
idx = pol->idx;
rate = pol->rate * 1000;
burst = pol->burst;
pup_tokens = sparx5_sdlb_pup_token_get(sparx5, g->pup_interval, rate);
max_pup_tokens =
sparx5_sdlb_pup_token_get(sparx5, g->pup_interval, g->max_rate);
thres = DIV_ROUND_UP(burst, g->min_burst);
spx5_wr(ANA_AC_SDLB_PUP_TOKENS_PUP_TOKENS_SET(pup_tokens), sparx5,
ANA_AC_SDLB_PUP_TOKENS(idx, 0));
spx5_rmw(ANA_AC_SDLB_INH_CTRL_PUP_TOKENS_MAX_SET(max_pup_tokens),
ANA_AC_SDLB_INH_CTRL_PUP_TOKENS_MAX, sparx5,
ANA_AC_SDLB_INH_CTRL(idx, 0));
spx5_rmw(ANA_AC_SDLB_THRES_THRES_SET(thres), ANA_AC_SDLB_THRES_THRES,
sparx5, ANA_AC_SDLB_THRES(idx, 0));
return 0;
}
int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol)
{
/* More policer types will be added later */
switch (pol->type) {
case SPX5_POL_SERVICE:
return sparx5_policer_service_conf_set(sparx5, pol);
default:
break;
}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment