2 * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator
4 * PAPR Inter-VM Logical Lan, aka ibmveth
6 * Copyright (c) 2010,2011 David Gibson, IBM Corporation.
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include "qemu/osdep.h"
31 #include "hw/ppc/spapr.h"
32 #include "hw/ppc/spapr_vio.h"
33 #include "sysemu/sysemu.h"
38 #define MAX_PACKET_SIZE 65536
43 #define DPRINTF(fmt...) do { fprintf(stderr, fmt); } while (0)
45 #define DPRINTF(fmt...)
48 /* Compatibility flags for migration */
49 #define SPAPRVLAN_FLAG_RX_BUF_POOLS_BIT 0
50 #define SPAPRVLAN_FLAG_RX_BUF_POOLS (1 << SPAPRVLAN_FLAG_RX_BUF_POOLS_BIT)
56 typedef uint64_t vlan_bd_t;
58 #define VLAN_BD_VALID 0x8000000000000000ULL
59 #define VLAN_BD_TOGGLE 0x4000000000000000ULL
60 #define VLAN_BD_NO_CSUM 0x0200000000000000ULL
61 #define VLAN_BD_CSUM_GOOD 0x0100000000000000ULL
62 #define VLAN_BD_LEN_MASK 0x00ffffff00000000ULL
63 #define VLAN_BD_LEN(bd) (((bd) & VLAN_BD_LEN_MASK) >> 32)
64 #define VLAN_BD_ADDR_MASK 0x00000000ffffffffULL
65 #define VLAN_BD_ADDR(bd) ((bd) & VLAN_BD_ADDR_MASK)
67 #define VLAN_VALID_BD(addr, len) (VLAN_BD_VALID | \
68 (((len) << 32) & VLAN_BD_LEN_MASK) | \
69 (addr & VLAN_BD_ADDR_MASK))
71 #define VLAN_RXQC_TOGGLE 0x80
72 #define VLAN_RXQC_VALID 0x40
73 #define VLAN_RXQC_NO_CSUM 0x02
74 #define VLAN_RXQC_CSUM_GOOD 0x01
76 #define VLAN_RQ_ALIGNMENT 16
77 #define VLAN_RXQ_BD_OFF 0
78 #define VLAN_FILTER_BD_OFF 8
79 #define VLAN_RX_BDS_OFF 16
81 * The final 8 bytes of the buffer list is a counter of frames dropped
82 * because there was not a buffer in the buffer list capable of holding
83 * the frame. We must avoid it, or the operating system will report garbage
86 #define VLAN_RX_BDS_LEN (SPAPR_TCE_PAGE_SIZE - VLAN_RX_BDS_OFF - 8)
87 #define VLAN_MAX_BUFS (VLAN_RX_BDS_LEN / 8)
89 #define TYPE_VIO_SPAPR_VLAN_DEVICE "spapr-vlan"
90 #define VIO_SPAPR_VLAN_DEVICE(obj) \
91 OBJECT_CHECK(VIOsPAPRVLANDevice, (obj), TYPE_VIO_SPAPR_VLAN_DEVICE)
93 #define RX_POOL_MAX_BDS 4096
94 #define RX_MAX_POOLS 5
99 vlan_bd_t bds[RX_POOL_MAX_BDS];
102 typedef struct VIOsPAPRVLANDevice {
107 target_ulong buf_list;
108 uint32_t add_buf_ptr, use_buf_ptr, rx_bufs;
109 target_ulong rxq_ptr;
110 uint32_t compat_flags; /* Compatability flags for migration */
111 RxBufPool *rx_pool[RX_MAX_POOLS]; /* Receive buffer descriptor pools */
112 } VIOsPAPRVLANDevice;
114 static int spapr_vlan_can_receive(NetClientState *nc)
116 VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc);
118 return (dev->isopen && dev->rx_bufs > 0);
122 * Get buffer descriptor from one of our receive buffer pools
124 static vlan_bd_t spapr_vlan_get_rx_bd_from_pool(VIOsPAPRVLANDevice *dev,
130 for (pool = 0; pool < RX_MAX_POOLS; pool++) {
131 if (dev->rx_pool[pool]->count > 0 &&
132 dev->rx_pool[pool]->bufsize >= size + 8) {
136 if (pool == RX_MAX_POOLS) {
137 /* Failed to find a suitable buffer */
141 DPRINTF("Found buffer: pool=%d count=%d rxbufs=%d\n", pool,
142 dev->rx_pool[pool]->count, dev->rx_bufs);
144 /* Remove the buffer from the pool */
145 dev->rx_pool[pool]->count--;
146 bd = dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count];
147 dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count] = 0;
153 * Get buffer descriptor from the receive buffer list page that has been
154 * supplied by the guest with the H_REGISTER_LOGICAL_LAN call
156 static vlan_bd_t spapr_vlan_get_rx_bd_from_page(VIOsPAPRVLANDevice *dev,
159 int buf_ptr = dev->use_buf_ptr;
164 if (buf_ptr >= VLAN_RX_BDS_LEN + VLAN_RX_BDS_OFF) {
165 buf_ptr = VLAN_RX_BDS_OFF;
168 bd = vio_ldq(&dev->sdev, dev->buf_list + buf_ptr);
169 DPRINTF("use_buf_ptr=%d bd=0x%016llx\n",
170 buf_ptr, (unsigned long long)bd);
171 } while ((!(bd & VLAN_BD_VALID) || VLAN_BD_LEN(bd) < size + 8)
172 && buf_ptr != dev->use_buf_ptr);
174 if (!(bd & VLAN_BD_VALID) || VLAN_BD_LEN(bd) < size + 8) {
175 /* Failed to find a suitable buffer */
179 /* Remove the buffer from the pool */
180 dev->use_buf_ptr = buf_ptr;
181 vio_stq(&dev->sdev, dev->buf_list + dev->use_buf_ptr, 0);
183 DPRINTF("Found buffer: ptr=%d rxbufs=%d\n", dev->use_buf_ptr, dev->rx_bufs);
188 static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
191 VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc);
192 VIOsPAPRDevice *sdev = VIO_SPAPR_DEVICE(dev);
193 vlan_bd_t rxq_bd = vio_ldq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF);
198 DPRINTF("spapr_vlan_receive() [%s] rx_bufs=%d\n", sdev->qdev.id,
209 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
210 bd = spapr_vlan_get_rx_bd_from_pool(dev, size);
212 bd = spapr_vlan_get_rx_bd_from_page(dev, size);
220 /* Transfer the packet data */
221 if (spapr_vio_dma_write(sdev, VLAN_BD_ADDR(bd) + 8, buf, size) < 0) {
225 DPRINTF("spapr_vlan_receive: DMA write completed\n");
227 /* Update the receive queue */
228 control = VLAN_RXQC_TOGGLE | VLAN_RXQC_VALID;
229 if (rxq_bd & VLAN_BD_TOGGLE) {
230 control ^= VLAN_RXQC_TOGGLE;
233 handle = vio_ldq(sdev, VLAN_BD_ADDR(bd));
234 vio_stq(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 8, handle);
235 vio_stl(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 4, size);
236 vio_sth(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 2, 8);
237 vio_stb(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr, control);
239 DPRINTF("wrote rxq entry (ptr=0x%llx): 0x%016llx 0x%016llx\n",
240 (unsigned long long)dev->rxq_ptr,
241 (unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
243 (unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
247 if (dev->rxq_ptr >= VLAN_BD_LEN(rxq_bd)) {
249 vio_stq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF, rxq_bd ^ VLAN_BD_TOGGLE);
252 if (sdev->signal_state & 1) {
253 qemu_irq_pulse(spapr_vio_qirq(sdev));
259 static NetClientInfo net_spapr_vlan_info = {
260 .type = NET_CLIENT_OPTIONS_KIND_NIC,
261 .size = sizeof(NICState),
262 .can_receive = spapr_vlan_can_receive,
263 .receive = spapr_vlan_receive,
266 static void spapr_vlan_reset_rx_pool(RxBufPool *rxp)
269 * Use INT_MAX as bufsize so that unused buffers are moved to the end
270 * of the list during the qsort in spapr_vlan_add_rxbuf_to_pool() later.
272 rxp->bufsize = INT_MAX;
274 memset(rxp->bds, 0, sizeof(rxp->bds));
277 static void spapr_vlan_reset(VIOsPAPRDevice *sdev)
279 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
286 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
287 for (i = 0; i < RX_MAX_POOLS; i++) {
288 spapr_vlan_reset_rx_pool(dev->rx_pool[i]);
293 static void spapr_vlan_realize(VIOsPAPRDevice *sdev, Error **errp)
295 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
297 qemu_macaddr_default_if_unset(&dev->nicconf.macaddr);
299 dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf,
300 object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev);
301 qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macaddr.a);
304 static void spapr_vlan_instance_init(Object *obj)
306 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(obj);
309 device_add_bootindex_property(obj, &dev->nicconf.bootindex,
313 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
314 for (i = 0; i < RX_MAX_POOLS; i++) {
315 dev->rx_pool[i] = g_new(RxBufPool, 1);
316 spapr_vlan_reset_rx_pool(dev->rx_pool[i]);
321 static void spapr_vlan_instance_finalize(Object *obj)
323 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(obj);
326 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
327 for (i = 0; i < RX_MAX_POOLS; i++) {
328 g_free(dev->rx_pool[i]);
329 dev->rx_pool[i] = NULL;
334 void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd)
338 dev = qdev_create(&bus->bus, "spapr-vlan");
340 qdev_set_nic_properties(dev, nd);
342 qdev_init_nofail(dev);
345 static int spapr_vlan_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
347 VIOsPAPRVLANDevice *vdev = VIO_SPAPR_VLAN_DEVICE(dev);
348 uint8_t padded_mac[8] = {0, 0};
351 /* Some old phyp versions give the mac address in an 8-byte
352 * property. The kernel driver has an insane workaround for this;
353 * rather than doing the obvious thing and checking the property
354 * length, it checks whether the first byte has 0b10 in the low
355 * bits. If a correct 6-byte property has a different first byte
356 * the kernel will get the wrong mac address, overrunning its
357 * buffer in the process (read only, thank goodness).
359 * Here we workaround the kernel workaround by always supplying an
360 * 8-byte property, with the mac address in the last six bytes */
361 memcpy(&padded_mac[2], &vdev->nicconf.macaddr, ETH_ALEN);
362 ret = fdt_setprop(fdt, node_off, "local-mac-address",
363 padded_mac, sizeof(padded_mac));
368 ret = fdt_setprop_cell(fdt, node_off, "ibm,mac-address-filters", 0);
376 static int check_bd(VIOsPAPRVLANDevice *dev, vlan_bd_t bd,
377 target_ulong alignment)
379 if ((VLAN_BD_ADDR(bd) % alignment)
380 || (VLAN_BD_LEN(bd) % alignment)) {
384 if (!spapr_vio_dma_valid(&dev->sdev, VLAN_BD_ADDR(bd),
385 VLAN_BD_LEN(bd), DMA_DIRECTION_FROM_DEVICE)
386 || !spapr_vio_dma_valid(&dev->sdev, VLAN_BD_ADDR(bd),
387 VLAN_BD_LEN(bd), DMA_DIRECTION_TO_DEVICE)) {
394 static target_ulong h_register_logical_lan(PowerPCCPU *cpu,
395 sPAPRMachineState *spapr,
399 target_ulong reg = args[0];
400 target_ulong buf_list = args[1];
401 target_ulong rec_queue = args[2];
402 target_ulong filter_list = args[3];
403 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
404 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
405 vlan_bd_t filter_list_bd;
412 hcall_dprintf("H_REGISTER_LOGICAL_LAN called twice without "
413 "H_FREE_LOGICAL_LAN\n");
417 if (check_bd(dev, VLAN_VALID_BD(buf_list, SPAPR_TCE_PAGE_SIZE),
418 SPAPR_TCE_PAGE_SIZE) < 0) {
419 hcall_dprintf("Bad buf_list 0x" TARGET_FMT_lx "\n", buf_list);
423 filter_list_bd = VLAN_VALID_BD(filter_list, SPAPR_TCE_PAGE_SIZE);
424 if (check_bd(dev, filter_list_bd, SPAPR_TCE_PAGE_SIZE) < 0) {
425 hcall_dprintf("Bad filter_list 0x" TARGET_FMT_lx "\n", filter_list);
429 if (!(rec_queue & VLAN_BD_VALID)
430 || (check_bd(dev, rec_queue, VLAN_RQ_ALIGNMENT) < 0)) {
431 hcall_dprintf("Bad receive queue\n");
435 dev->buf_list = buf_list;
436 sdev->signal_state = 0;
438 rec_queue &= ~VLAN_BD_TOGGLE;
440 /* Initialize the buffer list */
441 vio_stq(sdev, buf_list, rec_queue);
442 vio_stq(sdev, buf_list + 8, filter_list_bd);
443 spapr_vio_dma_set(sdev, buf_list + VLAN_RX_BDS_OFF, 0,
444 SPAPR_TCE_PAGE_SIZE - VLAN_RX_BDS_OFF);
445 dev->add_buf_ptr = VLAN_RX_BDS_OFF - 8;
446 dev->use_buf_ptr = VLAN_RX_BDS_OFF - 8;
450 /* Initialize the receive queue */
451 spapr_vio_dma_set(sdev, VLAN_BD_ADDR(rec_queue), 0, VLAN_BD_LEN(rec_queue));
454 qemu_flush_queued_packets(qemu_get_queue(dev->nic));
460 static target_ulong h_free_logical_lan(PowerPCCPU *cpu,
461 sPAPRMachineState *spapr,
462 target_ulong opcode, target_ulong *args)
464 target_ulong reg = args[0];
465 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
466 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
473 hcall_dprintf("H_FREE_LOGICAL_LAN called without "
474 "H_REGISTER_LOGICAL_LAN\n");
478 spapr_vlan_reset(sdev);
483 * Used for qsort, this function compares two RxBufPools by size.
485 static int rx_pool_size_compare(const void *p1, const void *p2)
487 const RxBufPool *pool1 = *(RxBufPool **)p1;
488 const RxBufPool *pool2 = *(RxBufPool **)p2;
490 if (pool1->bufsize < pool2->bufsize) {
493 return pool1->bufsize > pool2->bufsize;
497 * Search for a matching buffer pool with exact matching size,
498 * or return -1 if no matching pool has been found.
500 static int spapr_vlan_get_rx_pool_id(VIOsPAPRVLANDevice *dev, int size)
504 for (pool = 0; pool < RX_MAX_POOLS; pool++) {
505 if (dev->rx_pool[pool]->bufsize == size) {
514 * Enqueuing receive buffer by adding it to one of our receive buffer pools
516 static target_long spapr_vlan_add_rxbuf_to_pool(VIOsPAPRVLANDevice *dev,
519 int size = VLAN_BD_LEN(buf);
522 pool = spapr_vlan_get_rx_pool_id(dev, size);
525 * No matching pool found? Try to use a new one. If the guest used all
526 * pools before, but changed the size of one pool inbetween, we might
527 * need to recycle that pool here (if it's empty already). Thus scan
528 * all buffer pools now, starting with the last (likely empty) one.
530 for (pool = RX_MAX_POOLS - 1; pool >= 0 ; pool--) {
531 if (dev->rx_pool[pool]->count == 0) {
532 dev->rx_pool[pool]->bufsize = size;
534 * Sort pools by size so that spapr_vlan_receive()
535 * can later find the smallest buffer pool easily.
537 qsort(dev->rx_pool, RX_MAX_POOLS, sizeof(dev->rx_pool[0]),
538 rx_pool_size_compare);
539 pool = spapr_vlan_get_rx_pool_id(dev, size);
540 DPRINTF("created RX pool %d for size %lld\n", pool,
546 /* Still no usable pool? Give up */
547 if (pool < 0 || dev->rx_pool[pool]->count >= RX_POOL_MAX_BDS) {
551 DPRINTF("h_add_llan_buf(): Add buf using pool %i (size %lli, count=%i)\n",
552 pool, VLAN_BD_LEN(buf), dev->rx_pool[pool]->count);
554 dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count++] = buf;
560 * This is the old way of enqueuing receive buffers: Add it to the rx queue
561 * page that has been supplied by the guest (which is quite limited in size).
563 static target_long spapr_vlan_add_rxbuf_to_page(VIOsPAPRVLANDevice *dev,
568 if (dev->rx_bufs >= VLAN_MAX_BUFS) {
573 dev->add_buf_ptr += 8;
574 if (dev->add_buf_ptr >= VLAN_RX_BDS_LEN + VLAN_RX_BDS_OFF) {
575 dev->add_buf_ptr = VLAN_RX_BDS_OFF;
578 bd = vio_ldq(&dev->sdev, dev->buf_list + dev->add_buf_ptr);
579 } while (bd & VLAN_BD_VALID);
581 vio_stq(&dev->sdev, dev->buf_list + dev->add_buf_ptr, buf);
583 DPRINTF("h_add_llan_buf(): Added buf ptr=%d rx_bufs=%d bd=0x%016llx\n",
584 dev->add_buf_ptr, dev->rx_bufs, (unsigned long long)buf);
589 static target_ulong h_add_logical_lan_buffer(PowerPCCPU *cpu,
590 sPAPRMachineState *spapr,
594 target_ulong reg = args[0];
595 target_ulong buf = args[1];
596 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
597 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
600 DPRINTF("H_ADD_LOGICAL_LAN_BUFFER(0x" TARGET_FMT_lx
601 ", 0x" TARGET_FMT_lx ")\n", reg, buf);
604 hcall_dprintf("Bad device\n");
608 if ((check_bd(dev, buf, 4) < 0)
609 || (VLAN_BD_LEN(buf) < 16)) {
610 hcall_dprintf("Bad buffer enqueued\n");
618 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
619 ret = spapr_vlan_add_rxbuf_to_pool(dev, buf);
621 ret = spapr_vlan_add_rxbuf_to_page(dev, buf);
629 qemu_flush_queued_packets(qemu_get_queue(dev->nic));
634 static target_ulong h_send_logical_lan(PowerPCCPU *cpu,
635 sPAPRMachineState *spapr,
636 target_ulong opcode, target_ulong *args)
638 target_ulong reg = args[0];
639 target_ulong *bufs = args + 1;
640 target_ulong continue_token = args[7];
641 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
642 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
648 DPRINTF("H_SEND_LOGICAL_LAN(0x" TARGET_FMT_lx ", <bufs>, 0x"
649 TARGET_FMT_lx ")\n", reg, continue_token);
655 DPRINTF("rxbufs = %d\n", dev->rx_bufs);
661 if (continue_token) {
662 return H_HARDWARE; /* FIXME actually handle this */
666 for (i = 0; i < 6; i++) {
667 DPRINTF(" buf desc: 0x" TARGET_FMT_lx "\n", bufs[i]);
668 if (!(bufs[i] & VLAN_BD_VALID)) {
671 total_len += VLAN_BD_LEN(bufs[i]);
675 DPRINTF("h_send_logical_lan() %d buffers, total length 0x%x\n",
678 if (total_len == 0) {
682 if (total_len > MAX_PACKET_SIZE) {
683 /* Don't let the guest force too large an allocation */
687 lbuf = alloca(total_len);
689 for (i = 0; i < nbufs; i++) {
690 ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
691 p, VLAN_BD_LEN(bufs[i]));
696 p += VLAN_BD_LEN(bufs[i]);
699 qemu_send_packet(qemu_get_queue(dev->nic), lbuf, total_len);
704 static target_ulong h_multicast_ctrl(PowerPCCPU *cpu, sPAPRMachineState *spapr,
705 target_ulong opcode, target_ulong *args)
707 target_ulong reg = args[0];
708 VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
717 static Property spapr_vlan_properties[] = {
718 DEFINE_SPAPR_PROPERTIES(VIOsPAPRVLANDevice, sdev),
719 DEFINE_NIC_PROPERTIES(VIOsPAPRVLANDevice, nicconf),
720 DEFINE_PROP_BIT("use-rx-buffer-pools", VIOsPAPRVLANDevice,
721 compat_flags, SPAPRVLAN_FLAG_RX_BUF_POOLS_BIT, true),
722 DEFINE_PROP_END_OF_LIST(),
725 static bool spapr_vlan_rx_buffer_pools_needed(void *opaque)
727 VIOsPAPRVLANDevice *dev = opaque;
729 return (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) != 0;
732 static const VMStateDescription vmstate_rx_buffer_pool = {
733 .name = "spapr_llan/rx_buffer_pool",
735 .minimum_version_id = 1,
736 .needed = spapr_vlan_rx_buffer_pools_needed,
737 .fields = (VMStateField[]) {
738 VMSTATE_INT32(bufsize, RxBufPool),
739 VMSTATE_INT32(count, RxBufPool),
740 VMSTATE_UINT64_ARRAY(bds, RxBufPool, RX_POOL_MAX_BDS),
741 VMSTATE_END_OF_LIST()
745 static const VMStateDescription vmstate_rx_pools = {
746 .name = "spapr_llan/rx_pools",
748 .minimum_version_id = 1,
749 .needed = spapr_vlan_rx_buffer_pools_needed,
750 .fields = (VMStateField[]) {
751 VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(rx_pool, VIOsPAPRVLANDevice,
753 vmstate_rx_buffer_pool, RxBufPool),
754 VMSTATE_END_OF_LIST()
758 static const VMStateDescription vmstate_spapr_llan = {
759 .name = "spapr_llan",
761 .minimum_version_id = 1,
762 .fields = (VMStateField[]) {
763 VMSTATE_SPAPR_VIO(sdev, VIOsPAPRVLANDevice),
765 VMSTATE_BOOL(isopen, VIOsPAPRVLANDevice),
766 VMSTATE_UINTTL(buf_list, VIOsPAPRVLANDevice),
767 VMSTATE_UINT32(add_buf_ptr, VIOsPAPRVLANDevice),
768 VMSTATE_UINT32(use_buf_ptr, VIOsPAPRVLANDevice),
769 VMSTATE_UINT32(rx_bufs, VIOsPAPRVLANDevice),
770 VMSTATE_UINTTL(rxq_ptr, VIOsPAPRVLANDevice),
772 VMSTATE_END_OF_LIST()
774 .subsections = (const VMStateDescription * []) {
780 static void spapr_vlan_class_init(ObjectClass *klass, void *data)
782 DeviceClass *dc = DEVICE_CLASS(klass);
783 VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
785 k->realize = spapr_vlan_realize;
786 k->reset = spapr_vlan_reset;
787 k->devnode = spapr_vlan_devnode;
788 k->dt_name = "l-lan";
789 k->dt_type = "network";
790 k->dt_compatible = "IBM,l-lan";
791 k->signal_mask = 0x1;
792 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
793 dc->props = spapr_vlan_properties;
794 k->rtce_window_size = 0x10000000;
795 dc->vmsd = &vmstate_spapr_llan;
798 static const TypeInfo spapr_vlan_info = {
799 .name = TYPE_VIO_SPAPR_VLAN_DEVICE,
800 .parent = TYPE_VIO_SPAPR_DEVICE,
801 .instance_size = sizeof(VIOsPAPRVLANDevice),
802 .class_init = spapr_vlan_class_init,
803 .instance_init = spapr_vlan_instance_init,
804 .instance_finalize = spapr_vlan_instance_finalize,
807 static void spapr_vlan_register_types(void)
809 spapr_register_hypercall(H_REGISTER_LOGICAL_LAN, h_register_logical_lan);
810 spapr_register_hypercall(H_FREE_LOGICAL_LAN, h_free_logical_lan);
811 spapr_register_hypercall(H_SEND_LOGICAL_LAN, h_send_logical_lan);
812 spapr_register_hypercall(H_ADD_LOGICAL_LAN_BUFFER,
813 h_add_logical_lan_buffer);
814 spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
815 type_register_static(&spapr_vlan_info);
818 type_init(spapr_vlan_register_types)