Commit 35266255 authored by Ido Schimmel's avatar Ido Schimmel Committed by Jakub Kicinski

netdevsim: Add devlink resource for nexthops

The Spectrum ASIC has a dedicated table where nexthops (i.e., adjacency
entries) are populated. The size of this table can be controlled via
devlink-resource.

Add such a resource to netdevsim so that its occupancy will reflect the
number of nexthop objects currently programmed to the device.

By limiting the size of the resource, error paths could be exercised and
tested.

Example output:

# devlink resource show netdevsim/netdevsim10
netdevsim/netdevsim10:
  name IPv4 size unlimited unit entry size_min 0 size_max unlimited size_gran 1 dpipe_tables none
    resources:
      name fib size unlimited occ 4 unit entry size_min 0 size_max unlimited size_gran 1 dpipe_tables none
      name fib-rules size unlimited occ 3 unit entry size_min 0 size_max unlimited size_gran 1 dpipe_tables none
  name IPv6 size unlimited unit entry size_min 0 size_max unlimited size_gran 1 dpipe_tables none
    resources:
      name fib size unlimited occ 1 unit entry size_min 0 size_max unlimited size_gran 1 dpipe_tables none
      name fib-rules size unlimited occ 2 unit entry size_min 0 size_max unlimited size_gran 1 dpipe_tables none
  name nexthops size unlimited occ 0 unit entry size_min 0 size_max unlimited size_gran 1 dpipe_tables none
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent bbea126c
...@@ -46,7 +46,7 @@ Resources ...@@ -46,7 +46,7 @@ Resources
========= =========
The ``netdevsim`` driver exposes resources to control the number of FIB The ``netdevsim`` driver exposes resources to control the number of FIB
entries and FIB rule entries that the driver will allow. entries, FIB rule entries and nexthops that the driver will allow.
.. code:: shell .. code:: shell
...@@ -54,6 +54,7 @@ entries and FIB rule entries that the driver will allow. ...@@ -54,6 +54,7 @@ entries and FIB rule entries that the driver will allow.
$ devlink resource set netdevsim/netdevsim0 path /IPv4/fib-rules size 16 $ devlink resource set netdevsim/netdevsim0 path /IPv4/fib-rules size 16
$ devlink resource set netdevsim/netdevsim0 path /IPv6/fib size 64 $ devlink resource set netdevsim/netdevsim0 path /IPv6/fib size 64
$ devlink resource set netdevsim/netdevsim0 path /IPv6/fib-rules size 16 $ devlink resource set netdevsim/netdevsim0 path /IPv6/fib-rules size 16
$ devlink resource set netdevsim/netdevsim0 path /nexthops size 16
$ devlink dev reload netdevsim/netdevsim0 $ devlink dev reload netdevsim/netdevsim0
Driver-specific Traps Driver-specific Traps
......
...@@ -324,6 +324,12 @@ static int nsim_dev_resources_register(struct devlink *devlink) ...@@ -324,6 +324,12 @@ static int nsim_dev_resources_register(struct devlink *devlink)
return err; return err;
} }
/* Resources for nexthops */
err = devlink_resource_register(devlink, "nexthops", (u64)-1,
NSIM_RESOURCE_NEXTHOPS,
DEVLINK_RESOURCE_ID_PARENT_TOP,
&params);
out: out:
return err; return err;
} }
......
...@@ -42,6 +42,7 @@ struct nsim_fib_data { ...@@ -42,6 +42,7 @@ struct nsim_fib_data {
struct notifier_block fib_nb; struct notifier_block fib_nb;
struct nsim_per_fib_data ipv4; struct nsim_per_fib_data ipv4;
struct nsim_per_fib_data ipv6; struct nsim_per_fib_data ipv6;
struct nsim_fib_entry nexthops;
struct rhashtable fib_rt_ht; struct rhashtable fib_rt_ht;
struct list_head fib_rt_list; struct list_head fib_rt_list;
spinlock_t fib_lock; /* Protects hashtable, list and accounting */ spinlock_t fib_lock; /* Protects hashtable, list and accounting */
...@@ -104,6 +105,9 @@ u64 nsim_fib_get_val(struct nsim_fib_data *fib_data, ...@@ -104,6 +105,9 @@ u64 nsim_fib_get_val(struct nsim_fib_data *fib_data,
case NSIM_RESOURCE_IPV6_FIB_RULES: case NSIM_RESOURCE_IPV6_FIB_RULES:
entry = &fib_data->ipv6.rules; entry = &fib_data->ipv6.rules;
break; break;
case NSIM_RESOURCE_NEXTHOPS:
entry = &fib_data->nexthops;
break;
default: default:
return 0; return 0;
} }
...@@ -129,6 +133,9 @@ static void nsim_fib_set_max(struct nsim_fib_data *fib_data, ...@@ -129,6 +133,9 @@ static void nsim_fib_set_max(struct nsim_fib_data *fib_data,
case NSIM_RESOURCE_IPV6_FIB_RULES: case NSIM_RESOURCE_IPV6_FIB_RULES:
entry = &fib_data->ipv6.rules; entry = &fib_data->ipv6.rules;
break; break;
case NSIM_RESOURCE_NEXTHOPS:
entry = &fib_data->nexthops;
break;
default: default:
WARN_ON(1); WARN_ON(1);
return; return;
...@@ -866,12 +873,20 @@ static u64 nsim_fib_ipv6_rules_res_occ_get(void *priv) ...@@ -866,12 +873,20 @@ static u64 nsim_fib_ipv6_rules_res_occ_get(void *priv)
return nsim_fib_get_val(data, NSIM_RESOURCE_IPV6_FIB_RULES, false); return nsim_fib_get_val(data, NSIM_RESOURCE_IPV6_FIB_RULES, false);
} }
static u64 nsim_fib_nexthops_res_occ_get(void *priv)
{
struct nsim_fib_data *data = priv;
return nsim_fib_get_val(data, NSIM_RESOURCE_NEXTHOPS, false);
}
static void nsim_fib_set_max_all(struct nsim_fib_data *data, static void nsim_fib_set_max_all(struct nsim_fib_data *data,
struct devlink *devlink) struct devlink *devlink)
{ {
enum nsim_resource_id res_ids[] = { enum nsim_resource_id res_ids[] = {
NSIM_RESOURCE_IPV4_FIB, NSIM_RESOURCE_IPV4_FIB_RULES, NSIM_RESOURCE_IPV4_FIB, NSIM_RESOURCE_IPV4_FIB_RULES,
NSIM_RESOURCE_IPV6_FIB, NSIM_RESOURCE_IPV6_FIB_RULES NSIM_RESOURCE_IPV6_FIB, NSIM_RESOURCE_IPV6_FIB_RULES,
NSIM_RESOURCE_NEXTHOPS,
}; };
int i; int i;
...@@ -929,6 +944,10 @@ struct nsim_fib_data *nsim_fib_create(struct devlink *devlink, ...@@ -929,6 +944,10 @@ struct nsim_fib_data *nsim_fib_create(struct devlink *devlink,
NSIM_RESOURCE_IPV6_FIB_RULES, NSIM_RESOURCE_IPV6_FIB_RULES,
nsim_fib_ipv6_rules_res_occ_get, nsim_fib_ipv6_rules_res_occ_get,
data); data);
devlink_resource_occ_get_register(devlink,
NSIM_RESOURCE_NEXTHOPS,
nsim_fib_nexthops_res_occ_get,
data);
return data; return data;
err_rhashtable_destroy: err_rhashtable_destroy:
...@@ -941,6 +960,8 @@ struct nsim_fib_data *nsim_fib_create(struct devlink *devlink, ...@@ -941,6 +960,8 @@ struct nsim_fib_data *nsim_fib_create(struct devlink *devlink,
void nsim_fib_destroy(struct devlink *devlink, struct nsim_fib_data *data) void nsim_fib_destroy(struct devlink *devlink, struct nsim_fib_data *data)
{ {
devlink_resource_occ_get_unregister(devlink,
NSIM_RESOURCE_NEXTHOPS);
devlink_resource_occ_get_unregister(devlink, devlink_resource_occ_get_unregister(devlink,
NSIM_RESOURCE_IPV6_FIB_RULES); NSIM_RESOURCE_IPV6_FIB_RULES);
devlink_resource_occ_get_unregister(devlink, devlink_resource_occ_get_unregister(devlink,
......
...@@ -158,6 +158,7 @@ enum nsim_resource_id { ...@@ -158,6 +158,7 @@ enum nsim_resource_id {
NSIM_RESOURCE_IPV6, NSIM_RESOURCE_IPV6,
NSIM_RESOURCE_IPV6_FIB, NSIM_RESOURCE_IPV6_FIB,
NSIM_RESOURCE_IPV6_FIB_RULES, NSIM_RESOURCE_IPV6_FIB_RULES,
NSIM_RESOURCE_NEXTHOPS,
}; };
struct nsim_dev_health { struct nsim_dev_health {
......
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