]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
mlxsw: spectrum_router: Add support for setting counters on neighbors
authorArkadi Sharshevsky <arkadis@mellanox.com>
Thu, 24 Aug 2017 06:40:08 +0000 (08:40 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 24 Aug 2017 16:33:16 +0000 (09:33 -0700)
Add support for setting counters on neighbors based on dpipe's host table
counter status. This patch also adds the ability for getting the counter
value, which will be used by the dpipe host table implementation in the
next patches.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/reg.h
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h

index bcf55f6f94f375c9992b9758e128d8487ee7a45f..11e290c34aafd53711d35c91af881ef295df4dea 100644 (file)
@@ -5054,6 +5054,14 @@ static inline void mlxsw_reg_rauht_pack6(char *payload,
        mlxsw_reg_rauht_dip6_memcpy_to(payload, dip);
 }
 
+static inline void mlxsw_reg_rauht_pack_counter(char *payload,
+                                               u64 counter_index)
+{
+       mlxsw_reg_rauht_counter_index_set(payload, counter_index);
+       mlxsw_reg_rauht_counter_set_type_set(payload,
+                                            MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES);
+}
+
 /* RALEU - Router Algorithmic LPM ECMP Update Register
  * ---------------------------------------------------
  * The register enables updating the ECMP section in the action for multiple
index 5332b8f0b3f71cc966098723c7ce7f6fef9ee25f..17fc98881642d10e0cf1f03dec9d0eac3111faa7 100644 (file)
@@ -386,8 +386,10 @@ int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
        err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mgpc), mgpc_pl);
        if (err)
                return err;
-       *packets = mlxsw_reg_mgpc_packet_counter_get(mgpc_pl);
-       *bytes = mlxsw_reg_mgpc_byte_counter_get(mgpc_pl);
+       if (packets)
+               *packets = mlxsw_reg_mgpc_packet_counter_get(mgpc_pl);
+       if (bytes)
+               *bytes = mlxsw_reg_mgpc_byte_counter_get(mgpc_pl);
        return 0;
 }
 
index 0b989e16a4243fde12718b8b92e577de407b8ef9..abccd84235ebd7786803f95c349039ea84e1c727 100644 (file)
@@ -901,6 +901,8 @@ struct mlxsw_sp_neigh_entry {
                                        * this neigh entry
                                        */
        struct list_head nexthop_neighs_list_node;
+       unsigned int counter_index;
+       bool counter_valid;
 };
 
 static const struct rhashtable_params mlxsw_sp_neigh_ht_params = {
@@ -945,6 +947,17 @@ u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry)
        return ntohl(*((__be32 *) n->primary_key));
 }
 
+int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
+                              struct mlxsw_sp_neigh_entry *neigh_entry,
+                              u64 *p_counter)
+{
+       if (!neigh_entry->counter_valid)
+               return -EINVAL;
+
+       return mlxsw_sp_flow_counter_get(mlxsw_sp, neigh_entry->counter_index,
+                                        p_counter, NULL);
+}
+
 static struct mlxsw_sp_neigh_entry *
 mlxsw_sp_neigh_entry_alloc(struct mlxsw_sp *mlxsw_sp, struct neighbour *n,
                           u16 rif)
@@ -985,6 +998,41 @@ mlxsw_sp_neigh_entry_remove(struct mlxsw_sp *mlxsw_sp,
                               mlxsw_sp_neigh_ht_params);
 }
 
