rocker: prepare for easy addition of other worlds
v2 cover rocker: prepare for easy addition of other worlds
From: Jiri Pirko <[email protected]>
This patchset does couple of small changes in order to prepare for smooth addition of other worlds, like P4 and BPF. qemu user will be able to request desired rocker world by "world=worldname" property.
v1->v2:
patch 2/4:
- new patch
patch 4/4:
- goto error path in case world type is not found for name
- move worlds alloc check right after worlds alloc
Jiri Pirko (4):
rocker: forbid to change world type
rocker: return -ENOMEM in case of some world alloc fails
rocker: add name field into WorldOps ale let world specify its name
rocker: allow user to specify rocker world by property
hw/net/rocker/rocker.c | 38 ++++++++++++++++++++++++++++++++++++-- hw/net/rocker/rocker_fp.c | 5 +++++ hw/net/rocker/rocker_fp.h | 1 + hw/net/rocker/rocker_of_dpa.c | 1 + hw/net/rocker/rocker_world.c | 7 +------ hw/net/rocker/rocker_world.h | 1 + 6 files changed, 45 insertions(+), 8 deletions(-)
Signature · 1 line
2.4.3
PATCH v2 1/4 rocker: forbid to change world type
From: Jiri Pirko <[email protected]>
Port to world assignment should be permitted only by qemu user. Driver should not be able to do it, so forbid that possibility.
--- hw/net/rocker/rocker.c | 8 +++++++- hw/net/rocker/rocker_fp.c | 5 +++++ hw/net/rocker/rocker_fp.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-)
hw/net/rocker/rocker.c +7 -1
@@ -400,7 +400,13 @@ static int cmd_set_port_settings(Rocker *r,if (tlvs[ROCKER_TLV_CMD_PORT_SETTINGS_MODE ]) { mode =rocker_tlv_get_u8 (tlvs[ROCKER_TLV_CMD_PORT_SETTINGS_MODE ]); -fp_port_set_world (fp_port, r->worlds[mode]); +if (mode >=ROCKER_WORLD_TYPE_MAX ) { +return -ROCKER_EINVAL ; + } +/* We don't support world change. */ +if (!fp_port_check_world (fp_port, r->worlds[mode])) { +return -ROCKER_EINVAL ; + } }if (tlvs[ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING ]) {
hw/net/rocker/rocker_fp.c +5 -0
@@ -186,6 +186,11 @@ void fp_port_set_world(FpPort *port, World *world) port->world = world; } +bool fp_port_check_world (FpPort *port,World *world) +{ +return port->world == world; +} +bool fp_port_enabled (FpPort *port) {return port->enabled;
hw/net/rocker/rocker_fp.h +1 -0
@@ -40,6 +40,7 @@ int fp_port_set_settings(FpPort *port, uint32_t speed,bool fp_port_from_pport (uint32_t pport,uint32_t *port);World *fp_port_get_world (FpPort *port);void fp_port_set_world (FpPort *port,World *world); +bool fp_port_check_world (FpPort *port,World *world);bool fp_port_enabled (FpPort *port);void fp_port_enable (FpPort *port);void fp_port_disable (FpPort *port);
Signature · 1 line
2.4.3
PATCH v2 2/4 rocker: return -ENOMEM in case of some world alloc fails
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Until now, 0 is returned in this error case. Fix it ro return -ENOMEM.
---v1->v2:
- new patch
--- hw/net/rocker/rocker.c | 1 + 1 file changed, 1 insertion(+)
hw/net/rocker/rocker.c +1 -0
@@ -1301,6 +1301,7 @@ static int pci_rocker_init(PCIDevice *dev)for (i =0 ; i <ROCKER_WORLD_TYPE_MAX ; i++) {if (!r->worlds[i]) { + err = -ENOMEM ; goto err_world_alloc; } }
Signature · 1 line
2.4.3
PATCH v2 3/4 rocker: add name field into WorldOps ale let world specify its name
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Also use this in world_name getter function.
--- hw/net/rocker/rocker_of_dpa.c | 1 + hw/net/rocker/rocker_world.c | 7 +------ hw/net/rocker/rocker_world.h | 1 + 3 files changed, 3 insertions(+), 6 deletions(-)
hw/net/rocker/rocker_of_dpa.c +1 -0
@@ -2614,6 +2614,7 @@ RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name, }static WorldOps of_dpa_ops = { + .name ="ofdpa" , .init = of_dpa_init, .uninit = of_dpa_uninit, .ig = of_dpa_ig,
hw/net/rocker/rocker_world.c +1 -6
@@ -98,10 +98,5 @@ enum rocker_world_type world_type(World *world)const char *world_name (World *world) { -switch (world->type) { -case ROCKER_WORLD_TYPE_OF_DPA : -return "OF_DPA" ; -default : -return "unknown" ; - } +return world->ops->name; }
hw/net/rocker/rocker_world.h +1 -0
@@ -33,6 +33,7 @@ typedef int (world_cmd)(World *world, DescInfo *info, RockerTlv *cmd_info_tlv); typedef struct world_ops { + const char *name; world_init *init; world_uninit *uninit; world_ig *ig;
Signature · 1 line
2.4.3
PATCH v2 4/4 rocker: allow user to specify rocker world by property
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Add property to specify rocker world. All ports will be assigned to this world.
---v1->v2:
- goto error path in case world type is not found for name
- move worlds alloc check right after worlds alloc
--- hw/net/rocker/rocker.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
hw/net/rocker/rocker.c +28 -1
@@ -43,6 +43,7 @@ struct rocker {/* switch configuration */ char *name;/* switch name */ +char *world_name;/* world name */ uint32_t fp_ports;/* front-panel port count */ NICPeers *fp_ports_peers;MACAddr fp_start_macaddr;/* front-panel port 0 mac addr */
@@ -1286,6 +1287,18 @@ static void rocker_msix_uninit(Rocker *r)rocker_msix_vectors_unuse (r,ROCKER_MSIX_VEC_COUNT (r->fp_ports)); } +static World *rocker_world_type_by_name (Rocker *r,const char *name) +{ +int i; + +for (i =0 ; i <ROCKER_WORLD_TYPE_MAX ; i++) { +if (strcmp (name,world_name (r->worlds[i])) ==0 ) { +return r->worlds[i]; + } + } +return NULL ; +} +static int pci_rocker_init (PCIDevice *dev) {Rocker *r =to_rocker (dev);
@@ -1297,7 +1310,6 @@ static int pci_rocker_init(PCIDevice *dev)/* allocate worlds */ r->worlds[ROCKER_WORLD_TYPE_OF_DPA ] =of_dpa_world_alloc (r); - r->world_dflt = r->worlds[ROCKER_WORLD_TYPE_OF_DPA ];for (i =0 ; i <ROCKER_WORLD_TYPE_MAX ; i++) {if (!r->worlds[i]) {
@@ -1306,6 +1318,19 @@ static int pci_rocker_init(PCIDevice *dev) } } +if (!r->world_name) { + r->world_name =g_strdup (world_name (r->worlds[ROCKER_WORLD_TYPE_OF_DPA ])); + } + + r->world_dflt =rocker_world_type_by_name (r, r->world_name); +if (!r->world_dflt) { +fprintf (stderr, +"rocker: requested world \"%s\" does not exist\n" , + r->world_name); + err = -EINVAL ; + goto err_world_type_by_name; + } +/* set up memory-mapped region at BAR0 */ memory_region_init_io(&r->mmio, OBJECT(r), &rocker_mmio_ops, r,
@@ -1439,6 +1464,7 @@ err_duplicate: err_msix_init:object_unparent (OBJECT (&r->msix_bar));object_unparent (OBJECT (&r->mmio)); +err_world_type_by_name: err_world_alloc:for (i =0 ; i <ROCKER_WORLD_TYPE_MAX ; i++) {if (r->worlds[i]) {
@@ -1510,6 +1536,7 @@ static void rocker_reset(DeviceState *dev)static Property rocker_properties[] = {DEFINE_PROP_STRING ("name" , Rocker, name), +DEFINE_PROP_STRING ("world" , Rocker, world_name),DEFINE_PROP_MACADDR ("fp_start_macaddr" , Rocker, fp_start_macaddr), DEFINE_PROP_UINT64("switch_id", Rocker,
Signature · 1 line
2.4.3
Jason Wang
AppliedQuoted 19 lines · Jiri Pirko
From: Jiri Pirko <[email protected]>
This patchset does couple of small changes in order to prepare for smooth addition of other worlds, like P4 and BPF. qemu user will be able to request desired rocker world by "world=worldname" property.
v1->v2:
patch 2/4:
- new patch
patch 4/4:
- goto error path in case world type is not found for name
- move worlds alloc check right after worlds allocJiri Pirko (4):
rocker: forbid to change world type
rocker: return-ENOMEMin case of some world alloc fails
rocker: add name field into WorldOps ale let world specify its name
rocker: allow user to specify rocker world by property
Quoted 8 lines
hw/net/rocker/rocker.c | 38 ++++++++++++++++++++++++++++++++++++-- hw/net/rocker/rocker_fp.c | 5 +++++ hw/net/rocker/rocker_fp.h | 1 + hw/net/rocker/rocker_of_dpa.c | 1 + hw/net/rocker/rocker_world.c | 7 +------ hw/net/rocker/rocker_world.h | 1 + 6 files changed, 45 insertions(+), 8 deletions(-)
Applied to -net.
Thanks