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 QEMUTimer *rxp_timer;
114 uint32_t compat_flags; /* Compatability flags for migration */
115 RxBufPool *rx_pool[RX_MAX_POOLS]; /* Receive buffer descriptor pools */
116 } VIOsPAPRVLANDevice;
118 static int spapr_vlan_can_receive(NetClientState *nc)
120 VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc);
122 return (dev->isopen && dev->rx_bufs > 0);
126 * Get buffer descriptor from one of our receive buffer pools
128 static vlan_bd_t spapr_vlan_get_rx_bd_from_pool(VIOsPAPRVLANDevice *dev,
134 for (pool = 0; pool < RX_MAX_POOLS; pool++) {
135 if (dev->rx_pool[pool]->count > 0 &&
136 dev->rx_pool[pool]->bufsize >= size + 8) {
140 if (pool == RX_MAX_POOLS) {
141 /* Failed to find a suitable buffer */
145 DPRINTF("Found buffer: pool=%d count=%d rxbufs=%d\n", pool,
146 dev->rx_pool[pool]->count, dev->rx_bufs);
148 /* Remove the buffer from the pool */
149 dev->rx_pool[pool]->count--;
150 bd = dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count];
151 dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count] = 0;
157 * Get buffer descriptor from the receive buffer list page that has been
158 * supplied by the guest with the H_REGISTER_LOGICAL_LAN call
160 static vlan_bd_t spapr_vlan_get_rx_bd_from_page(VIOsPAPRVLANDevice *dev,
163 int buf_ptr = dev->use_buf_ptr;
168 if (buf_ptr >= VLAN_RX_BDS_LEN + VLAN_RX_BDS_OFF) {
169 buf_ptr = VLAN_RX_BDS_OFF;
172 bd = vio_ldq(&dev->sdev, dev->buf_list + buf_ptr);
173 DPRINTF("use_buf_ptr=%d bd=0x%016llx\n",
174 buf_ptr, (unsigned long long)bd);
175 } while ((!(bd & VLAN_BD_VALID) || VLAN_BD_LEN(bd) < size + 8)
176 && buf_ptr != dev->use_buf_ptr);
178 if (!(bd & VLAN_BD_VALID) || VLAN_BD_LEN(bd) < size + 8) {
179 /* Failed to find a suitable buffer */
183 /* Remove the buffer from the pool */
184 dev->use_buf_ptr = buf_ptr;
185 vio_stq(&dev->sdev, dev->buf_list + dev->use_buf_ptr, 0);
187 DPRINTF("Found buffer: ptr=%d rxbufs=%d\n", dev->use_buf_ptr, dev->rx_bufs);
192 static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
195 VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc);
196 VIOsPAPRDevice *sdev = VIO_SPAPR_DEVICE(dev);
197 vlan_bd_t rxq_bd = vio_ldq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF);
202 DPRINTF("spapr_vlan_receive() [%s] rx_bufs=%d\n", sdev->qdev.id,
213 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
214 bd = spapr_vlan_get_rx_bd_from_pool(dev, size);
216 bd = spapr_vlan_get_rx_bd_from_page(dev, size);
224 /* Transfer the packet data */
225 if (spapr_vio_dma_write(sdev, VLAN_BD_ADDR(bd) + 8, buf, size) < 0) {
229 DPRINTF("spapr_vlan_receive: DMA write completed\n");
231 /* Update the receive queue */
232 control = VLAN_RXQC_TOGGLE | VLAN_RXQC_VALID;
233 if (rxq_bd & VLAN_BD_TOGGLE) {
234 control ^= VLAN_RXQC_TOGGLE;
237 handle = vio_ldq(sdev, VLAN_BD_ADDR(bd));
238 vio_stq(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 8, handle);
239 vio_stl(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 4, size);
240 vio_sth(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr + 2, 8);
241 vio_stb(sdev, VLAN_BD_ADDR(rxq_bd) + dev->rxq_ptr, control);
243 DPRINTF("wrote rxq entry (ptr=0x%llx): 0x%016llx 0x%016llx\n",
244 (unsigned long long)dev->rxq_ptr,
245 (unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
247 (unsigned long long)vio_ldq(sdev, VLAN_BD_ADDR(rxq_bd) +
251 if (dev->rxq_ptr >= VLAN_BD_LEN(rxq_bd)) {
253 vio_stq(sdev, dev->buf_list + VLAN_RXQ_BD_OFF, rxq_bd ^ VLAN_BD_TOGGLE);
256 if (sdev->signal_state & 1) {
257 qemu_irq_pulse(spapr_vio_qirq(sdev));
263 static NetClientInfo net_spapr_vlan_info = {
264 .type = NET_CLIENT_OPTIONS_KIND_NIC,
265 .size = sizeof(NICState),
266 .can_receive = spapr_vlan_can_receive,
267 .receive = spapr_vlan_receive,
270 static void spapr_vlan_flush_rx_queue(void *opaque)
272 VIOsPAPRVLANDevice *dev = opaque;
274 qemu_flush_queued_packets(qemu_get_queue(dev->nic));
277 static void spapr_vlan_reset_rx_pool(RxBufPool *rxp)
280 * Use INT_MAX as bufsize so that unused buffers are moved to the end
281 * of the list during the qsort in spapr_vlan_add_rxbuf_to_pool() later.
283 rxp->bufsize = INT_MAX;
285 memset(rxp->bds, 0, sizeof(rxp->bds));
288 static void spapr_vlan_reset(VIOsPAPRDevice *sdev)
290 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
297 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
298 for (i = 0; i < RX_MAX_POOLS; i++) {
299 spapr_vlan_reset_rx_pool(dev->rx_pool[i]);
304 static void spapr_vlan_realize(VIOsPAPRDevice *sdev, Error **errp)
306 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
308 qemu_macaddr_default_if_unset(&dev->nicconf.macaddr);
310 dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf,
311 object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev);
312 qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macaddr.a);
314 dev->rxp_timer = timer_new_us(QEMU_CLOCK_VIRTUAL, spapr_vlan_flush_rx_queue,
318 static void spapr_vlan_instance_init(Object *obj)
320 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(obj);
323 device_add_bootindex_property(obj, &dev->nicconf.bootindex,
327 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
328 for (i = 0; i < RX_MAX_POOLS; i++) {
329 dev->rx_pool[i] = g_new(RxBufPool, 1);
330 spapr_vlan_reset_rx_pool(dev->rx_pool[i]);
335 static void spapr_vlan_instance_finalize(Object *obj)
337 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(obj);
340 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
341 for (i = 0; i < RX_MAX_POOLS; i++) {
342 g_free(dev->rx_pool[i]);
343 dev->rx_pool[i] = NULL;
347 if (dev->rxp_timer) {
348 timer_del(dev->rxp_timer);
349 timer_free(dev->rxp_timer);
353 void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd)
357 dev = qdev_create(&bus->bus, "spapr-vlan");
359 qdev_set_nic_properties(dev, nd);
361 qdev_init_nofail(dev);
364 static int spapr_vlan_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
366 VIOsPAPRVLANDevice *vdev = VIO_SPAPR_VLAN_DEVICE(dev);
367 uint8_t padded_mac[8] = {0, 0};
370 /* Some old phyp versions give the mac address in an 8-byte
371 * property. The kernel driver has an insane workaround for this;
372 * rather than doing the obvious thing and checking the property
373 * length, it checks whether the first byte has 0b10 in the low
374 * bits. If a correct 6-byte property has a different first byte
375 * the kernel will get the wrong mac address, overrunning its
376 * buffer in the process (read only, thank goodness).
378 * Here we workaround the kernel workaround by always supplying an
379 * 8-byte property, with the mac address in the last six bytes */
380 memcpy(&padded_mac[2], &vdev->nicconf.macaddr, ETH_ALEN);
381 ret = fdt_setprop(fdt, node_off, "local-mac-address",
382 padded_mac, sizeof(padded_mac));
387 ret = fdt_setprop_cell(fdt, node_off, "ibm,mac-address-filters", 0);
395 static int check_bd(VIOsPAPRVLANDevice *dev, vlan_bd_t bd,
396 target_ulong alignment)
398 if ((VLAN_BD_ADDR(bd) % alignment)
399 || (VLAN_BD_LEN(bd) % alignment)) {
403 if (!spapr_vio_dma_valid(&dev->sdev, VLAN_BD_ADDR(bd),
404 VLAN_BD_LEN(bd), DMA_DIRECTION_FROM_DEVICE)
405 || !spapr_vio_dma_valid(&dev->sdev, VLAN_BD_ADDR(bd),
406 VLAN_BD_LEN(bd), DMA_DIRECTION_TO_DEVICE)) {
413 static target_ulong h_register_logical_lan(PowerPCCPU *cpu,
414 sPAPRMachineState *spapr,
418 target_ulong reg = args[0];
419 target_ulong buf_list = args[1];
420 target_ulong rec_queue = args[2];
421 target_ulong filter_list = args[3];
422 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
423 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
424 vlan_bd_t filter_list_bd;
431 hcall_dprintf("H_REGISTER_LOGICAL_LAN called twice without "
432 "H_FREE_LOGICAL_LAN\n");
436 if (check_bd(dev, VLAN_VALID_BD(buf_list, SPAPR_TCE_PAGE_SIZE),
437 SPAPR_TCE_PAGE_SIZE) < 0) {
438 hcall_dprintf("Bad buf_list 0x" TARGET_FMT_lx "\n", buf_list);
442 filter_list_bd = VLAN_VALID_BD(filter_list, SPAPR_TCE_PAGE_SIZE);
443 if (check_bd(dev, filter_list_bd, SPAPR_TCE_PAGE_SIZE) < 0) {
444 hcall_dprintf("Bad filter_list 0x" TARGET_FMT_lx "\n", filter_list);
448 if (!(rec_queue & VLAN_BD_VALID)
449 || (check_bd(dev, rec_queue, VLAN_RQ_ALIGNMENT) < 0)) {
450 hcall_dprintf("Bad receive queue\n");
454 dev->buf_list = buf_list;
455 sdev->signal_state = 0;
457 rec_queue &= ~VLAN_BD_TOGGLE;
459 /* Initialize the buffer list */
460 vio_stq(sdev, buf_list, rec_queue);
461 vio_stq(sdev, buf_list + 8, filter_list_bd);
462 spapr_vio_dma_set(sdev, buf_list + VLAN_RX_BDS_OFF, 0,
463 SPAPR_TCE_PAGE_SIZE - VLAN_RX_BDS_OFF);
464 dev->add_buf_ptr = VLAN_RX_BDS_OFF - 8;
465 dev->use_buf_ptr = VLAN_RX_BDS_OFF - 8;
469 /* Initialize the receive queue */
470 spapr_vio_dma_set(sdev, VLAN_BD_ADDR(rec_queue), 0, VLAN_BD_LEN(rec_queue));
473 qemu_flush_queued_packets(qemu_get_queue(dev->nic));
479 static target_ulong h_free_logical_lan(PowerPCCPU *cpu,
480 sPAPRMachineState *spapr,
481 target_ulong opcode, target_ulong *args)
483 target_ulong reg = args[0];
484 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
485 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
492 hcall_dprintf("H_FREE_LOGICAL_LAN called without "
493 "H_REGISTER_LOGICAL_LAN\n");
497 spapr_vlan_reset(sdev);
502 * Used for qsort, this function compares two RxBufPools by size.
504 static int rx_pool_size_compare(const void *p1, const void *p2)
506 const RxBufPool *pool1 = *(RxBufPool **)p1;
507 const RxBufPool *pool2 = *(RxBufPool **)p2;
509 if (pool1->bufsize < pool2->bufsize) {
512 return pool1->bufsize > pool2->bufsize;
516 * Search for a matching buffer pool with exact matching size,
517 * or return -1 if no matching pool has been found.
519 static int spapr_vlan_get_rx_pool_id(VIOsPAPRVLANDevice *dev, int size)
523 for (pool = 0; pool < RX_MAX_POOLS; pool++) {
524 if (dev->rx_pool[pool]->bufsize == size) {
533 * Enqueuing receive buffer by adding it to one of our receive buffer pools
535 static target_long spapr_vlan_add_rxbuf_to_pool(VIOsPAPRVLANDevice *dev,
538 int size = VLAN_BD_LEN(buf);
541 pool = spapr_vlan_get_rx_pool_id(dev, size);
544 * No matching pool found? Try to use a new one. If the guest used all
545 * pools before, but changed the size of one pool inbetween, we might
546 * need to recycle that pool here (if it's empty already). Thus scan
547 * all buffer pools now, starting with the last (likely empty) one.
549 for (pool = RX_MAX_POOLS - 1; pool >= 0 ; pool--) {
550 if (dev->rx_pool[pool]->count == 0) {
551 dev->rx_pool[pool]->bufsize = size;
553 * Sort pools by size so that spapr_vlan_receive()
554 * can later find the smallest buffer pool easily.
556 qsort(dev->rx_pool, RX_MAX_POOLS, sizeof(dev->rx_pool[0]),
557 rx_pool_size_compare);
558 pool = spapr_vlan_get_rx_pool_id(dev, size);
559 DPRINTF("created RX pool %d for size %lld\n", pool,
565 /* Still no usable pool? Give up */
566 if (pool < 0 || dev->rx_pool[pool]->count >= RX_POOL_MAX_BDS) {
570 DPRINTF("h_add_llan_buf(): Add buf using pool %i (size %lli, count=%i)\n",
571 pool, VLAN_BD_LEN(buf), dev->rx_pool[pool]->count);
573 dev->rx_pool[pool]->bds[dev->rx_pool[pool]->count++] = buf;
579 * This is the old way of enqueuing receive buffers: Add it to the rx queue
580 * page that has been supplied by the guest (which is quite limited in size).
582 static target_long spapr_vlan_add_rxbuf_to_page(VIOsPAPRVLANDevice *dev,
587 if (dev->rx_bufs >= VLAN_MAX_BUFS) {
592 dev->add_buf_ptr += 8;
593 if (dev->add_buf_ptr >= VLAN_RX_BDS_LEN + VLAN_RX_BDS_OFF) {
594 dev->add_buf_ptr = VLAN_RX_BDS_OFF;
597 bd = vio_ldq(&dev->sdev, dev->buf_list + dev->add_buf_ptr);
598 } while (bd & VLAN_BD_VALID);
600 vio_stq(&dev->sdev, dev->buf_list + dev->add_buf_ptr, buf);
602 DPRINTF("h_add_llan_buf(): Added buf ptr=%d rx_bufs=%d bd=0x%016llx\n",
603 dev->add_buf_ptr, dev->rx_bufs, (unsigned long long)buf);
608 static target_ulong h_add_logical_lan_buffer(PowerPCCPU *cpu,
609 sPAPRMachineState *spapr,
613 target_ulong reg = args[0];
614 target_ulong buf = args[1];
615 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
616 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
619 DPRINTF("H_ADD_LOGICAL_LAN_BUFFER(0x" TARGET_FMT_lx
620 ", 0x" TARGET_FMT_lx ")\n", reg, buf);
623 hcall_dprintf("Bad device\n");
627 if ((check_bd(dev, buf, 4) < 0)
628 || (VLAN_BD_LEN(buf) < 16)) {
629 hcall_dprintf("Bad buffer enqueued\n");
637 if (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) {
638 ret = spapr_vlan_add_rxbuf_to_pool(dev, buf);
640 ret = spapr_vlan_add_rxbuf_to_page(dev, buf);
649 * Give guest some more time to add additional RX buffers before we
650 * flush the receive queue, so that e.g. fragmented IP packets can
651 * be passed to the guest in one go later (instead of passing single
652 * fragments if there is only one receive buffer available).
654 timer_mod(dev->rxp_timer, qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + 500);
659 static target_ulong h_send_logical_lan(PowerPCCPU *cpu,
660 sPAPRMachineState *spapr,
661 target_ulong opcode, target_ulong *args)
663 target_ulong reg = args[0];
664 target_ulong *bufs = args + 1;
665 target_ulong continue_token = args[7];
666 VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
667 VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev);
673 DPRINTF("H_SEND_LOGICAL_LAN(0x" TARGET_FMT_lx ", <bufs>, 0x"
674 TARGET_FMT_lx ")\n", reg, continue_token);
680 DPRINTF("rxbufs = %d\n", dev->rx_bufs);
686 if (continue_token) {
687 return H_HARDWARE; /* FIXME actually handle this */
691 for (i = 0; i < 6; i++) {
692 DPRINTF(" buf desc: 0x" TARGET_FMT_lx "\n", bufs[i]);
693 if (!(bufs[i] & VLAN_BD_VALID)) {
696 total_len += VLAN_BD_LEN(bufs[i]);
700 DPRINTF("h_send_logical_lan() %d buffers, total length 0x%x\n",
703 if (total_len == 0) {
707 if (total_len > MAX_PACKET_SIZE) {
708 /* Don't let the guest force too large an allocation */
712 lbuf = alloca(total_len);
714 for (i = 0; i < nbufs; i++) {
715 ret = spapr_vio_dma_read(sdev, VLAN_BD_ADDR(bufs[i]),
716 p, VLAN_BD_LEN(bufs[i]));
721 p += VLAN_BD_LEN(bufs[i]);
724 qemu_send_packet(qemu_get_queue(dev->nic), lbuf, total_len);
729 static target_ulong h_multicast_ctrl(PowerPCCPU *cpu, sPAPRMachineState *spapr,
730 target_ulong opcode, target_ulong *args)
732 target_ulong reg = args[0];
733 VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
742 static Property spapr_vlan_properties[] = {
743 DEFINE_SPAPR_PROPERTIES(VIOsPAPRVLANDevice, sdev),
744 DEFINE_NIC_PROPERTIES(VIOsPAPRVLANDevice, nicconf),
745 DEFINE_PROP_BIT("use-rx-buffer-pools", VIOsPAPRVLANDevice,
746 compat_flags, SPAPRVLAN_FLAG_RX_BUF_POOLS_BIT, true),
747 DEFINE_PROP_END_OF_LIST(),
750 static bool spapr_vlan_rx_buffer_pools_needed(void *opaque)
752 VIOsPAPRVLANDevice *dev = opaque;
754 return (dev->compat_flags & SPAPRVLAN_FLAG_RX_BUF_POOLS) != 0;
757 static const VMStateDescription vmstate_rx_buffer_pool = {
758 .name = "spapr_llan/rx_buffer_pool",
760 .minimum_version_id = 1,
761 .needed = spapr_vlan_rx_buffer_pools_needed,
762 .fields = (VMStateField[]) {
763 VMSTATE_INT32(bufsize, RxBufPool),
764 VMSTATE_INT32(count, RxBufPool),
765 VMSTATE_UINT64_ARRAY(bds, RxBufPool, RX_POOL_MAX_BDS),
766 VMSTATE_END_OF_LIST()
770 static const VMStateDescription vmstate_rx_pools = {
771 .name = "spapr_llan/rx_pools",
773 .minimum_version_id = 1,
774 .needed = spapr_vlan_rx_buffer_pools_needed,
775 .fields = (VMStateField[]) {
776 VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(rx_pool, VIOsPAPRVLANDevice,
778 vmstate_rx_buffer_pool, RxBufPool),
779 VMSTATE_END_OF_LIST()
783 static const VMStateDescription vmstate_spapr_llan = {
784 .name = "spapr_llan",
786 .minimum_version_id = 1,
787 .fields = (VMStateField[]) {
788 VMSTATE_SPAPR_VIO(sdev, VIOsPAPRVLANDevice),
790 VMSTATE_BOOL(isopen, VIOsPAPRVLANDevice),
791 VMSTATE_UINT64(buf_list, VIOsPAPRVLANDevice),
792 VMSTATE_UINT32(add_buf_ptr, VIOsPAPRVLANDevice),
793 VMSTATE_UINT32(use_buf_ptr, VIOsPAPRVLANDevice),
794 VMSTATE_UINT32(rx_bufs, VIOsPAPRVLANDevice),
795 VMSTATE_UINT64(rxq_ptr, VIOsPAPRVLANDevice),
797 VMSTATE_END_OF_LIST()
799 .subsections = (const VMStateDescription * []) {
805 static void spapr_vlan_class_init(ObjectClass *klass, void *data)
807 DeviceClass *dc = DEVICE_CLASS(klass);
808 VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
810 k->realize = spapr_vlan_realize;
811 k->reset = spapr_vlan_reset;
812 k->devnode = spapr_vlan_devnode;
813 k->dt_name = "l-lan";
814 k->dt_type = "network";
815 k->dt_compatible = "IBM,l-lan";
816 k->signal_mask = 0x1;
817 set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
818 dc->props = spapr_vlan_properties;
819 k->rtce_window_size = 0x10000000;
820 dc->vmsd = &vmstate_spapr_llan;
823 static const TypeInfo spapr_vlan_info = {
824 .name = TYPE_VIO_SPAPR_VLAN_DEVICE,
825 .parent = TYPE_VIO_SPAPR_DEVICE,
826 .instance_size = sizeof(VIOsPAPRVLANDevice),
827 .class_init = spapr_vlan_class_init,
828 .instance_init = spapr_vlan_instance_init,
829 .instance_finalize = spapr_vlan_instance_finalize,
832 static void spapr_vlan_register_types(void)
834 spapr_register_hypercall(H_REGISTER_LOGICAL_LAN, h_register_logical_lan);
835 spapr_register_hypercall(H_FREE_LOGICAL_LAN, h_free_logical_lan);
836 spapr_register_hypercall(H_SEND_LOGICAL_LAN, h_send_logical_lan);
837 spapr_register_hypercall(H_ADD_LOGICAL_LAN_BUFFER,
838 h_add_logical_lan_buffer);
839 spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
840 type_register_static(&spapr_vlan_info);
843 type_init(spapr_vlan_register_types)