Skip to content

Commit 6fb88aa

Browse files
pmachatakuba-moo
authored andcommitted
mlxsw: spectrum: Allow fetch-and-clear of flow counters
For the report_delta-like interface like a previous patch has added for collection of NH group statistics, it's easiest to read the counter and have the HW clear it right away. Thus, change mlxsw_sp_flow_counter_get() to take a bool indicating whether this should be done. Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://lore.kernel.org/r/6a096ede8ee92d5041e3832242c3bbc137198aba.1709901020.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 8acb480 commit 6fb88aa

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ MLXSW_ITEM32(tx, hdr, fid, 0x08, 16, 16);
176176
MLXSW_ITEM32(tx, hdr, type, 0x0C, 0, 4);
177177

178178
int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
179-
unsigned int counter_index, u64 *packets,
180-
u64 *bytes)
179+
unsigned int counter_index, bool clear,
180+
u64 *packets, u64 *bytes)
181181
{
182+
enum mlxsw_reg_mgpc_opcode op = clear ? MLXSW_REG_MGPC_OPCODE_CLEAR :
183+
MLXSW_REG_MGPC_OPCODE_NOP;
182184
char mgpc_pl[MLXSW_REG_MGPC_LEN];
183185
int err;
184186

185-
mlxsw_reg_mgpc_pack(mgpc_pl, counter_index, MLXSW_REG_MGPC_OPCODE_NOP,
187+
mlxsw_reg_mgpc_pack(mgpc_pl, counter_index, op,
186188
MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES);
187189
err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mgpc), mgpc_pl);
188190
if (err)

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ int mlxsw_sp_port_kill_vid(struct net_device *dev,
706706
int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
707707
u16 vid_end, bool is_member, bool untagged);
708708
int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
709-
unsigned int counter_index, u64 *packets,
710-
u64 *bytes);
709+
unsigned int counter_index, bool clear,
710+
u64 *packets, u64 *bytes);
711711
int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
712712
unsigned int *p_counter_index);
713713
void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,

drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
10241024
rulei = mlxsw_sp_acl_rule_rulei(rule);
10251025
if (rulei->counter_valid) {
10261026
err = mlxsw_sp_flow_counter_get(mlxsw_sp, rulei->counter_index,
1027-
&current_packets,
1027+
false, &current_packets,
10281028
&current_bytes);
10291029
if (err)
10301030
return err;

drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static int mlxsw_sp_mr_tcam_route_stats(struct mlxsw_sp *mlxsw_sp,
361361
struct mlxsw_sp_mr_tcam_route *route = route_priv;
362362

363363
return mlxsw_sp_flow_counter_get(mlxsw_sp, route->counter_index,
364-
packets, bytes);
364+
false, packets, bytes);
365365
}
366366

367367
static int

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
22512251
return -EINVAL;
22522252

22532253
return mlxsw_sp_flow_counter_get(mlxsw_sp, neigh_entry->counter_index,
2254-
p_counter, NULL);
2254+
false, p_counter, NULL);
22552255
}
22562256

22572257
static struct mlxsw_sp_neigh_entry *
@@ -3186,7 +3186,7 @@ int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
31863186
return -EINVAL;
31873187

31883188
return mlxsw_sp_flow_counter_get(mlxsw_sp, nh->counter_index,
3189-
p_counter, NULL);
3189+
false, p_counter, NULL);
31903190
}
31913191

31923192
struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,

0 commit comments

Comments
 (0)