xref: /openbmc/qemu/hw/s390x/virtio-ccw-net.c (revision d2623129a7dec1d3041ad1221dda1ca49c667532)
1efbc1783SThomas Huth /*
2efbc1783SThomas Huth  * virtio ccw net implementation
3efbc1783SThomas Huth  *
4efbc1783SThomas Huth  * Copyright 2012, 2015 IBM Corp.
5efbc1783SThomas Huth  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6efbc1783SThomas Huth  *
7efbc1783SThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8efbc1783SThomas Huth  * your option) any later version. See the COPYING file in the top-level
9efbc1783SThomas Huth  * directory.
10efbc1783SThomas Huth  */
11efbc1783SThomas Huth 
12efbc1783SThomas Huth #include "qemu/osdep.h"
13a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
14efbc1783SThomas Huth #include "hw/virtio/virtio.h"
15efbc1783SThomas Huth #include "qapi/error.h"
160b8fa32fSMarkus Armbruster #include "qemu/module.h"
17efbc1783SThomas Huth #include "virtio-ccw.h"
18efbc1783SThomas Huth 
19efbc1783SThomas Huth static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp)
20efbc1783SThomas Huth {
21efbc1783SThomas Huth     DeviceState *qdev = DEVICE(ccw_dev);
22efbc1783SThomas Huth     VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
23efbc1783SThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
24efbc1783SThomas Huth 
25efbc1783SThomas Huth     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
26efbc1783SThomas Huth                                   object_get_typename(OBJECT(qdev)));
27efbc1783SThomas Huth     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
28efbc1783SThomas Huth     object_property_set_bool(OBJECT(vdev), true, "realized", errp);
29efbc1783SThomas Huth }
30efbc1783SThomas Huth 
31efbc1783SThomas Huth static void virtio_ccw_net_instance_init(Object *obj)
32efbc1783SThomas Huth {
33efbc1783SThomas Huth     VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
34efbc1783SThomas Huth 
35efbc1783SThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
36efbc1783SThomas Huth                                 TYPE_VIRTIO_NET);
37efbc1783SThomas Huth     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
38*d2623129SMarkus Armbruster                               "bootindex");
39efbc1783SThomas Huth }
40efbc1783SThomas Huth 
41efbc1783SThomas Huth static Property virtio_ccw_net_properties[] = {
42efbc1783SThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
43efbc1783SThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
44efbc1783SThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
45efbc1783SThomas Huth                        VIRTIO_CCW_MAX_REV),
46efbc1783SThomas Huth     DEFINE_PROP_END_OF_LIST(),
47efbc1783SThomas Huth };
48efbc1783SThomas Huth 
49efbc1783SThomas Huth static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
50efbc1783SThomas Huth {
51efbc1783SThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
52efbc1783SThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
53efbc1783SThomas Huth 
54efbc1783SThomas Huth     k->realize = virtio_ccw_net_realize;
554f67d30bSMarc-André Lureau     device_class_set_props(dc, virtio_ccw_net_properties);
56efbc1783SThomas Huth     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
57efbc1783SThomas Huth }
58efbc1783SThomas Huth 
59efbc1783SThomas Huth static const TypeInfo virtio_ccw_net = {
60efbc1783SThomas Huth     .name          = TYPE_VIRTIO_NET_CCW,
61efbc1783SThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
62efbc1783SThomas Huth     .instance_size = sizeof(VirtIONetCcw),
63efbc1783SThomas Huth     .instance_init = virtio_ccw_net_instance_init,
64efbc1783SThomas Huth     .class_init    = virtio_ccw_net_class_init,
65efbc1783SThomas Huth };
66efbc1783SThomas Huth 
67efbc1783SThomas Huth static void virtio_ccw_net_register(void)
68efbc1783SThomas Huth {
69efbc1783SThomas Huth     type_register_static(&virtio_ccw_net);
70efbc1783SThomas Huth }
71efbc1783SThomas Huth 
72efbc1783SThomas Huth type_init(virtio_ccw_net_register)
73