mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-05-24 10:39:52 +00:00
net: microchip: sparx5: Add support for rule count by cookie
This adds support for TC clients to get the packet count for a TC filter identified by its cookie. Signed-off-by: Steen Hegelund <steen.hegelund@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
0d4cda805a
commit
27d293ccee
3 changed files with 47 additions and 56 deletions
|
@ -35,11 +35,6 @@ struct sparx5_tc_flower_parse_usage {
|
||||||
unsigned int used_keys;
|
unsigned int used_keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sparx5_tc_rule_pkt_cnt {
|
|
||||||
u64 cookie;
|
|
||||||
u32 pkts;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These protocols have dedicated keysets in IS2 and a TC dissector
|
/* These protocols have dedicated keysets in IS2 and a TC dissector
|
||||||
* ETH_P_ARP does not have a TC dissector
|
* ETH_P_ARP does not have a TC dissector
|
||||||
*/
|
*/
|
||||||
|
@ -947,44 +942,21 @@ static int sparx5_tc_flower_destroy(struct net_device *ndev,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Collect packet counts from all rules with the same cookie */
|
|
||||||
static int sparx5_tc_rule_counter_cb(void *arg, struct vcap_rule *rule)
|
|
||||||
{
|
|
||||||
struct sparx5_tc_rule_pkt_cnt *rinfo = arg;
|
|
||||||
struct vcap_counter counter;
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
if (rule->cookie == rinfo->cookie) {
|
|
||||||
err = vcap_rule_get_counter(rule, &counter);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
rinfo->pkts += counter.value;
|
|
||||||
/* Reset the rule counter */
|
|
||||||
counter.value = 0;
|
|
||||||
vcap_rule_set_counter(rule, &counter);
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sparx5_tc_flower_stats(struct net_device *ndev,
|
static int sparx5_tc_flower_stats(struct net_device *ndev,
|
||||||
struct flow_cls_offload *fco,
|
struct flow_cls_offload *fco,
|
||||||
struct vcap_admin *admin)
|
struct vcap_admin *admin)
|
||||||
{
|
{
|
||||||
struct sparx5_port *port = netdev_priv(ndev);
|
struct sparx5_port *port = netdev_priv(ndev);
|
||||||
struct sparx5_tc_rule_pkt_cnt rinfo = {};
|
struct vcap_counter ctr = {};
|
||||||
struct vcap_control *vctrl;
|
struct vcap_control *vctrl;
|
||||||
ulong lastused = 0;
|
ulong lastused = 0;
|
||||||
u64 drops = 0;
|
|
||||||
u32 pkts = 0;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
rinfo.cookie = fco->cookie;
|
|
||||||
vctrl = port->sparx5->vcap_ctrl;
|
vctrl = port->sparx5->vcap_ctrl;
|
||||||
err = vcap_rule_iter(vctrl, sparx5_tc_rule_counter_cb, &rinfo);
|
err = vcap_get_rule_count_by_cookie(vctrl, &ctr, fco->cookie);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
pkts = rinfo.pkts;
|
flow_stats_update(&fco->stats, 0x0, ctr.value, 0, lastused,
|
||||||
flow_stats_update(&fco->stats, 0x0, pkts, drops, lastused,
|
|
||||||
FLOW_ACTION_HW_STATS_IMMEDIATE);
|
FLOW_ACTION_HW_STATS_IMMEDIATE);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2989,31 +2989,6 @@ void vcap_rule_set_counter_id(struct vcap_rule *rule, u32 counter_id)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(vcap_rule_set_counter_id);
|
EXPORT_SYMBOL_GPL(vcap_rule_set_counter_id);
|
||||||
|
|
||||||
/* Provide all rules via a callback interface */
|
|
||||||
int vcap_rule_iter(struct vcap_control *vctrl,
|
|
||||||
int (*callback)(void *, struct vcap_rule *), void *arg)
|
|
||||||
{
|
|
||||||
struct vcap_rule_internal *ri;
|
|
||||||
struct vcap_admin *admin;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = vcap_api_check(vctrl);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
/* Iterate all rules in each VCAP instance */
|
|
||||||
list_for_each_entry(admin, &vctrl->list, list) {
|
|
||||||
list_for_each_entry(ri, &admin->rules, list) {
|
|
||||||
ret = callback(arg, &ri->data);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(vcap_rule_iter);
|
|
||||||
|
|
||||||
int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr)
|
int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr)
|
||||||
{
|
{
|
||||||
struct vcap_rule_internal *ri = to_intrule(rule);
|
struct vcap_rule_internal *ri = to_intrule(rule);
|
||||||
|
@ -3105,6 +3080,48 @@ int vcap_rule_get_keysets(struct vcap_rule_internal *ri,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Collect packet counts from all rules with the same cookie */
|
||||||
|
int vcap_get_rule_count_by_cookie(struct vcap_control *vctrl,
|
||||||
|
struct vcap_counter *ctr, u64 cookie)
|
||||||
|
{
|
||||||
|
struct vcap_rule_internal *ri;
|
||||||
|
struct vcap_counter temp = {};
|
||||||
|
struct vcap_admin *admin;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = vcap_api_check(vctrl);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
/* Iterate all rules in each VCAP instance */
|
||||||
|
list_for_each_entry(admin, &vctrl->list, list) {
|
||||||
|
mutex_lock(&admin->lock);
|
||||||
|
list_for_each_entry(ri, &admin->rules, list) {
|
||||||
|
if (ri->data.cookie != cookie)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
err = vcap_read_counter(ri, &temp);
|
||||||
|
if (err)
|
||||||
|
goto unlock;
|
||||||
|
ctr->value += temp.value;
|
||||||
|
|
||||||
|
/* Reset the rule counter */
|
||||||
|
temp.value = 0;
|
||||||
|
temp.sticky = 0;
|
||||||
|
err = vcap_write_counter(ri, &temp);
|
||||||
|
if (err)
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
|
mutex_unlock(&admin->lock);
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
|
||||||
|
unlock:
|
||||||
|
mutex_unlock(&admin->lock);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(vcap_get_rule_count_by_cookie);
|
||||||
|
|
||||||
static int vcap_rule_mod_key(struct vcap_rule *rule,
|
static int vcap_rule_mod_key(struct vcap_rule *rule,
|
||||||
enum vcap_key_field key,
|
enum vcap_key_field key,
|
||||||
enum vcap_field_type ftype,
|
enum vcap_field_type ftype,
|
||||||
|
|
|
@ -202,6 +202,8 @@ int vcap_rule_add_action_u32(struct vcap_rule *rule,
|
||||||
enum vcap_action_field action, u32 value);
|
enum vcap_action_field action, u32 value);
|
||||||
|
|
||||||
/* VCAP rule counter operations */
|
/* VCAP rule counter operations */
|
||||||
|
int vcap_get_rule_count_by_cookie(struct vcap_control *vctrl,
|
||||||
|
struct vcap_counter *ctr, u64 cookie);
|
||||||
int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
|
int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
|
||||||
int vcap_rule_get_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
|
int vcap_rule_get_counter(struct vcap_rule *rule, struct vcap_counter *ctr);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue