Skip to content

Commit adefefe

Browse files
Volodymyr Mytnykdavem330
authored andcommitted
net: prestera: acl: add rule stats support
Make flower to use counter API to get rule HW statistics. Co-developed-by: Serhiy Boiko <[email protected]> Signed-off-by: Serhiy Boiko <[email protected]> Signed-off-by: Volodymyr Mytnyk <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6e36c7b commit adefefe

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

drivers/net/ethernet/marvell/prestera/prestera_acl.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct prestera_acl_rule_entry {
3333
struct {
3434
u8 valid:1;
3535
} accept, drop, trap;
36+
struct {
37+
u32 id;
38+
struct prestera_counter_block *block;
39+
} counter;
3640
};
3741
};
3842

@@ -335,6 +339,10 @@ int prestera_acl_rule_add(struct prestera_switch *sw,
335339
rule->re_arg.vtcam_id = ruleset->vtcam_id;
336340
rule->re_key.prio = rule->priority;
337341

342+
/* setup counter */
343+
rule->re_arg.count.valid = true;
344+
rule->re_arg.count.client = PRESTERA_HW_COUNTER_CLIENT_LOOKUP_0;
345+
338346
rule->re = prestera_acl_rule_entry_find(sw->acl, &rule->re_key);
339347
err = WARN_ON(rule->re) ? -EEXIST : 0;
340348
if (err)
@@ -389,9 +397,20 @@ int prestera_acl_rule_get_stats(struct prestera_acl *acl,
389397
struct prestera_acl_rule *rule,
390398
u64 *packets, u64 *bytes, u64 *last_use)
391399
{
400+
u64 current_packets;
401+
u64 current_bytes;
402+
int err;
403+
404+
err = prestera_counter_stats_get(acl->sw->counter,
405+
rule->re->counter.block,
406+
rule->re->counter.id,
407+
&current_packets, &current_bytes);
408+
if (err)
409+
return err;
410+
411+
*packets = current_packets;
412+
*bytes = current_bytes;
392413
*last_use = jiffies;
393-
*packets = 0;
394-
*bytes = 0;
395414

396415
return 0;
397416
}
@@ -437,6 +456,12 @@ static int __prestera_acl_rule_entry2hw_add(struct prestera_switch *sw,
437456
act_hw[act_num].id = PRESTERA_ACL_RULE_ACTION_TRAP;
438457
act_num++;
439458
}
459+
/* counter */
460+
if (e->counter.block) {
461+
act_hw[act_num].id = PRESTERA_ACL_RULE_ACTION_COUNT;
462+
act_hw[act_num].count.id = e->counter.id;
463+
act_num++;
464+
}
440465

441466
return prestera_hw_vtcam_rule_add(sw, e->vtcam_id, e->key.prio,
442467
e->key.match.key, e->key.match.mask,
@@ -447,7 +472,8 @@ static void
447472
__prestera_acl_rule_entry_act_destruct(struct prestera_switch *sw,
448473
struct prestera_acl_rule_entry *e)
449474
{
450-
/* destroy action entry */
475+
/* counter */
476+
prestera_counter_put(sw->counter, e->counter.block, e->counter.id);
451477
}
452478

453479
void prestera_acl_rule_entry_destroy(struct prestera_acl *acl,
@@ -476,8 +502,22 @@ __prestera_acl_rule_entry_act_construct(struct prestera_switch *sw,
476502
e->drop.valid = arg->drop.valid;
477503
/* trap */
478504
e->trap.valid = arg->trap.valid;
505+
/* counter */
506+
if (arg->count.valid) {
507+
int err;
508+
509+
err = prestera_counter_get(sw->counter, arg->count.client,
510+
&e->counter.block,
511+
&e->counter.id);
512+
if (err)
513+
goto err_out;
514+
}
479515

480516
return 0;
517+
518+
err_out:
519+
__prestera_acl_rule_entry_act_destruct(sw, e);
520+
return -EINVAL;
481521
}
482522

483523
struct prestera_acl_rule_entry *

drivers/net/ethernet/marvell/prestera/prestera_acl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define _PRESTERA_ACL_H_
66

77
#include <linux/types.h>
8+
#include "prestera_counter.h"
89

910
#define PRESTERA_ACL_KEYMASK_PCL_ID 0x3FF
1011
#define PRESTERA_ACL_KEYMASK_PCL_ID_USER \
@@ -86,6 +87,10 @@ struct prestera_acl_rule_entry_arg {
8687
struct {
8788
u8 valid:1;
8889
} accept, drop, trap;
90+
struct {
91+
u8 valid:1;
92+
u32 client;
93+
} count;
8994
};
9095
};
9196

0 commit comments

Comments
 (0)