diff options
author | Damjan Marion <damjan.marion@gmail.com> | 2024-10-23 20:56:27 +0200 |
---|---|---|
committer | Damjan Marion <damjan.marion@gmail.com> | 2024-10-23 21:03:30 +0200 |
commit | 8cbf565e065e397f5b03f19fb4222d9f576d4c20 (patch) | |
tree | 1ff4bbb00fea6af633b1c1d89e145a3889e70890 | |
parent | b87e7ba1e582ea6f8d066ee236ca0ae991a1af56 (diff) |
dev: keep dev_instance data in struct
Type: refactor
Change-Id: I05d04e2e9872d025384524b1bc133d909581e18a
Signed-off-by: Damjan Marion <damjan.marion@gmail.com>
-rw-r--r-- | src/vnet/dev/api.c | 2 | ||||
-rw-r--r-- | src/vnet/dev/dev.h | 7 | ||||
-rw-r--r-- | src/vnet/dev/dev_funcs.h | 16 | ||||
-rw-r--r-- | src/vnet/dev/port.c | 11 |
4 files changed, 24 insertions, 12 deletions
diff --git a/src/vnet/dev/api.c b/src/vnet/dev/api.c index 114b63d6662..0f4bd0b653e 100644 --- a/src/vnet/dev/api.c +++ b/src/vnet/dev/api.c @@ -263,7 +263,7 @@ vnet_dev_api_remove_port_if (vlib_main_t *vm, if (!hi) return VNET_DEV_ERR_UNKNOWN_INTERFACE; - if (pool_is_free_index (dm->ports_by_dev_instance, hi->dev_instance)) + if (pool_is_free_index (dm->dev_instances, hi->dev_instance)) return VNET_DEV_ERR_UNKNOWN_INTERFACE; port = vnet_dev_get_port_from_dev_instance (hi->dev_instance); diff --git a/src/vnet/dev/dev.h b/src/vnet/dev/dev.h index 744dc5ac819..a00c9e2e95e 100644 --- a/src/vnet/dev/dev.h +++ b/src/vnet/dev/dev.h @@ -461,10 +461,15 @@ typedef struct typedef struct { + vnet_dev_port_t *port; +} vnet_dev_instance_t; + +typedef struct +{ vnet_dev_bus_t *buses; vnet_dev_driver_t *drivers; vnet_dev_t **devices; - vnet_dev_port_t **ports_by_dev_instance; + vnet_dev_instance_t *dev_instances; vnet_dev_bus_registration_t *bus_registrations; vnet_dev_driver_registration_t *driver_registrations; void *runtime_temp_spaces; diff --git a/src/vnet/dev/dev_funcs.h b/src/vnet/dev/dev_funcs.h index b805698ea3c..0531b17a009 100644 --- a/src/vnet/dev/dev_funcs.h +++ b/src/vnet/dev/dev_funcs.h @@ -51,13 +51,21 @@ vnet_dev_get_port_by_index (vnet_dev_t *dev, u32 index) return pool_elt_at_index (dev->ports, index)[0]; } -static_always_inline vnet_dev_port_t * -vnet_dev_get_port_from_dev_instance (u32 dev_instance) +static_always_inline vnet_dev_instance_t * +vnet_dev_get_dev_instance (u32 dev_instance) { vnet_dev_main_t *dm = &vnet_dev_main; - if (pool_is_free_index (dm->ports_by_dev_instance, dev_instance)) + if (pool_is_free_index (dm->dev_instances, dev_instance)) return 0; - return pool_elt_at_index (dm->ports_by_dev_instance, dev_instance)[0]; + return pool_elt_at_index (dm->dev_instances, dev_instance); +} + +static_always_inline vnet_dev_port_t * +vnet_dev_get_port_from_dev_instance (u32 dev_instance) +{ + vnet_dev_instance_t *di = vnet_dev_get_dev_instance (dev_instance); + + return di ? di->port : 0; } static_always_inline vnet_dev_port_t * diff --git a/src/vnet/dev/port.c b/src/vnet/dev/port.c index 0ebe3c4690d..7126ceed731 100644 --- a/src/vnet/dev/port.c +++ b/src/vnet/dev/port.c @@ -517,7 +517,7 @@ vnet_dev_port_if_create (vlib_main_t *vm, vnet_dev_port_t *port) u16 n_threads = vlib_get_n_threads (); vnet_dev_main_t *dm = &vnet_dev_main; vnet_dev_t *dev = port->dev; - vnet_dev_port_t **pp; + vnet_dev_instance_t *di; vnet_dev_rv_t rv; u16 ti = 0; @@ -563,10 +563,9 @@ vnet_dev_port_if_create (vlib_main_t *vm, vnet_dev_port_t *port) break; } - /* pool of port pointers helps us to assign unique dev_instance */ - pool_get (dm->ports_by_dev_instance, pp); - port->intf.dev_instance = pp - dm->ports_by_dev_instance; - pp[0] = port; + pool_get (dm->dev_instances, di); + port->intf.dev_instance = di - dm->dev_instances; + di->port = port; if (port->attr.type == VNET_DEV_PORT_TYPE_ETHERNET) { @@ -709,7 +708,7 @@ vnet_dev_port_if_remove (vlib_main_t *vm, vnet_dev_port_t *port) vlib_worker_thread_barrier_sync (vm); vnet_delete_hw_interface (vnm, port->intf.hw_if_index); vlib_worker_thread_barrier_release (vm); - pool_put_index (dm->ports_by_dev_instance, port->intf.dev_instance); + pool_put_index (dm->dev_instances, port->intf.dev_instance); port->interface_created = 0; } |