| 1 |
// SPDX-License-Identifier: GPL-2.0+ |
| 2 |
/* Microchip Sparx5 Switch driver |
| 3 |
* |
| 4 |
* Copyright (c) 2023 Microchip Technology Inc. and its subsidiaries. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "sparx5_main_regs.h" |
| 8 |
#include "sparx5_main.h" |
| 9 |
|
| 10 |
static int sparx5_policer_service_conf_set(struct sparx5 *sparx5, |
| 11 |
struct sparx5_policer *pol) |
| 12 |
{ |
| 13 |
u32 idx, pup_tokens, max_pup_tokens, burst, thres; |
| 14 |
const struct sparx5_ops *ops = sparx5->data->ops; |
| 15 |
struct sparx5_sdlb_group *g; |
| 16 |
u64 rate; |
| 17 |
|
| 18 |
g = ops->get_sdlb_group(pol->group); |
| 19 |
idx = pol->idx; |
| 20 |
|
| 21 |
rate = pol->rate * 1000; |
| 22 |
burst = pol->burst; |
| 23 |
|
| 24 |
pup_tokens = sparx5_sdlb_pup_token_get(sparx5, g->pup_interval, rate); |
| 25 |
max_pup_tokens = |
| 26 |
sparx5_sdlb_pup_token_get(sparx5, g->pup_interval, g->max_rate); |
| 27 |
|
| 28 |
thres = DIV_ROUND_UP(burst, g->min_burst); |
| 29 |
|
| 30 |
spx5_wr(ANA_AC_SDLB_PUP_TOKENS_PUP_TOKENS_SET(pup_tokens), sparx5, |
| 31 |
ANA_AC_SDLB_PUP_TOKENS(idx, 0)); |
| 32 |
|
| 33 |
spx5_rmw(ANA_AC_SDLB_INH_CTRL_PUP_TOKENS_MAX_SET(max_pup_tokens), |
| 34 |
ANA_AC_SDLB_INH_CTRL_PUP_TOKENS_MAX, sparx5, |
| 35 |
ANA_AC_SDLB_INH_CTRL(idx, 0)); |
| 36 |
|
| 37 |
spx5_rmw(ANA_AC_SDLB_THRES_THRES_SET(thres), ANA_AC_SDLB_THRES_THRES, |
| 38 |
sparx5, ANA_AC_SDLB_THRES(idx, 0)); |
| 39 |
|
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol) |
| 44 |
{ |
| 45 |
/* More policer types will be added later */ |
| 46 |
switch (pol->type) { |
| 47 |
case SPX5_POL_SERVICE: |
| 48 |
return sparx5_policer_service_conf_set(sparx5, pol); |
| 49 |
default: |
| 50 |
break; |
| 51 |
} |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |