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"
28 #include "qemu-common.h"
34 #include "hw/ppc/spapr.h"
35 #include "hw/ppc/spapr_vio.h"
36 #include "sysemu/sysemu.h"
41 #define MAX_PACKET_SIZE 65536
46 #define DPRINTF(fmt...) do { fprintf(stderr, fmt); } while (0)
48 #define DPRINTF(fmt...)
51 /* Compatibility flags for migration */
52 #define SPAPRVLAN_FLAG_RX_BUF_POOLS_BIT 0
53 #define SPAPRVLAN_FLAG_RX_BUF_POOLS (1 << SPAPRVLAN_FLAG_RX_BUF_POOLS_BIT)
59 typedef uint64_t vlan_bd_t;
61 #define VLAN_BD_VALID 0x8000000000000000ULL
62 #define VLAN_BD_TOGGLE 0x4000000000000000ULL
63 #define VLAN_BD_NO_CSUM 0x0200000000000000ULL
64 #define VLAN_BD_CSUM_GOOD 0x0100000000000000ULL
65 #define VLAN_BD_LEN_MASK 0x00ffffff00000000ULL
66 #define VLAN_BD_LEN(bd) (((bd) & VLAN_BD_LEN_MASK) >> 32)
67 #define VLAN_BD_ADDR_MASK 0x00000000ffffffffULL
68 #define VLAN_BD_ADDR(bd) ((bd) & VLAN_BD_ADDR_MASK)
70 #define VLAN_VALID_BD(addr, len) (VLAN_BD_VALID | \
71 (((len) << 32) & VLAN_BD_LEN_MASK) | \
72 (addr & VLAN_BD_ADDR_MASK))
74 #define VLAN_RXQC_TOGGLE 0x80
75 #define VLAN_RXQC_VALID 0x40
76 #define VLAN_RXQC_NO_CSUM 0x02
77 #define VLAN_RXQC_CSUM_GOOD 0x01
79 #define VLAN_RQ_ALIGNMENT 16
80 #define VLAN_RXQ_BD_OFF 0
81 #define VLAN_FILTER_BD_OFF 8
82 #define VLAN_RX_BDS_OFF 16
84 * The final 8 bytes of the buffer list is a counter of frames dropped
85 * because there was not a buffer in the buffer list capable of holding
86 * the frame. We must avoid it, or the operating system will report garbage
89 #define VLAN_RX_BDS_LEN (SPAPR_TCE_PAGE_SIZE - VLAN_RX_BDS_OFF - 8)
90 #define VLAN_MAX_BUFS (VLAN_RX_BDS_LEN / 8)
92 #define TYPE_VIO_SPAPR_VLAN_DEVICE "spapr-vlan"
93 #define VIO_SPAPR_VLAN_DEVICE(obj) \
94 OBJECT_CHECK(VIOsPAPRVLANDevice, (obj), TYPE_VIO_SPAPR_VLAN_DEVICE)
96 #define RX_POOL_MAX_BDS 4096
97 #define RX_MAX_POOLS 5
102 vlan_bd_t bds[RX_POOL_MAX_BDS];
105 typedef struct VIOsPAPRVLANDevice {
111 uint32_t add_buf_ptr, use_buf_ptr, rx_bufs;
113 uint32_t compat_flags; /* Compatability flags for migration */
114 RxBufPool *rx_pool[RX_MAX_POOLS]; /* Receive buffer descriptor pools */
115 } VIOsPAPRVLANDevice;
117 static int spapr_vlan_can_receive(NetClientState *nc)
119 VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc);
121 return (dev->isopen && dev->rx_bufs > 0);
125 * Get buffer descriptor from one of our receive buffer pools
127 static vlan_bd_t spapr_vlan_get_rx_bd_from_pool(VIOsPAPRVLANDevice *dev,
133 for (pool = 0; pool < RX_MAX_POOLS; pool++) {
134 if (dev->rx_pool[pool]->count > 0 &&
135 dev->rx_pool[pool]->bufsize >= size + 8) {
139 if (pool == RX_MAX_POOLS) {
140 /* Failed to find a suitable buffer */
144 DPRINTF("Found buffer: pool=%d count=%d rxbufs=%d\n", pool,
145 dev->rx_pool[pool]->count, dev->rx_bufs);
147 /* Remove the buffer from the pool */
148 dev->rx_pool[pool]->count--;
149 bd = dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count];
150 dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count] = 0;
156 * Get buffer descriptor from the receive buffer list page that has been
157 * supplied by the guest with the H_REGISTER_LOGICAL_LAN call
159 static vlan_bd_t spapr_vlan_get_rx_bd_from_page(VIOsPAPRVLANDevice *dev,
162 int buf_ptr = dev->use_buf_ptr;
167 if (buf_ptr >= VLAN_RX_BDS_LEN + VLAN_RX_BDS_OFF) {
168 buf_ptr = VLAN_RX_BDS_OFF;
171 bd = vio_ldq(&dev->sdev, dev->buf_list + buf_ptr);
172 DPRINTF("use_buf_ptr=%d bd=0x%016llx\n",
173 buf_ptr, (unsigned long long)bd);
174 } while ((!(bd & VLAN_BD_VALID) || VLAN_BD_LEN(bd) < size + 8)
175 && buf_ptr != dev->use_buf_ptr);
177 if (!(bd & VLAN_BD_VALID) || VLAN_BD_LEN(bd) < size + 8) {
178 /* Failed to find a suitable buffer */
182 /* Remove the buffer from the pool */
183 dev->use_buf_ptr = buf_ptr;
184 vio_stq(&dev->sdev, dev->buf_list + dev->use_buf_ptr, 0);
186 DPRINTF("Found buffer: ptr=%d rxbufs=%d\n", dev->use_buf_ptr, dev->rx_bufs);
191 static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
194 VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc);
195 VIOsPAPRDevice *sdev = VIO_SPAPR_DEVICE(dev);
196 vlan_bd_t rxq_bd = vio_ldq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF);
201 DPRINTF("spapr_vlan_receive() [%s] rx_bufs=%d\n", sdev->qdev.id,
212 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
213 bd = spapr_vlan_get_rx_bd_from_pool(dev, size);
215 bd = spapr_vlan_get_rx_bd_from_page(dev, size);
223 /* Transfer the packet data */
224 if (spapr_vio_dma_write(sdev, VLAN_BD_ADDR(bd) + 8, buf, size) < 0) {
228 DPRINTF("spapr_vlan_receive: DMA write completed\n");
230 /* Update the receive queue */
231 control = VLAN_RXQC_TOGGLE | VLAN_RXQC_VALID;
232 if (rxq_bd & VLAN_BD_TOGGLE) {
233 control ^= VLAN_RXQC_TOGGLE;
236 handle = vio_ldq(sdev, VLAN_BD_ADDR(bd));
237 vio_stq(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 8, handle);
238 vio_stl(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 4, size);
239 vio_sth(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 2, 8);
240 vio_stb(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr, control);
242 DPRINTF("wrote rxq entry (ptr=0x%llx): 0x%016llx 0x%016llx\n",
243 (unsigned long long)dev->rxq_ptr,
244 (unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
246 (unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
250 if (dev->rxq_ptr >= VLAN_BD_LEN(rxq_bd)) {
252 vio_stq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF, rxq_bd ^ VLAN_BD_TOGGLE);
255 if (sdev->signal_state & 1) {
256 qemu_irq_pulse(spapr_vio_qirq(sdev));
262 static NetClientInfo net_spapr_vlan_info = {
263 .type = NET_CLIENT_OPTIONS_KIND_NIC,
264 .size = sizeof(NICState),
265 .can_receive = spapr_vlan_can_receive,
266 .receive = spapr_vlan_receive,
269 static void spapr_vlan_reset_rx_pool(RxBufPool *rxp)
272 * Use INT_MAX as bufsize so that unused buffers are moved to the end
273 * of the list during the qsort in spapr_vlan_add_rxbuf_to_pool() later.
275 rxp->bufsize = INT_MAX;
277 memset(rxp->bds, 0, sizeof(rxp->bds));
280 static void spapr_vlan_reset(VIOsPAPRDevice *sdev)
282 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
289 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
290 for (i = 0; i < RX_MAX_POOLS; i++) {
291 spapr_vlan_reset_rx_pool(dev->rx_pool[i]);
296 static void spapr_vlan_realize(VIOsPAPRDevice *sdev, Error **errp)
298 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
300 qemu_macaddr_default_if_unset(&dev->nicconf.macaddr);
302 dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf,
303 object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev);
304 qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macaddr.a);
307 static void spapr_vlan_instance_init(Object *obj)
309 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(obj);
312 device_add_bootindex_property(obj, &dev->nicconf.bootindex,
316 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
317 for (i = 0; i < RX_MAX_POOLS; i++) {
318 dev->rx_pool[i] = g_new(RxBufPool, 1);
319 spapr_vlan_reset_rx_pool(dev->rx_pool[i]);
324 static void spapr_vlan_instance_finalize(Object *obj)
326 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(obj);
329 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
330 for (i = 0; i < RX_MAX_POOLS; i++) {
331 g_free(dev->rx_pool[i]);
332 dev->rx_pool[i] = NULL;
337 void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd)
341 dev = qdev_create(&bus->bus, "spapr-vlan");
343 qdev_set_nic_properties(dev, nd);
345 qdev_init_nofail(dev);
348 static int spapr_vlan_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
350 VIOsPAPRVLANDevice *vdev = VIO_SPAPR_VLAN_DEVICE(dev);
351 uint8_t padded_mac[8] = {0, 0};
354 /* Some old phyp versions give the mac address in an 8-byte
355 * property. The kernel driver has an insane workaround for this;
356 * rather than doing the obvious thing and checking the property
357 * length, it checks whether the first byte has 0b10 in the low
358 * bits. If a correct 6-byte property has a different first byte
359 * the kernel will get the wrong mac address, overrunning its
360 * buffer in the process (read only, thank goodness).
362 * Here we workaround the kernel workaround by always supplying an
363 * 8-byte property, with the mac address in the last six bytes */
364 memcpy(&padded_mac[2], &vdev->nicconf.macaddr, ETH_ALEN);
365 ret = fdt_setprop(fdt, node_off, "local-mac-address",
366 padded_mac, sizeof(padded_mac));
371 ret = fdt_setprop_cell(fdt, node_off, "ibm,mac-address-filters", 0);
379 static int check_bd(VIOsPAPRVLANDevice *dev, vlan_bd_t bd,
380 target_ulong alignment)
382 if ((VLAN_BD_ADDR(bd) % alignment)
383 || (VLAN_BD_LEN(bd) % alignment)) {
387 if (!spapr_vio_dma_valid(&dev->sdev, VLAN_BD_ADDR(bd),
388 VLAN_BD_LEN(bd), DMA_DIRECTION_FROM_DEVICE)
389 || !spapr_vio_dma_valid(&dev->sdev, VLAN_BD_ADDR(bd),
390 VLAN_BD_LEN(bd), DMA_DIRECTION_TO_DEVICE)) {
397 static target_ulong h_register_logical_lan(PowerPCCPU *cpu,
398 sPAPRMachineState *spapr,
402 target_ulong reg = args[0];
403 target_ulong buf_list = args[1];
404 target_ulong rec_queue = args[2];
405 target_ulong filter_list = args[3];
406 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
407 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
408 vlan_bd_t filter_list_bd;
415 hcall_dprintf("H_REGISTER_LOGICAL_LAN called twice without "
416 "H_FREE_LOGICAL_LAN\n");
420 if (check_bd(dev, VLAN_VALID_BD(buf_list, SPAPR_TCE_PAGE_SIZE),
421 SPAPR_TCE_PAGE_SIZE) < 0) {
422 hcall_dprintf("Bad buf_list 0x" TARGET_FMT_lx "\n", buf_list);
426 filter_list_bd = VLAN_VALID_BD(filter_list, SPAPR_TCE_PAGE_SIZE);
427 if (check_bd(dev, filter_list_bd, SPAPR_TCE_PAGE_SIZE) < 0) {
428 hcall_dprintf("Bad filter_list 0x" TARGET_FMT_lx "\n", filter_list);
432 if (!(rec_queue & VLAN_BD_VALID)
433 || (check_bd(dev, rec_queue, VLAN_RQ_ALIGNMENT) < 0)) {
434 hcall_dprintf("Bad receive queue\n");
438 dev->buf_list = buf_list;
439 sdev->signal_state = 0;
441 rec_queue &= ~VLAN_BD_TOGGLE;
443 /* Initialize the buffer list */
444 vio_stq(sdev, buf_list, rec_queue);
445 vio_stq(sdev, buf_list + 8, filter_list_bd);
446 spapr_vio_dma_set(sdev, buf_list + VLAN_RX_BDS_OFF, 0,
447 SPAPR_TCE_PAGE_SIZE - VLAN_RX_BDS_OFF);
448 dev->add_buf_ptr = VLAN_RX_BDS_OFF - 8;
449 dev->use_buf_ptr = VLAN_RX_BDS_OFF - 8;
453 /* Initialize the receive queue */
454 spapr_vio_dma_set(sdev, VLAN_BD_ADDR(rec_queue), 0, VLAN_BD_LEN(rec_queue));
457 qemu_flush_queued_packets(qemu_get_queue(dev->nic));
463 static target_ulong h_free_logical_lan(PowerPCCPU *cpu,
464 sPAPRMachineState *spapr,
465 target_ulong opcode, target_ulong *args)
467 target_ulong reg = args[0];
468 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
469 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
476 hcall_dprintf("H_FREE_LOGICAL_LAN called without "
477 "H_REGISTER_LOGICAL_LAN\n");
481 spapr_vlan_reset(sdev);
486 * Used for qsort, this function compares two RxBufPools by size.
488 static int rx_pool_size_compare(const void *p1, const void *p2)
490 const RxBufPool *pool1 = *(RxBufPool **)p1;
491 const RxBufPool *pool2 = *(RxBufPool **)p2;
493 if (pool1->bufsize < pool2->bufsize) {
496 return pool1->bufsize > pool2->bufsize;
500 * Search for a matching buffer pool with exact matching size,
501 * or return -1 if no matching pool has been found.
503 static int spapr_vlan_get_rx_pool_id(VIOsPAPRVLANDevice *dev, int size)
507 for (pool = 0; pool < RX_MAX_POOLS; pool++) {
508 if (dev->rx_pool[pool]->bufsize == size) {
517 * Enqueuing receive buffer by adding it to one of our receive buffer pools
519 static target_long spapr_vlan_add_rxbuf_to_pool(VIOsPAPRVLANDevice *dev,
522 int size = VLAN_BD_LEN(buf);
525 pool = spapr_vlan_get_rx_pool_id(dev, size);
528 * No matching pool found? Try to use a new one. If the guest used all
529 * pools before, but changed the size of one pool inbetween, we might
530 * need to recycle that pool here (if it's empty already). Thus scan
531 * all buffer pools now, starting with the last (likely empty) one.
533 for (pool = RX_MAX_POOLS - 1; pool >= 0 ; pool--) {
534 if (dev->rx_pool[pool]->count == 0) {
535 dev->rx_pool[pool]->bufsize = size;
537 * Sort pools by size so that spapr_vlan_receive()
538 * can later find the smallest buffer pool easily.
540 qsort(dev->rx_pool, RX_MAX_POOLS, sizeof(dev->rx_pool[0]),
541 rx_pool_size_compare);
542 pool = spapr_vlan_get_rx_pool_id(dev, size);
543 DPRINTF("created RX pool %d for size %lld\n", pool,
549 /* Still no usable pool? Give up */
550 if (pool < 0 || dev->rx_pool[pool]->count >= RX_POOL_MAX_BDS) {
554 DPRINTF("h_add_llan_buf(): Add buf using pool %i (size %lli, count=%i)\n",
555 pool, VLAN_BD_LEN(buf), dev->rx_pool[pool]->count);
557 dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count++] = buf;
563 * This is the old way of enqueuing receive buffers: Add it to the rx queue
564 * page that has been supplied by the guest (which is quite limited in size).
566 static target_long spapr_vlan_add_rxbuf_to_page(VIOsPAPRVLANDevice *dev,
571 if (dev->rx_bufs >= VLAN_MAX_BUFS) {
576 dev->add_buf_ptr += 8;
577 if (dev->add_buf_ptr >= VLAN_RX_BDS_LEN + VLAN_RX_BDS_OFF) {
578 dev->add_buf_ptr = VLAN_RX_BDS_OFF;
581 bd = vio_ldq(&dev->sdev, dev->buf_list + dev->add_buf_ptr);
582 } while (bd & VLAN_BD_VALID);
584 vio_stq(&dev->sdev, dev->buf_list + dev->add_buf_ptr, buf);
586 DPRINTF("h_add_llan_buf(): Added buf ptr=%d rx_bufs=%d bd=0x%016llx\n",
587 dev->add_buf_ptr, dev->rx_bufs, (unsigned long long)buf);
592 static target_ulong h_add_logical_lan_buffer(PowerPCCPU *cpu,
593 sPAPRMachineState *spapr,
597 target_ulong reg = args[0];
598 target_ulong buf = args[1];
599 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
600 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
603 DPRINTF("H_ADD_LOGICAL_LAN_BUFFER(0x" TARGET_FMT_lx
604 ", 0x" TARGET_FMT_lx ")\n", reg, buf);
607 hcall_dprintf("Bad device\n");
611 if ((check_bd(dev, buf, 4) < 0)
612 || (VLAN_BD_LEN(buf) < 16)) {
613 hcall_dprintf("Bad buffer enqueued\n");
621 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
622 ret = spapr_vlan_add_rxbuf_to_pool(dev, buf);
624 ret = spapr_vlan_add_rxbuf_to_page(dev, buf);
632 qemu_flush_queued_packets(qemu_get_queue(dev->nic));
637 static target_ulong h_send_logical_lan(PowerPCCPU *cpu,
638 sPAPRMachineState *spapr,
639 target_ulong opcode, target_ulong *args)
641 target_ulong reg = args[0];
642 target_ulong *bufs = args + 1;
643 target_ulong continue_token = args[7];
644 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
645 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
651 DPRINTF("H_SEND_LOGICAL_LAN(0x" TARGET_FMT_lx ", <bufs>, 0x"
652 TARGET_FMT_lx ")\n", reg, continue_token);
658 DPRINTF("rxbufs = %d\n", dev->rx_bufs);
664 if (continue_token) {
665 return H_HARDWARE; /* FIXME actually handle this */
669 for (i = 0; i < 6; i++) {
670 DPRINTF(" buf desc: 0x" TARGET_FMT_lx "\n", bufs[i]);
671 if (!(bufs[i] & VLAN_BD_VALID)) {
674 total_len += VLAN_BD_LEN(bufs[i]);
678 DPRINTF("h_send_logical_lan() %d buffers, total length 0x%x\n",
681 if (total_len == 0) {
685 if (total_len > MAX_PACKET_SIZE) {
686 /* Don't let the guest force too large an allocation */
690 lbuf = alloca(total_len);
692 for (i = 0; i < nbufs; i++) {
693 ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
694 p, VLAN_BD_LEN(bufs[i]));
699 p += VLAN_BD_LEN(bufs[i]);
702 qemu_send_packet(qemu_get_queue(dev->nic), lbuf, total_len);
707 static target_ulong h_multicast_ctrl(PowerPCCPU *cpu, sPAPRMachineState *spapr,
708 target_ulong opcode, target_ulong *args)
710 target_ulong reg = args[0];
711 VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
720 static Property spapr_vlan_properties[] = {
721 DEFINE_SPAPR_PROPERTIES(VIOsPAPRVLANDevice, sdev),
722 DEFINE_NIC_PROPERTIES(VIOsPAPRVLANDevice, nicconf),
723 DEFINE_PROP_BIT("use-rx-buffer-pools", VIOsPAPRVLANDevice,
724 compat_flags, SPAPRVLAN_FLAG_RX_BUF_POOLS_BIT, true),
725 DEFINE_PROP_END_OF_LIST(),
728 static bool spapr_vlan_rx_buffer_pools_needed(void *opaque)
730 VIOsPAPRVLANDevice *dev = opaque;
732 return (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) != 0;
735 static const VMStateDescription vmstate_rx_buffer_pool = {
736 .name = "spapr_llan/rx_buffer_pool",
738 .minimum_version_id = 1,
739 .needed = spapr_vlan_rx_buffer_pools_needed,
740 .fields = (VMStateField[]) {
741 VMSTATE_INT32(bufsize, RxBufPool),
742 VMSTATE_INT32(count, RxBufPool),
743 VMSTATE_UINT64_ARRAY(bds, RxBufPool, RX_POOL_MAX_BDS),
744 VMSTATE_END_OF_LIST()
748 static const VMStateDescription vmstate_rx_pools = {
749 .name = "spapr_llan/rx_pools",
751 .minimum_version_id = 1,
752 .needed = spapr_vlan_rx_buffer_pools_needed,
753 .fields = (VMStateField[]) {
754 VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(rx_pool, VIOsPAPRVLANDevice,
756 vmstate_rx_buffer_pool, RxBufPool),
757 VMSTATE_END_OF_LIST()
761 static const VMStateDescription vmstate_spapr_llan = {
762 .name = "spapr_llan",
764 .minimum_version_id = 1,
765 .fields = (VMStateField[]) {
766 VMSTATE_SPAPR_VIO(sdev, VIOsPAPRVLANDevice),
768 VMSTATE_BOOL(isopen, VIOsPAPRVLANDevice),
769 VMSTATE_UINT64(buf_list, VIOsPAPRVLANDevice),
770 VMSTATE_UINT32(add_buf_ptr, VIOsPAPRVLANDevice),
771 VMSTATE_UINT32(use_buf_ptr, VIOsPAPRVLANDevice),
772 VMSTATE_UINT32(rx_bufs, VIOsPAPRVLANDevice),
773 VMSTATE_UINT64(rxq_ptr, VIOsPAPRVLANDevice),
775 VMSTATE_END_OF_LIST()
777 .subsections = (const VMStateDescription * []) {
783 static void spapr_vlan_class_init(ObjectClass *klass, void *data)
785 DeviceClass *dc = DEVICE_CLASS(klass);
786 VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
788 k->realize = spapr_vlan_realize;
789 k->reset = spapr_vlan_reset;
790 k->devnode = spapr_vlan_devnode;
791 k->dt_name = "l-lan";
792 k->dt_type = "network";
793 k->dt_compatible = "IBM,l-lan";
794 k->signal_mask = 0x1;
795 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
796 dc->props = spapr_vlan_properties;
797 k->rtce_window_size = 0x10000000;
798 dc->vmsd = &vmstate_spapr_llan;
801 static const TypeInfo spapr_vlan_info = {
802 .name = TYPE_VIO_SPAPR_VLAN_DEVICE,
803 .parent = TYPE_VIO_SPAPR_DEVICE,
804 .instance_size = sizeof(VIOsPAPRVLANDevice),
805 .class_init = spapr_vlan_class_init,
806 .instance_init = spapr_vlan_instance_init,
807 .instance_finalize = spapr_vlan_instance_finalize,
810 static void spapr_vlan_register_types(void)
812 spapr_register_hypercall(H_REGISTER_LOGICAL_LAN, h_register_logical_lan);
813 spapr_register_hypercall(H_FREE_LOGICAL_LAN, h_free_logical_lan);
814 spapr_register_hypercall(H_SEND_LOGICAL_LAN, h_send_logical_lan);
815 spapr_register_hypercall(H_ADD_LOGICAL_LAN_BUFFER,
816 h_add_logical_lan_buffer);
817 spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
818 type_register_static(&spapr_vlan_info);
821 type_init(spapr_vlan_register_types)