[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 29/47] hw/arm/stellaris: use qemu_find_nic_info()
From: |
Peter Maydell |
Subject: |
Re: [PATCH v4 29/47] hw/arm/stellaris: use qemu_find_nic_info() |
Date: |
Wed, 31 Jan 2024 14:28:41 +0000 |
On Wed, 31 Jan 2024 at 12:14, Thomas Huth <thuth@redhat.com> wrote:
>
> On 26/01/2024 18.25, David Woodhouse wrote:
> > From: David Woodhouse <dwmw@amazon.co.uk>
> >
> > Rather than just using qemu_configure_nic_device(), populate the MAC
> > address in the system-registers device by peeking at the NICInfo before
> > it's assigned to the device.
> >
> > Generate the MAC address early, if there is no matching -nic option.
> > Otherwise the MAC address wouldn't be generated until net_client_init1()
> > runs.
> >
> > Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> > ---
> > hw/arm/stellaris.c | 30 ++++++++++++++++++++++--------
> > 1 file changed, 22 insertions(+), 8 deletions(-)
> >
> > diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> > index d18b1144af..34c5a86ac2 100644
> > --- a/hw/arm/stellaris.c
> > +++ b/hw/arm/stellaris.c
> > @@ -1028,7 +1028,8 @@ static void stellaris_init(MachineState *ms,
> > stellaris_board_info *board)
> > DeviceState *ssys_dev;
> > int i;
> > int j;
> > - const uint8_t *macaddr;
> > + NICInfo *nd;
> > + MACAddr mac;
> >
> > MemoryRegion *sram = g_new(MemoryRegion, 1);
> > MemoryRegion *flash = g_new(MemoryRegion, 1);
> > @@ -1051,12 +1052,22 @@ static void stellaris_init(MachineState *ms,
> > stellaris_board_info *board)
> > * need its sysclk output.
> > */
> > ssys_dev = qdev_new(TYPE_STELLARIS_SYS);
> > - /* Most devices come preprogrammed with a MAC address in the user
> > data. */
> > - macaddr = nd_table[0].macaddr.a;
> > +
> > + /*
> > + * Most devices come preprogrammed with a MAC address in the user data.
> > + * Generate a MAC address now, if there isn't a matching -nic for it.
> > + */
> > + nd = qemu_find_nic_info("stellaris_enet", true, "stellaris");
> > + if (nd) {
> > + memcpy(mac.a, nd->macaddr.a, sizeof(mac.a));
> > + } else {
> > + qemu_macaddr_default_if_unset(&mac);
> > + }
> > +
> > qdev_prop_set_uint32(ssys_dev, "user0",
> > - macaddr[0] | (macaddr[1] << 8) | (macaddr[2] <<
> > 16));
> > + mac.a[0] | (mac.a[1] << 8) | (mac.a[2] << 16));
> > qdev_prop_set_uint32(ssys_dev, "user1",
> > - macaddr[3] | (macaddr[4] << 8) | (macaddr[5] <<
> > 16));
> > + mac.a[3] | (mac.a[4] << 8) | (mac.a[5] << 16));
>
> Out of scope of your patch, but I wonder why we didn't use
> qdev_prop_set_macaddr() with an according MAC address property for this
> device...?
Partly because this code originates from 2007 and
qdev_prop_set_macaddr() only arrived in 2009. When I did
a basic qdev conversion in 2021 (commit 4bebb9ad4e4) I
just did a simple change from "directly set fields in the
device state struct" to "set fields in the device state
struct via some qdev properties".
But also because the device we're setting these fields on isn't
an ethernet device -- it's a "system control" device with a bunch
of registers, including two which have no effect on the hardware
behaviour but which by convention usually have the MAC address in
them. So as an interface to the system control device it does make
some sense to have it be "what are the values of these two 'user'
registers" ?
(qdev_prop_set_macaddr() and the associated mac address property
seem a bit odd -- qdev_prop_set_macaddr() is called from exactly
one place, and it takes an array of bytes, marshalls them into
an ASCII string representation, sets the property, and then the
property setter parses them back out of ASCII and into an array
of bytes again...)
thanks
-- PMM
- [PATCH v4 22/47] hw/arm/aspeed: use qemu_configure_nic_device(), (continued)
- [PATCH v4 22/47] hw/arm/aspeed: use qemu_configure_nic_device(), David Woodhouse, 2024/01/26
- [PATCH v4 16/47] hw/ppc/spapr: use qemu_get_nic_info() and pci_init_nic_devices(), David Woodhouse, 2024/01/26
- [PATCH v4 10/47] hw/hppa: use pci_init_nic_devices(), David Woodhouse, 2024/01/26
- [PATCH v4 44/47] net: remove qemu_check_nic_model(), David Woodhouse, 2024/01/26
- [PATCH v4 08/47] hw/arm/sbsa-ref: use pci_init_nic_devices(), David Woodhouse, 2024/01/26
- [PATCH v4 33/47] hw/m68k/q800: use qemu_find_nic_info(), David Woodhouse, 2024/01/26
- [PATCH v4 29/47] hw/arm/stellaris: use qemu_find_nic_info(), David Woodhouse, 2024/01/26
- [PATCH v4 15/47] hw/ppc/prep: use pci_init_nic_devices(), David Woodhouse, 2024/01/26
- [PATCH v4 09/47] hw/arm/virt: use pci_init_nic_devices(), David Woodhouse, 2024/01/26
- [PATCH v4 43/47] hw/xtensa/xtfpga: use qemu_create_nic_device(), David Woodhouse, 2024/01/26
- [PATCH v4 42/47] hw/sparc/sun4m: use qemu_find_nic_info(), David Woodhouse, 2024/01/26
- [PATCH v4 01/47] net: add qemu_{configure, create}_nic_device(), qemu_find_nic_info(), David Woodhouse, 2024/01/26
- [PATCH v4 32/47] hw/m68k/mcf5208: use qemu_create_nic_device(), David Woodhouse, 2024/01/26
- [PATCH v4 06/47] hw/xen: use qemu_create_nic_bus_devices() to instantiate Xen NICs, David Woodhouse, 2024/01/26
- [PATCH v4 23/47] hw/arm/exynos4: use qemu_create_nic_device(), David Woodhouse, 2024/01/26
- [PATCH v4 28/47] hw/arm/npcm7xx: use qemu_configure_nic_device, allow emc0/emc1 as aliases, David Woodhouse, 2024/01/26
- [PATCH v4 11/47] hw/loongarch: use pci_init_nic_devices(), David Woodhouse, 2024/01/26