Loading...
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
10static 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
43int 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}
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
10static 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 struct sparx5_sdlb_group *g;
15 u64 rate;
16
17 g = &sdlb_groups[pol->group];
18 idx = pol->idx;
19
20 rate = pol->rate * 1000;
21 burst = pol->burst;
22
23 pup_tokens = sparx5_sdlb_pup_token_get(sparx5, g->pup_interval, rate);
24 max_pup_tokens =
25 sparx5_sdlb_pup_token_get(sparx5, g->pup_interval, g->max_rate);
26
27 thres = DIV_ROUND_UP(burst, g->min_burst);
28
29 spx5_wr(ANA_AC_SDLB_PUP_TOKENS_PUP_TOKENS_SET(pup_tokens), sparx5,
30 ANA_AC_SDLB_PUP_TOKENS(idx, 0));
31
32 spx5_rmw(ANA_AC_SDLB_INH_CTRL_PUP_TOKENS_MAX_SET(max_pup_tokens),
33 ANA_AC_SDLB_INH_CTRL_PUP_TOKENS_MAX, sparx5,
34 ANA_AC_SDLB_INH_CTRL(idx, 0));
35
36 spx5_rmw(ANA_AC_SDLB_THRES_THRES_SET(thres), ANA_AC_SDLB_THRES_THRES,
37 sparx5, ANA_AC_SDLB_THRES(idx, 0));
38
39 return 0;
40}
41
42int sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol)
43{
44 /* More policer types will be added later */
45 switch (pol->type) {
46 case SPX5_POL_SERVICE:
47 return sparx5_policer_service_conf_set(sparx5, pol);
48 default:
49 break;
50 }
51
52 return 0;
53}