hw/net/eepro100: Finish QDev conversion
v2 cover hw/net/eepro100: Finish QDev conversion
Convert EEPRO100 to use the latest QDev conventions / style.
v1:
https://lore.kernel.org/qemu-devel/[email protected]/
Based-on: <[email protected]>
hw/qdev: Housekeeping around qdev_get_parent_bus()
Philippe Mathieu-Daudé (7):
hw/net/eepro100: Abort if pci_add_capability() ever fail hw/net/eepro100: Introduce TYPE_EEPRO100 QOM abstract parent hw/net/eepro100: Convert reset handler to DeviceReset hw/net/eepro100: Pass E100PCIDeviceInfo as class init data hw/net/eepro100: Remove instance
EEPRO100State::has_extended_tcb_support
hw/net/eepro100: Remove instance's EEPRO100State::device hw/net/eepro100: Replace DO_UPCAST(EEPRO100State) by EEPRO100()
hw/net/eepro100.c | 147 ++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 78 deletions(-)
Signature · 1 line
2.38.1
PATCH v2 1/7 hw/net/eepro100: Abort if pci_add_capability() ever fail
If pci_add_capability() ever fail, the EEPRO100 device is broken, which is a bug. No need to report that to the user, abort instead.
--- hw/net/eepro100.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
hw/net/eepro100.c +2 -7
@@ -549,13 +549,8 @@ static void e100_pci_reset(EEPRO100State *s, Error **errp)if (info->power_management) {/* Power Management Capabilities */ int cfg_offset =0xdc ; -int r =pci_add_capability (&s->dev,PCI_CAP_ID_PM , - cfg_offset,PCI_PM_SIZEOF , - errp); -if (r <0 ) { -return ; - } - +pci_add_capability (&s->dev,PCI_CAP_ID_PM , cfg_offset,PCI_PM_SIZEOF , + &error_abort);pci_set_word (pci_conf + cfg_offset +PCI_PM_PMC ,0x7e21 );#if 0 /* TODO: replace dummy code for power management emulation. */ /* TODO: Power Management Control / Status. */
Signature · 1 line
2.38.1
PATCH v2 2/7 hw/net/eepro100: Introduce TYPE_EEPRO100 QOM abstract parent
In reply to Philippe Mathieu-DaudéHave all the EEPRO100-based devices share a common (abstract) QOM parent.
--- hw/net/eepro100.c | 58 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 17 deletions(-)
hw/net/eepro100.c +41 -17
@@ -235,8 +235,20 @@ typedef enum { ru_ready = 4 } ru_state_t; -typedef struct { +#define TYPE_EEPRO100 "eepro100" +OBJECT_DECLARE_TYPE(EEPRO100State, EEPRO100Class, EEPRO100) + +struct EEPRO100Class { +/*< private >*/ +PCIDeviceClass parent_class; +/*< public >*/ +}; + +struct EEPRO100State { +/*< private >*/ PCIDevice dev; +/*< public >*/ +/* Hash register (multicast mask array, multiple individual addresses). */ uint8_t mult[8 ];MemoryRegion mmio_bar;
@@ -279,7 +291,7 @@ typedef struct {/* Quasi static device properties (no need to save them). */ uint16_t stats_size;bool has_extended_tcb_support; -} EEPRO100State; +};/* Word indices in EEPROM. */ typedef enum {
@@ -2055,43 +2067,55 @@ static Property e100_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void eepro100_class_init (ObjectClass *klass,void *data) +static void eepro100_base_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass);E100PCIDeviceInfo *info; - info =eepro100_get_class_by_name (object_class_get_name (klass));set_bit (DEVICE_CATEGORY_NETWORK , dc->categories);device_class_set_props (dc, e100_properties); - dc->desc = info->desc; k->vendor_id =PCI_VENDOR_ID_INTEL ; k->class_id =PCI_CLASS_NETWORK_ETHERNET ; k->romfile ="pxe-eepro100.rom" ; k->realize = e100_nic_realize; k->exit = pci_nic_uninit; + + info =eepro100_get_class_by_name (object_class_get_name (klass)); +if (!info) { +/* base class */ +return ; + } + dc->desc = info->desc; k->device_id = info->device_id; k->revision = info->revision; k->subsystem_vendor_id = info->subsystem_vendor_id; k->subsystem_id = info->subsystem_id; } +static const TypeInfo eepro100_base_info = { + .name =TYPE_EEPRO100 , + .parent =TYPE_PCI_DEVICE , + .abstract = true, + .class_init = eepro100_base_class_init, + .class_size =sizeof (EEPRO100Class), + .instance_size =sizeof (EEPRO100State), + .instance_init = eepro100_instance_init, + .interfaces = (InterfaceInfo []) { + {INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; +static void eepro100_register_types (void ) { -size_t i; -for (i =0 ; i <ARRAY_SIZE (e100_devices); i++) { -TypeInfo type_info = {}; -E100PCIDeviceInfo *info = &e100_devices[i]; +type_register_static (&eepro100_base_info); - type_info.name = info->name; - type_info.parent =TYPE_PCI_DEVICE ; - type_info.class_init = eepro100_class_init; - type_info.instance_size =sizeof (EEPRO100State); - type_info.instance_init = eepro100_instance_init; - type_info.interfaces = (InterfaceInfo []) { - {INTERFACE_CONVENTIONAL_PCI_DEVICE }, - { }, +for (size_t i =0 ; i <ARRAY_SIZE (e100_devices); i++) { +TypeInfo type_info = { + .name = e100_devices[i].name, + .parent =TYPE_EEPRO100 , };type_register (&type_info);
Signature · 1 line
2.38.1
PATCH v2 3/7 hw/net/eepro100: Convert reset handler to DeviceReset
In reply to Philippe Mathieu-Daudé--- hw/net/eepro100.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
hw/net/eepro100.c +3 -8
@@ -486,8 +486,9 @@ static void eepro100_fcp_interrupt(EEPRO100State * s) }#endif -static void e100_pci_reset (EEPRO100State *s,Error **errp) +static void e100_pci_reset (DeviceState *dev) { +EEPRO100State *s =EEPRO100 (dev);E100PCIDeviceInfo *info =eepro100_get_class (s);uint32_t device = s->device;uint8_t *pci_conf = s->dev.config;
@@ -1847,18 +1848,11 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp) {EEPRO100State *s =DO_UPCAST (EEPRO100State, dev, pci_dev);E100PCIDeviceInfo *info =eepro100_get_class (s); -Error *local_err =NULL ;TRACE (OTHER ,logout ("\n" )); s->device = info->device; -e100_pci_reset (s, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; - } -/* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM, * i82559 and later support 64 or 256 word EEPROM. */ s->eeprom =eeprom93xx_new (&pci_dev->qdev,EEPROM_SIZE );
@@ -2076,6 +2070,7 @@ static void eepro100_base_class_init(ObjectClass *klass, void *data)set_bit (DEVICE_CATEGORY_NETWORK , dc->categories);device_class_set_props (dc, e100_properties); + dc->reset = e100_pci_reset; k->vendor_id =PCI_VENDOR_ID_INTEL ; k->class_id =PCI_CLASS_NETWORK_ETHERNET ; k->romfile ="pxe-eepro100.rom" ;
Signature · 1 line
2.38.1
PATCH v2 4/7 hw/net/eepro100: Pass E100PCIDeviceInfo as class init data
In reply to Philippe Mathieu-DaudéQOM already provides the TypeInfo::class_data to set class-specific data. Use it instead of reinventing the wheel with eepro100_get_class_by_name(). This finishes the QDev conversion started 12 years ago in commit 40021f0888 ("pci: convert to QEMU Object Model").
--- hw/net/eepro100.c | 63 +++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 43 deletions(-)
hw/net/eepro100.c +20 -43
@@ -242,6 +242,8 @@ struct EEPRO100Class {/*< private >*/ PCIDeviceClass parent_class;/*< public >*/ + +const E100PCIDeviceInfo *info; };struct EEPRO100State {
@@ -338,8 +340,6 @@ static const uint16_t eepro100_mdi_mask[] = { 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, }; -static E100PCIDeviceInfo *eepro100_get_class (EEPRO100State *s); -/* Read a 16 bit control/status (CSR) register. */ static uint16_t e100_read_reg2 (EEPRO100State *s,E100RegisterOffset addr) {
@@ -489,8 +489,9 @@ static void eepro100_fcp_interrupt(EEPRO100State * s)static void e100_pci_reset (DeviceState *dev) {EEPRO100State *s =EEPRO100 (dev); -E100PCIDeviceInfo *info =eepro100_get_class (s); -uint32_t device = s->device; +EEPRO100Class *ek =EEPRO100_GET_CLASS (s); +const E100PCIDeviceInfo *info = ek->info; +uint32_t device = info->device;uint8_t *pci_conf = s->dev.config;TRACE (OTHER ,logout ("%p\n" , s));
@@ -1847,11 +1848,11 @@ static NetClientInfo net_eepro100_info = {static void e100_nic_realize (PCIDevice *pci_dev,Error **errp) {EEPRO100State *s =DO_UPCAST (EEPRO100State, dev, pci_dev); -E100PCIDeviceInfo *info =eepro100_get_class (s); +EEPRO100Class *ek =EEPRO100_GET_CLASS (s);TRACE (OTHER ,logout ("\n" )); - s->device = info->device; + s->device = ek->info->device;/* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM, * i82559 and later support 64 or 256 word EEPROM. */
@@ -2028,32 +2029,19 @@ static E100PCIDeviceInfo e100_devices[] = { } }; -static E100PCIDeviceInfo *eepro100_get_class_by_name (const char *typename) +static void eepro100_class_init (ObjectClass *klass,void *data) { -E100PCIDeviceInfo *info =NULL ; -int i; +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); +EEPRO100Class *ek =EEPRO100_CLASS (klass); +const E100PCIDeviceInfo *info = data; -/* This is admittedly awkward but also temporary. QOM allows for -* parameterized typing and for subclassing both of which would suitable -* handle what's going on here. But class_data is already being used as -* a stop-gap hack to allow incremental qdev conversion so we cannot use it -* right now. Once we merge the final QOM series, we can come back here and -* do this in a much more elegant fashion. -*/ -for (i =0 ; i <ARRAY_SIZE (e100_devices); i++) { -if (strcmp (e100_devices[i].name, typename) ==0 ) { - info = &e100_devices[i]; -break ; - } - } -assert (info !=NULL ); - -return info; -} - -static E100PCIDeviceInfo *eepro100_get_class (EEPRO100State *s) -{ -return eepro100_get_class_by_name (object_get_typename (OBJECT (s))); + dc->desc = info->desc; + k->device_id = info->device_id; + k->revision = info->revision; + k->subsystem_vendor_id = info->subsystem_vendor_id; + k->subsystem_id = info->subsystem_id; + ek->info = info; }static Property e100_properties[] = {
@@ -2065,8 +2053,6 @@ static void eepro100_base_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass);PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); -E100PCIDeviceInfo *info; -set_bit (DEVICE_CATEGORY_NETWORK , dc->categories);device_class_set_props (dc, e100_properties);
@@ -2076,17 +2062,6 @@ static void eepro100_base_class_init(ObjectClass *klass, void *data) k->romfile ="pxe-eepro100.rom" ; k->realize = e100_nic_realize; k->exit = pci_nic_uninit; - - info =eepro100_get_class_by_name (object_class_get_name (klass)); -if (!info) { -/* base class */ -return ; - } - dc->desc = info->desc; - k->device_id = info->device_id; - k->revision = info->revision; - k->subsystem_vendor_id = info->subsystem_vendor_id; - k->subsystem_id = info->subsystem_id; }static const TypeInfo eepro100_base_info = {
@@ -2111,6 +2086,8 @@ static void eepro100_register_types(void)TypeInfo type_info = { .name = e100_devices[i].name, .parent =TYPE_EEPRO100 , + .class_init = eepro100_class_init, + .class_data = (void *)&e100_devices[i], };type_register (&type_info);
Signature · 1 line
2.38.1
PATCH v2 5/7 hw/net/eepro100: Remove instance EEPRO100State::has_extended_tcb_support
In reply to Philippe Mathieu-Daudé'has_extended_tcb_support' is accessed read-only and is present in the class definition. No need to duplicate it in the instance state. Directly access the class field.
--- hw/net/eepro100.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/eepro100.c +3 -3
@@ -292,7 +292,6 @@ struct EEPRO100State {/* Quasi static device properties (no need to save them). */ uint16_t stats_size; -bool has_extended_tcb_support; };/* Word indices in EEPROM. */
@@ -511,7 +510,6 @@ static void e100_pci_reset(DeviceState *dev)pci_set_byte (pci_conf +PCI_MAX_LAT ,0x18 ); s->stats_size = info->stats_size; - s->has_extended_tcb_support = info->has_extended_tcb_support;switch (device) {case i82550:
@@ -746,6 +744,8 @@ static void read_cb(EEPRO100State *s)static void tx_command (EEPRO100State *s) { +EEPRO100Class *ek =EEPRO100_GET_CLASS (s); +const E100PCIDeviceInfo *info = ek->info;const MemTxAttrs attrs =MEMTXATTRS_UNSPECIFIED ;uint32_t tbd_array = s->tx.tbd_array_addr;uint16_t tcb_bytes = s->tx.tcb_bytes &0x3fff ;
@@ -782,7 +782,7 @@ static void tx_command(EEPRO100State *s)uint16_t tx_buffer_size;uint16_t tx_buffer_el; -if (s->has_extended_tcb_support && !(s->configuration[6 ] &BIT (4 ))) { +if (info->has_extended_tcb_support && !(s->configuration[6 ] &BIT (4 ))) {/* Extended Flexible TCB. */ for (; tbd_count <2 ; tbd_count++) {ldl_le_pci_dma (&s->dev, tbd_address, &tx_buffer_address, attrs);
Signature · 1 line
2.38.1
PATCH v2 6/7 hw/net/eepro100: Remove instance's EEPRO100State::device
In reply to Philippe Mathieu-Daudé'device' is accessed read-only and is present in the class definition. No need to duplicate it in the instance state. Directly access the class field.
--- hw/net/eepro100.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/net/eepro100.c +6 -6
@@ -263,7 +263,6 @@ struct EEPRO100State {/* region must not be saved by nic_save. */ uint16_t mdimem[32 ];eeprom_t *eeprom; -uint32_t device;/* device variant */ /* (cu_base + cu_offset) address the next command block in the command block list. */ uint32_t cu_base;/* CU base address */ uint32_t cu_offset;/* CU address offset */
@@ -591,6 +590,9 @@ static void e100_pci_reset(DeviceState *dev)static void nic_selective_reset (EEPRO100State * s) { +EEPRO100Class *ek =EEPRO100_GET_CLASS (s); +const E100PCIDeviceInfo *info = ek->info; +size_t i;uint16_t *eeprom_contents =eeprom93xx_data (s->eeprom);#if 0
@@ -598,8 +600,9 @@ static void nic_selective_reset(EEPRO100State * s)#endif memcpy (eeprom_contents, s->conf.macaddr.a,6 ); eeprom_contents[EEPROM_ID ] =EEPROM_ID_VALID ; -if (s->device == i82557B || s->device == i82557C) +if (info->device == i82557B || info->device == i82557C) { eeprom_contents[5 ] =0x0100 ; + } eeprom_contents[EEPROM_PHY_ID ] =1 ;uint16_t sum =0 ;for (i =0 ; i <EEPROM_SIZE -1 ; i++) {
@@ -1794,7 +1797,7 @@ static const VMStateDescription vmstate_eepro100 = {VMSTATE_UNUSED (19 *4 ),VMSTATE_UINT16_ARRAY (mdimem, EEPRO100State,32 ),/* The eeprom should be saved and restored by its own routines. */ -VMSTATE_UINT32 (device, EEPRO100State), +VMSTATE_UNUSED (sizeof (uint32_t )),/* was device variant */ /* TODO check device. */ VMSTATE_UINT32 (cu_base, EEPRO100State), VMSTATE_UINT32(cu_offset, EEPRO100State),
@@ -1848,12 +1851,9 @@ static NetClientInfo net_eepro100_info = {static void e100_nic_realize (PCIDevice *pci_dev,Error **errp) {EEPRO100State *s =DO_UPCAST (EEPRO100State, dev, pci_dev); -EEPRO100Class *ek =EEPRO100_GET_CLASS (s);TRACE (OTHER ,logout ("\n" )); - s->device = ek->info->device; -/* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM, * i82559 and later support 64 or 256 word EEPROM. */ s->eeprom =eeprom93xx_new (&pci_dev->qdev,EEPROM_SIZE );
Signature · 1 line
2.38.1
PATCH v2 7/7 hw/net/eepro100: Replace DO_UPCAST(EEPRO100State) by EEPRO100()
In reply to Philippe Mathieu-DaudéUse the EEPRO100() QOM type-checking macro to avoid DO_UPCAST().
--- hw/net/eepro100.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/eepro100.c +3 -3
@@ -1834,7 +1834,7 @@ static const VMStateDescription vmstate_eepro100 = {static void pci_nic_uninit (PCIDevice *pci_dev) { -EEPRO100State *s =DO_UPCAST (EEPRO100State, dev, pci_dev); +EEPRO100State *s =EEPRO100 (pci_dev);vmstate_unregister (VMSTATE_IF (&pci_dev->qdev), s->vmstate, s);g_free (s->vmstate);
@@ -1850,7 +1850,7 @@ static NetClientInfo net_eepro100_info = {static void e100_nic_realize (PCIDevice *pci_dev,Error **errp) { -EEPRO100State *s =DO_UPCAST (EEPRO100State, dev, pci_dev); +EEPRO100State *s =EEPRO100 (pci_dev);TRACE (OTHER ,logout ("\n" ));
@@ -1891,7 +1891,7 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp)static void eepro100_instance_init (Object *obj) { -EEPRO100State *s =DO_UPCAST (EEPRO100State, dev,PCI_DEVICE (obj)); +EEPRO100State *s =EEPRO100 (obj);device_add_bootindex_property (obj, &s->conf.bootindex,"bootindex" ,"/ethernet-phy@0" ,DEVICE (s));
Signature · 1 line
2.38.1
ping
Quoted 21 lines · Philippe Mathieu-Daudé
Convert EEPRO100 to use the latest QDev conventions / style.
v1:
https://lore.kernel.org/qemu-devel/[email protected]/Based-on: <[email protected]>
hw/qdev: Housekeeping aroundqdev_get_parent_bus()Philippe Mathieu-Daudé (7):
hw/net/eepro100: Abort ifpci_add_capability()ever fail hw/net/eepro100: IntroduceTYPE_EEPRO100QOM abstract parent hw/net/eepro100: Convert reset handler to DeviceReset hw/net/eepro100: Pass E100PCIDeviceInfo as class init data hw/net/eepro100: Remove instance
EEPRO100State::has_extended_tcb_support
hw/net/eepro100: Remove instance'sEEPRO100State::devicehw/net/eepro100: ReplaceDO_UPCAST(EEPRO100State)byEEPRO100()hw/net/eepro100.c | 147 ++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 78 deletions(-)
Hi Jason, do you Ack this series?
Quoted 25 lines · Philippe Mathieu-Daudé
ping
Quoted 21 lines · Philippe Mathieu-Daudé
Convert EEPRO100 to use the latest QDev conventions / style.
v1:
https://lore.kernel.org/qemu-devel/[email protected]/Based-on: <[email protected]> hw/qdev: Housekeeping around
qdev_get_parent_bus()Philippe Mathieu-Daudé (7):
hw/net/eepro100: Abort ifpci_add_capability()ever fail hw/net/eepro100: IntroduceTYPE_EEPRO100QOM abstract parent hw/net/eepro100: Convert reset handler to DeviceReset hw/net/eepro100: Pass E100PCIDeviceInfo as class init data hw/net/eepro100: Remove instanceEEPRO100State::has_extended_tcb_supporthw/net/eepro100: Remove instance'sEEPRO100State::devicehw/net/eepro100: ReplaceDO_UPCAST(EEPRO100State)byEEPRO100()
hw/net/eepro100.c| 147 ++++++++++++++++++++++------------------------1 file changed, 69 insertions(+), 78 deletions(-)
Quoted 2 lines · Philippe Mathieu-Daudé
Hi Jason, do you Ack this series?
Sorry for the late reply.
I've queued this series.
Thanks
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 25 lines
ping
Quoted 21 lines · Philippe Mathieu-Daudé
Convert EEPRO100 to use the latest QDev conventions / style.
v1:
https://lore.kernel.org/qemu-devel/[email protected]/Based-on: <[email protected]>
hw/qdev: Housekeeping aroundqdev_get_parent_bus()Philippe Mathieu-Daudé (7):
hw/net/eepro100: Abort ifpci_add_capability()ever fail hw/net/eepro100: IntroduceTYPE_EEPRO100QOM abstract parent hw/net/eepro100: Convert reset handler to DeviceReset hw/net/eepro100: Pass E100PCIDeviceInfo as class init data hw/net/eepro100: Remove instance
EEPRO100State::has_extended_tcb_support
hw/net/eepro100: Remove instance'sEEPRO100State::devicehw/net/eepro100: ReplaceDO_UPCAST(EEPRO100State)byEEPRO100()hw/net/eepro100.c | 147 ++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 78 deletions(-)
Quoted 8 lines · Jason Wang
Quoted 2 lines · Philippe Mathieu-Daudé
Hi Jason, do you Ack this series?
Sorry for the late reply.
I've queued this series.
Thank you!