+static bool
+mlxsw_sp_neigh4_counter_should_alloc(struct mlxsw_sp *mlxsw_sp)
+{
+       struct devlink *devlink;
+
+       devlink = priv_to_devlink(mlxsw_sp->core);
+       return devlink_dpipe_table_counter_enabled(devlink,
+                                                  MLXSW_SP_DPIPE_TABLE_NAME_HOST4);
+}
+
+static void
+mlxsw_sp_neigh_counter_alloc(struct mlxsw_sp *mlxsw_sp,
+                            struct mlxsw_sp_neigh_entry *neigh_entry)
+{
+       if (mlxsw_sp_neigh_entry_type(neigh_entry) != AF_INET ||
+           !mlxsw_sp_neigh4_counter_should_alloc(mlxsw_sp))
+               return;
+
+       if (mlxsw_sp_flow_counter_alloc(mlxsw_sp, &neigh_entry->counter_index))
+               return;
+
+       neigh_entry->counter_valid = true;
+}
+
+static void
+mlxsw_sp_neigh_counter_free(struct mlxsw_sp *mlxsw_sp,
+                           struct mlxsw_sp_neigh_entry *neigh_entry)
+{
+       if (!neigh_entry->counter_valid)
+               return;
+       mlxsw_sp_flow_counter_free(mlxsw_sp,
+                                  neigh_entry->counter_index);
+       neigh_entry->counter_valid = false;
+}
+
 static struct mlxsw_sp_neigh_entry *
 mlxsw_sp_neigh_entry_create(struct mlxsw_sp *mlxsw_sp, struct neighbour *n)
 {
@@ -1004,6 +1052,7 @@ mlxsw_sp_neigh_entry_create(struct mlxsw_sp *mlxsw_sp, struct neighbour *n)
        if (err)
                goto err_neigh_entry_insert;
 
+       mlxsw_sp_neigh_counter_alloc(mlxsw_sp, neigh_entry);
        list_add(&neigh_entry->rif_list_node, &rif->neigh_list);
 
        return neigh_entry;
@@ -1018,6 +1067,7 @@ mlxsw_sp_neigh_entry_destroy(struct mlxsw_sp *mlxsw_sp,
                             struct mlxsw_sp_neigh_entry *neigh_entry)
 {
        list_del(&neigh_entry->rif_list_node);
+       mlxsw_sp_neigh_counter_free(mlxsw_sp, neigh_entry);
        mlxsw_sp_neigh_entry_remove(mlxsw_sp, neigh_entry);
        mlxsw_sp_neigh_entry_free(neigh_entry);
 }
@@ -1323,6 +1373,9 @@ mlxsw_sp_router_neigh_entry_op4(struct mlxsw_sp *mlxsw_sp,
 
        mlxsw_reg_rauht_pack4(rauht_pl, op, neigh_entry->rif, neigh_entry->ha,
                              dip);
+       if (neigh_entry->counter_valid)
+               mlxsw_reg_rauht_pack_counter(rauht_pl,
+                                            neigh_entry->counter_index);
        mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(rauht), rauht_pl);
 }
 
@@ -1337,6 +1390,9 @@ mlxsw_sp_router_neigh_entry_op6(struct mlxsw_sp *mlxsw_sp,
 
        mlxsw_reg_rauht_pack6(rauht_pl, op, neigh_entry->rif, neigh_entry->ha,
                              dip);
+       if (neigh_entry->counter_valid)
+               mlxsw_reg_rauht_pack_counter(rauht_pl,
+                                            neigh_entry->counter_index);
        mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(rauht), rauht_pl);
 }
 
index 80ac032d64a2065a82847af0b0455f0ad0ddacbd..aafae469be3af3a74263c48951663d5e27a460e6 100644 (file)
@@ -69,5 +69,8 @@ u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
 #define mlxsw_sp_rif_neigh_for_each(neigh_entry, rif)                          \
        for (neigh_entry = mlxsw_sp_rif_neigh_next(rif, NULL); neigh_entry;     \
             neigh_entry = mlxsw_sp_rif_neigh_next(rif, neigh_entry))
+int mlxsw_sp_neigh_counter_get(struct mlxsw_sp *mlxsw_sp,
+                              struct mlxsw_sp_neigh_entry *neigh_entry,
+                              u64 *p_counter);
 
 #endif /* _MLXSW_ROUTER_H_*/