xref: /openbmc/qemu/hw/s390x/virtio-ccw-net.c (revision 7da50d6411eede9eb1ff90ba85c30aa748ac4883)
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"
18*7da50d64SPaolo Bonzini #include "hw/virtio/virtio-net.h"
19*7da50d64SPaolo Bonzini 
20*7da50d64SPaolo Bonzini #define TYPE_VIRTIO_NET_CCW "virtio-net-ccw"
21*7da50d64SPaolo Bonzini OBJECT_DECLARE_SIMPLE_TYPE(VirtIONetCcw, VIRTIO_NET_CCW)
22*7da50d64SPaolo Bonzini 
23*7da50d64SPaolo Bonzini struct VirtIONetCcw {
24*7da50d64SPaolo Bonzini     VirtioCcwDevice parent_obj;
25*7da50d64SPaolo Bonzini     VirtIONet vdev;
26*7da50d64SPaolo Bonzini };
27efbc1783SThomas Huth 
28efbc1783SThomas Huth static void virtio_ccw_net_realize(VirtioCcwDevice *ccw_dev, Error **errp)
29efbc1783SThomas Huth {
30efbc1783SThomas Huth     DeviceState *qdev = DEVICE(ccw_dev);
31efbc1783SThomas Huth     VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
32efbc1783SThomas Huth     DeviceState *vdev = DEVICE(&dev->vdev);
33efbc1783SThomas Huth 
34efbc1783SThomas Huth     virtio_net_set_netclient_name(&dev->vdev, qdev->id,
35efbc1783SThomas Huth                                   object_get_typename(OBJECT(qdev)));
3699ba777eSMarkus Armbruster     qdev_realize(vdev, BUS(&ccw_dev->bus), errp);
37efbc1783SThomas Huth }
38efbc1783SThomas Huth 
39efbc1783SThomas Huth static void virtio_ccw_net_instance_init(Object *obj)
40efbc1783SThomas Huth {
41efbc1783SThomas Huth     VirtIONetCcw *dev = VIRTIO_NET_CCW(obj);
42efbc1783SThomas Huth 
43efbc1783SThomas Huth     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
44efbc1783SThomas Huth                                 TYPE_VIRTIO_NET);
45efbc1783SThomas Huth     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
46d2623129SMarkus Armbruster                               "bootindex");
47efbc1783SThomas Huth }
48efbc1783SThomas Huth 
49efbc1783SThomas Huth static Property virtio_ccw_net_properties[] = {
50efbc1783SThomas Huth     DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
51efbc1783SThomas Huth                     VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
52efbc1783SThomas Huth     DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev,
53efbc1783SThomas Huth                        VIRTIO_CCW_MAX_REV),
54efbc1783SThomas Huth     DEFINE_PROP_END_OF_LIST(),
55efbc1783SThomas Huth };
56efbc1783SThomas Huth 
57efbc1783SThomas Huth static void virtio_ccw_net_class_init(ObjectClass *klass, void *data)
58efbc1783SThomas Huth {
59efbc1783SThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
60efbc1783SThomas Huth     VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_CLASS(klass);
61efbc1783SThomas Huth 
62efbc1783SThomas Huth     k->realize = virtio_ccw_net_realize;
634f67d30bSMarc-André Lureau     device_class_set_props(dc, virtio_ccw_net_properties);
64efbc1783SThomas Huth     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
65efbc1783SThomas Huth }
66efbc1783SThomas Huth 
67efbc1783SThomas Huth static const TypeInfo virtio_ccw_net = {
68efbc1783SThomas Huth     .name          = TYPE_VIRTIO_NET_CCW,
69efbc1783SThomas Huth     .parent        = TYPE_VIRTIO_CCW_DEVICE,
70efbc1783SThomas Huth     .instance_size = sizeof(VirtIONetCcw),
71efbc1783SThomas Huth     .instance_init = virtio_ccw_net_instance_init,
72efbc1783SThomas Huth     .class_init    = virtio_ccw_net_class_init,
73efbc1783SThomas Huth };
74efbc1783SThomas Huth 
75efbc1783SThomas Huth static void virtio_ccw_net_register(void)
76efbc1783SThomas Huth {
77efbc1783SThomas Huth     type_register_static(&virtio_ccw_net);
78efbc1783SThomas Huth }
79efbc1783SThomas Huth 
80efbc1783SThomas Huth type_init(virtio_ccw_net_register)
81