Commit f6fc5b49 authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-Add-router-adjacency-dpipe-table'

Jiri Pirko says:

====================
mlxsw: Add router adjacency dpipe table

Arkadi says:

This patchset adds router adjacency dpipe table support. This will provide
the ability to observe the hardware offloaded IPv4/6 nexthops.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 390e96ec 427e652a
...@@ -4549,6 +4549,27 @@ MLXSW_ITEM32(reg, ratr, ipip_ipv4_udip, 0x18, 0, 32); ...@@ -4549,6 +4549,27 @@ MLXSW_ITEM32(reg, ratr, ipip_ipv4_udip, 0x18, 0, 32);
*/ */
MLXSW_ITEM32(reg, ratr, ipip_ipv6_ptr, 0x1C, 0, 24); MLXSW_ITEM32(reg, ratr, ipip_ipv6_ptr, 0x1C, 0, 24);
enum mlxsw_reg_flow_counter_set_type {
/* No count */
MLXSW_REG_FLOW_COUNTER_SET_TYPE_NO_COUNT = 0x00,
/* Count packets and bytes */
MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES = 0x03,
/* Count only packets */
MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS = 0x05,
};
/* reg_ratr_counter_set_type
* Counter set type for flow counters
* Access: RW
*/
MLXSW_ITEM32(reg, ratr, counter_set_type, 0x28, 24, 8);
/* reg_ratr_counter_index
* Counter index for flow counters
* Access: RW
*/
MLXSW_ITEM32(reg, ratr, counter_index, 0x28, 0, 24);
static inline void static inline void
mlxsw_reg_ratr_pack(char *payload, mlxsw_reg_ratr_pack(char *payload,
enum mlxsw_reg_ratr_op op, bool valid, enum mlxsw_reg_ratr_op op, bool valid,
...@@ -4576,6 +4597,20 @@ static inline void mlxsw_reg_ratr_ipip4_entry_pack(char *payload, u32 ipv4_udip) ...@@ -4576,6 +4597,20 @@ static inline void mlxsw_reg_ratr_ipip4_entry_pack(char *payload, u32 ipv4_udip)
mlxsw_reg_ratr_ipip_ipv4_udip_set(payload, ipv4_udip); mlxsw_reg_ratr_ipip_ipv4_udip_set(payload, ipv4_udip);
} }
static inline void mlxsw_reg_ratr_counter_pack(char *payload, u64 counter_index,
bool counter_enable)
{
enum mlxsw_reg_flow_counter_set_type set_type;
if (counter_enable)
set_type = MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES;
else
set_type = MLXSW_REG_FLOW_COUNTER_SET_TYPE_NO_COUNT;
mlxsw_reg_ratr_counter_index_set(payload, counter_index);
mlxsw_reg_ratr_counter_set_type_set(payload, set_type);
}
/* RICNT - Router Interface Counter Register /* RICNT - Router Interface Counter Register
* ----------------------------------------- * -----------------------------------------
* The RICNT register retrieves per port performance counters * The RICNT register retrieves per port performance counters
...@@ -5297,15 +5332,6 @@ enum mlxsw_reg_rauht_trap_id { ...@@ -5297,15 +5332,6 @@ enum mlxsw_reg_rauht_trap_id {
*/ */
MLXSW_ITEM32(reg, rauht, trap_id, 0x60, 0, 9); MLXSW_ITEM32(reg, rauht, trap_id, 0x60, 0, 9);
enum mlxsw_reg_flow_counter_set_type {
/* No count */
MLXSW_REG_FLOW_COUNTER_SET_TYPE_NO_COUNT = 0x00,
/* Count packets and bytes */
MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES = 0x03,
/* Count only packets */
MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS = 0x05,
};
/* reg_rauht_counter_set_type /* reg_rauht_counter_set_type
* Counter set type for flow counters * Counter set type for flow counters
* Access: RW * Access: RW
......
...@@ -56,5 +56,6 @@ static inline void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp) ...@@ -56,5 +56,6 @@ static inline void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp)
#define MLXSW_SP_DPIPE_TABLE_NAME_ERIF "mlxsw_erif" #define MLXSW_SP_DPIPE_TABLE_NAME_ERIF "mlxsw_erif"
#define MLXSW_SP_DPIPE_TABLE_NAME_HOST4 "mlxsw_host4" #define MLXSW_SP_DPIPE_TABLE_NAME_HOST4 "mlxsw_host4"
#define MLXSW_SP_DPIPE_TABLE_NAME_HOST6 "mlxsw_host6" #define MLXSW_SP_DPIPE_TABLE_NAME_HOST6 "mlxsw_host6"
#define MLXSW_SP_DPIPE_TABLE_NAME_ADJ "mlxsw_adj"
#endif /* _MLXSW_PIPELINE_H_*/ #endif /* _MLXSW_PIPELINE_H_*/
...@@ -78,6 +78,7 @@ struct mlxsw_sp_router { ...@@ -78,6 +78,7 @@ struct mlxsw_sp_router {
struct rhashtable neigh_ht; struct rhashtable neigh_ht;
struct rhashtable nexthop_group_ht; struct rhashtable nexthop_group_ht;
struct rhashtable nexthop_ht; struct rhashtable nexthop_ht;
struct list_head nexthop_list;
struct { struct {
struct mlxsw_sp_lpm_tree *trees; struct mlxsw_sp_lpm_tree *trees;
unsigned int tree_count; unsigned int tree_count;
...@@ -1316,7 +1317,7 @@ mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif, ...@@ -1316,7 +1317,7 @@ mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
typeof(*neigh_entry), typeof(*neigh_entry),
rif_list_node); rif_list_node);
} }
if (neigh_entry->rif_list_node.next == &rif->neigh_list) if (list_is_last(&neigh_entry->rif_list_node, &rif->neigh_list))
return NULL; return NULL;
return list_next_entry(neigh_entry, rif_list_node); return list_next_entry(neigh_entry, rif_list_node);
} }
...@@ -2028,6 +2029,7 @@ struct mlxsw_sp_nexthop_key { ...@@ -2028,6 +2029,7 @@ struct mlxsw_sp_nexthop_key {
struct mlxsw_sp_nexthop { struct mlxsw_sp_nexthop {
struct list_head neigh_list_node; /* member of neigh entry list */ struct list_head neigh_list_node; /* member of neigh entry list */
struct list_head rif_list_node; struct list_head rif_list_node;
struct list_head router_list_node;
struct mlxsw_sp_nexthop_group *nh_grp; /* pointer back to the group struct mlxsw_sp_nexthop_group *nh_grp; /* pointer back to the group
* this belongs to * this belongs to
*/ */
...@@ -2050,6 +2052,8 @@ struct mlxsw_sp_nexthop { ...@@ -2050,6 +2052,8 @@ struct mlxsw_sp_nexthop {
struct mlxsw_sp_neigh_entry *neigh_entry; struct mlxsw_sp_neigh_entry *neigh_entry;
struct mlxsw_sp_ipip_entry *ipip_entry; struct mlxsw_sp_ipip_entry *ipip_entry;
}; };
unsigned int counter_index;
bool counter_valid;
}; };
struct mlxsw_sp_nexthop_group { struct mlxsw_sp_nexthop_group {
...@@ -2066,6 +2070,112 @@ struct mlxsw_sp_nexthop_group { ...@@ -2066,6 +2070,112 @@ struct mlxsw_sp_nexthop_group {
#define nh_rif nexthops[0].rif #define nh_rif nexthops[0].rif
}; };
void mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh)
{
struct devlink *devlink;
devlink = priv_to_devlink(mlxsw_sp->core);
if (!devlink_dpipe_table_counter_enabled(devlink,
MLXSW_SP_DPIPE_TABLE_NAME_ADJ))
return;
if (mlxsw_sp_flow_counter_alloc(mlxsw_sp, &nh->counter_index))
return;
nh->counter_valid = true;
}
void mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh)
{
if (!nh->counter_valid)
return;
mlxsw_sp_flow_counter_free(mlxsw_sp, nh->counter_index);
nh->counter_valid = false;
}
int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh, u64 *p_counter)
{
if (!nh->counter_valid)
return -EINVAL;
return mlxsw_sp_flow_counter_get(mlxsw_sp, nh->counter_index,
p_counter, NULL);
}
struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,
struct mlxsw_sp_nexthop *nh)
{
if (!nh) {
if (list_empty(&router->nexthop_list))
return NULL;
else
return list_first_entry(&router->nexthop_list,
typeof(*nh), router_list_node);
}
if (list_is_last(&nh->router_list_node, &router->nexthop_list))
return NULL;
return list_next_entry(nh, router_list_node);
}
bool mlxsw_sp_nexthop_offload(struct mlxsw_sp_nexthop *nh)
{
return nh->offloaded;
}
unsigned char *mlxsw_sp_nexthop_ha(struct mlxsw_sp_nexthop *nh)
{
if (!nh->offloaded)
return NULL;
return nh->neigh_entry->ha;
}
int mlxsw_sp_nexthop_indexes(struct mlxsw_sp_nexthop *nh, u32 *p_adj_index,
u32 *p_adj_hash_index)
{
struct mlxsw_sp_nexthop_group *nh_grp = nh->nh_grp;
u32 adj_hash_index = 0;
int i;
if (!nh->offloaded || !nh_grp->adj_index_valid)
return -EINVAL;
*p_adj_index = nh_grp->adj_index;
for (i = 0; i < nh_grp->count; i++) {
struct mlxsw_sp_nexthop *nh_iter = &nh_grp->nexthops[i];
if (nh_iter == nh)
break;
if (nh_iter->offloaded)
adj_hash_index++;
}
*p_adj_hash_index = adj_hash_index;
return 0;
}
struct mlxsw_sp_rif *mlxsw_sp_nexthop_rif(struct mlxsw_sp_nexthop *nh)
{
return nh->rif;
}
bool mlxsw_sp_nexthop_group_has_ipip(struct mlxsw_sp_nexthop *nh)
{
struct mlxsw_sp_nexthop_group *nh_grp = nh->nh_grp;
int i;
for (i = 0; i < nh_grp->count; i++) {
struct mlxsw_sp_nexthop *nh_iter = &nh_grp->nexthops[i];
if (nh_iter->type == MLXSW_SP_NEXTHOP_TYPE_IPIP)
return true;
}
return false;
}
static struct fib_info * static struct fib_info *
mlxsw_sp_nexthop4_group_fi(const struct mlxsw_sp_nexthop_group *nh_grp) mlxsw_sp_nexthop4_group_fi(const struct mlxsw_sp_nexthop_group *nh_grp)
{ {
...@@ -2323,8 +2433,8 @@ static int mlxsw_sp_adj_index_mass_update(struct mlxsw_sp *mlxsw_sp, ...@@ -2323,8 +2433,8 @@ static int mlxsw_sp_adj_index_mass_update(struct mlxsw_sp *mlxsw_sp,
return 0; return 0;
} }
static int mlxsw_sp_nexthop_mac_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index, int mlxsw_sp_nexthop_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
struct mlxsw_sp_nexthop *nh) struct mlxsw_sp_nexthop *nh)
{ {
struct mlxsw_sp_neigh_entry *neigh_entry = nh->neigh_entry; struct mlxsw_sp_neigh_entry *neigh_entry = nh->neigh_entry;
char ratr_pl[MLXSW_REG_RATR_LEN]; char ratr_pl[MLXSW_REG_RATR_LEN];
...@@ -2333,6 +2443,11 @@ static int mlxsw_sp_nexthop_mac_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index, ...@@ -2333,6 +2443,11 @@ static int mlxsw_sp_nexthop_mac_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
true, MLXSW_REG_RATR_TYPE_ETHERNET, true, MLXSW_REG_RATR_TYPE_ETHERNET,
adj_index, neigh_entry->rif); adj_index, neigh_entry->rif);
mlxsw_reg_ratr_eth_entry_pack(ratr_pl, neigh_entry->ha); mlxsw_reg_ratr_eth_entry_pack(ratr_pl, neigh_entry->ha);
if (nh->counter_valid)
mlxsw_reg_ratr_counter_pack(ratr_pl, nh->counter_index, true);
else
mlxsw_reg_ratr_counter_pack(ratr_pl, 0, false);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ratr), ratr_pl); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ratr), ratr_pl);
} }
...@@ -2367,7 +2482,7 @@ mlxsw_sp_nexthop_group_update(struct mlxsw_sp *mlxsw_sp, ...@@ -2367,7 +2482,7 @@ mlxsw_sp_nexthop_group_update(struct mlxsw_sp *mlxsw_sp,
if (nh->update || reallocate) { if (nh->update || reallocate) {
switch (nh->type) { switch (nh->type) {
case MLXSW_SP_NEXTHOP_TYPE_ETH: case MLXSW_SP_NEXTHOP_TYPE_ETH:
err = mlxsw_sp_nexthop_mac_update err = mlxsw_sp_nexthop_update
(mlxsw_sp, adj_index, nh); (mlxsw_sp, adj_index, nh);
break; break;
case MLXSW_SP_NEXTHOP_TYPE_IPIP: case MLXSW_SP_NEXTHOP_TYPE_IPIP:
...@@ -2784,6 +2899,9 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp, ...@@ -2784,6 +2899,9 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp,
if (err) if (err)
return err; return err;
mlxsw_sp_nexthop_counter_alloc(mlxsw_sp, nh);
list_add_tail(&nh->router_list_node, &mlxsw_sp->router->nexthop_list);
if (!dev) if (!dev)
return 0; return 0;
...@@ -2807,6 +2925,8 @@ static void mlxsw_sp_nexthop4_fini(struct mlxsw_sp *mlxsw_sp, ...@@ -2807,6 +2925,8 @@ static void mlxsw_sp_nexthop4_fini(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh) struct mlxsw_sp_nexthop *nh)
{ {
mlxsw_sp_nexthop4_type_fini(mlxsw_sp, nh); mlxsw_sp_nexthop4_type_fini(mlxsw_sp, nh);
list_del(&nh->router_list_node);
mlxsw_sp_nexthop_counter_free(mlxsw_sp, nh);
mlxsw_sp_nexthop_remove(mlxsw_sp, nh); mlxsw_sp_nexthop_remove(mlxsw_sp, nh);
} }
...@@ -4044,6 +4164,9 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp, ...@@ -4044,6 +4164,9 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp,
nh->nh_grp = nh_grp; nh->nh_grp = nh_grp;
memcpy(&nh->gw_addr, &rt->rt6i_gateway, sizeof(nh->gw_addr)); memcpy(&nh->gw_addr, &rt->rt6i_gateway, sizeof(nh->gw_addr));
mlxsw_sp_nexthop_counter_alloc(mlxsw_sp, nh);
list_add_tail(&nh->router_list_node, &mlxsw_sp->router->nexthop_list);
if (!dev) if (!dev)
return 0; return 0;
...@@ -4056,6 +4179,8 @@ static void mlxsw_sp_nexthop6_fini(struct mlxsw_sp *mlxsw_sp, ...@@ -4056,6 +4179,8 @@ static void mlxsw_sp_nexthop6_fini(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh) struct mlxsw_sp_nexthop *nh)
{ {
mlxsw_sp_nexthop6_type_fini(mlxsw_sp, nh); mlxsw_sp_nexthop6_type_fini(mlxsw_sp, nh);
list_del(&nh->router_list_node);
mlxsw_sp_nexthop_counter_free(mlxsw_sp, nh);
} }
static bool mlxsw_sp_rt6_is_gateway(const struct mlxsw_sp *mlxsw_sp, static bool mlxsw_sp_rt6_is_gateway(const struct mlxsw_sp *mlxsw_sp,
...@@ -5990,6 +6115,7 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp) ...@@ -5990,6 +6115,7 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
if (err) if (err)
goto err_nexthop_group_ht_init; goto err_nexthop_group_ht_init;
INIT_LIST_HEAD(&mlxsw_sp->router->nexthop_list);
err = mlxsw_sp_lpm_init(mlxsw_sp); err = mlxsw_sp_lpm_init(mlxsw_sp);
if (err) if (err)
goto err_lpm_init; goto err_lpm_init;
......
...@@ -62,6 +62,7 @@ enum mlxsw_sp_rif_counter_dir { ...@@ -62,6 +62,7 @@ enum mlxsw_sp_rif_counter_dir {
}; };
struct mlxsw_sp_neigh_entry; struct mlxsw_sp_neigh_entry;
struct mlxsw_sp_nexthop;
struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp,
u16 rif_index); u16 rif_index);
...@@ -108,5 +109,24 @@ union mlxsw_sp_l3addr ...@@ -108,5 +109,24 @@ union mlxsw_sp_l3addr
mlxsw_sp_ipip_netdev_daddr(enum mlxsw_sp_l3proto proto, mlxsw_sp_ipip_netdev_daddr(enum mlxsw_sp_l3proto proto,
const struct net_device *ol_dev); const struct net_device *ol_dev);
__be32 mlxsw_sp_ipip_netdev_daddr4(const struct net_device *ol_dev); __be32 mlxsw_sp_ipip_netdev_daddr4(const struct net_device *ol_dev);
struct mlxsw_sp_nexthop *mlxsw_sp_nexthop_next(struct mlxsw_sp_router *router,
struct mlxsw_sp_nexthop *nh);
bool mlxsw_sp_nexthop_offload(struct mlxsw_sp_nexthop *nh);
unsigned char *mlxsw_sp_nexthop_ha(struct mlxsw_sp_nexthop *nh);
int mlxsw_sp_nexthop_indexes(struct mlxsw_sp_nexthop *nh, u32 *p_adj_index,
u32 *p_adj_hash_index);
struct mlxsw_sp_rif *mlxsw_sp_nexthop_rif(struct mlxsw_sp_nexthop *nh);
bool mlxsw_sp_nexthop_group_has_ipip(struct mlxsw_sp_nexthop *nh);
#define mlxsw_sp_nexthop_for_each(nh, router) \
for (nh = mlxsw_sp_nexthop_next(router, NULL); nh; \
nh = mlxsw_sp_nexthop_next(router, nh))
int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh, u64 *p_counter);
int mlxsw_sp_nexthop_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
struct mlxsw_sp_nexthop *nh);
void mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh);
void mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop *nh);
#endif /* _MLXSW_ROUTER_H_*/ #endif /* _MLXSW_ROUTER_H_*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment