aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvik Sil <aviksil@linux.vnet.ibm.com>2013-09-23 14:07:36 +0530
committerNikunj A Dadhania <nikunj@linux.vnet.ibm.com>2013-10-04 12:01:06 +0530
commite5be30744ec9d6d8da26f112792e4b1d7187e2f5 (patch)
treeb75059c794722ca67df17d6a6f17d47bcf1699ba
parentc9e1f76d10bb065e4ddd65b5150083428f90609b (diff)
downloadSLOF-e5be30744ec9d6d8da26f112792e4b1d7187e2f5.zip
SLOF-e5be30744ec9d6d8da26f112792e4b1d7187e2f5.tar.gz
SLOF-e5be30744ec9d6d8da26f112792e4b1d7187e2f5.tar.bz2
Remove virtio-net network driver as module
The driver has been moved to libvirtio Signed-off-by: Avik Sil <aviksil@linux.vnet.ibm.com> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
-rw-r--r--board-qemu/Makefile2
-rw-r--r--board-qemu/romfs/boot_rom.ffs1
-rw-r--r--board-qemu/virtio-net/Makefile51
-rw-r--r--board-qemu/virtio-net/module_entry.c50
-rw-r--r--board-qemu/virtio-net/virtio-net.c272
-rw-r--r--board-qemu/virtio-net/virtio-net.h57
-rw-r--r--board-qemu/virtio-net/virtio-net.lds37
-rw-r--r--board-qemu/virtio-net/vn-pci.c123
8 files changed, 1 insertions, 592 deletions
diff --git a/board-qemu/Makefile b/board-qemu/Makefile
index be47c10..b9109fe 100644
--- a/board-qemu/Makefile
+++ b/board-qemu/Makefile
@@ -12,7 +12,7 @@
BOARD_TARGETS = tools_build romfs_build clients_build netdrivers stage1 subdirs
-SUBDIRS = slof virtio-net
+SUBDIRS = slof
COMMON_LIBS = libc libbootmsg libbases libnvram libelf libhvcall libvirtio libusb \
libveth libe1k
diff --git a/board-qemu/romfs/boot_rom.ffs b/board-qemu/romfs/boot_rom.ffs
index c34079f..7ef46f4 100644
--- a/board-qemu/romfs/boot_rom.ffs
+++ b/board-qemu/romfs/boot_rom.ffs
@@ -19,4 +19,3 @@ ofw_main board-qemu/slof/paflof 0 0
bootinfo board-qemu/llfw/Cboot.bin 0 0
snk clients/net-snk.client 0 0
net_e1000 drivers/e1k/net_e1k.elf 0 0
-net_virtio board-qemu/virtio-net/net_virtio.elf 0 0
diff --git a/board-qemu/virtio-net/Makefile b/board-qemu/virtio-net/Makefile
deleted file mode 100644
index 009e10f..0000000
--- a/board-qemu/virtio-net/Makefile
+++ /dev/null
@@ -1,51 +0,0 @@
-# *****************************************************************************
-# * Copyright (c) 2011 IBM Corporation
-# * All rights reserved.
-# * This program and the accompanying materials
-# * are made available under the terms of the BSD License
-# * which accompanies this distribution, and is available at
-# * http://www.opensource.org/licenses/bsd-license.php
-# *
-# * Contributors:
-# * IBM Corporation - initial implementation
-# ****************************************************************************/
-
-ifndef TOP
- TOP = $(shell while ! test -e make.rules; do cd .. ; done; pwd)
- export TOP
-endif
-include $(TOP)/make.rules
-
-CPPFLAGS = -I./ -I$(TOP)/clients/net-snk/include/ -I$(TOP)/lib/libc/include/ \
- -I$(TOP)/lib/libhvcall -I$(TOP)/lib/libvirtio -I$(INCLCMNDIR) \
- -I$(INCLCMNDIR)/$(CPUARCH)
-
-LIBS = $(TOP)/lib/libc.a $(TOP)/lib/libhvcall.a $(TOP)/lib/libvirtio.a
-
-SRCS = module_entry.c virtio-net.c vn-pci.c
-
-OBJS = $(SRCS:%.c=%.o)
-
-all: net_virtio.elf
-
-net_virtio.elf: $(OBJS) $(LIBS)
- $(LD) $(LDFLAGS) $^ -o $@ -T virtio-net.lds -N -q
- $(STRIP) --strip-unneeded $@
-
-clean:
- $(RM) -f *.o *.a *.i *.elf
-
-distclean : clean
- rm -f Makefile.dep
-
-
-# Rules for creating the dependency file:
-depend:
- $(RM) Makefile.dep
- $(MAKE) Makefile.dep
-
-Makefile.dep:
- $(CC) -M $(CFLAGS) $(CPPFLAGS) $(SRCS) > Makefile.dep
-
-# Include dependency file if available:
--include Makefile.dep
diff --git a/board-qemu/virtio-net/module_entry.c b/board-qemu/virtio-net/module_entry.c
deleted file mode 100644
index 2d2ca94..0000000
--- a/board-qemu/virtio-net/module_entry.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- * IBM Corporation - initial implementation
- *****************************************************************************/
-
-#include <string.h>
-#include <netdriver_int.h>
-#include "virtio-net.h"
-
-extern char __module_start[];
-extern char __module_end[];
-extern char __bss_start[];
-extern char __bss_end[];
-
-snk_kernel_t *snk_kernel_interface;
-snk_module_t *snk_module_interface;
-
-
-snk_module_t* module_init(snk_kernel_t *snk_kernel_int, pci_config_t *conf)
-{
- long module_size;
-
- module_size = __module_end - __module_start;
- if (module_size >= 0x800000) {
- snk_kernel_int->print("Module size (%llu bytes) is too big!\n",
- module_size);
- return 0;
- }
-
- memset(__bss_start, 0, __bss_end - __bss_start);
-
- snk_kernel_interface = snk_kernel_int;
- snk_module_interface = &virtionet_interface;
- snk_module_interface->link_addr = module_init;
-
- if (snk_kernel_int->version != snk_module_interface->version)
- return 0;
-
- if (vn_module_init_pci(snk_kernel_int, conf))
- return 0;
-
- return &virtionet_interface;
-}
diff --git a/board-qemu/virtio-net/virtio-net.c b/board-qemu/virtio-net/virtio-net.c
deleted file mode 100644
index fe9990f..0000000
--- a/board-qemu/virtio-net/virtio-net.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2011 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- * IBM Corporation - initial implementation
- *****************************************************************************/
-
-/*
- * This is the implementation for the Virtio network device driver. Details
- * about the virtio-net interface can be found in Rusty Russel's "Virtio PCI
- * Card Specification v0.8.10", appendix C, which can be found here:
- *
- * http://ozlabs.org/~rusty/virtio-spec/virtio-spec.pdf
- */
-
-#include <stdint.h>
-#include <cpu.h>
-#include "netdriver_int.h"
-#include <libhvcall.h>
-#include <virtio.h>
-#include <string.h>
-#include "virtio-net.h"
-
-struct virtio_device virtiodev;
-struct vqs vq[2]; /* Information about virtqueues */
-
-
-/* See Virtio Spec, appendix C, "Device Operation" */
-struct virtio_net_hdr {
- uint8_t flags;
- uint8_t gso_type;
- uint16_t hdr_len;
- uint16_t gso_size;
- uint16_t csum_start;
- uint16_t csum_offset;
- // uint16_t num_buffers; /* Only if VIRTIO_NET_F_MRG_RXBUF */
-};
-
-static uint16_t last_rx_idx; /* Last index in RX "used" ring */
-
-
-/**
- * Initialize the virtio-net device.
- * See the Virtio Spec, chapter 2.2.1 and Appendix C "Device Initialization"
- * for details.
- */
-static int virtionet_init(void)
-{
- int i;
-
- dprintk("virtionet_init(%02x:%02x:%02x:%02x:%02x:%02x)\n",
- snk_module_interface->mac_addr[0], snk_module_interface->mac_addr[1],
- snk_module_interface->mac_addr[2], snk_module_interface->mac_addr[3],
- snk_module_interface->mac_addr[4], snk_module_interface->mac_addr[5]);
-
- if (snk_module_interface->running != 0)
- return 0;
-
- /* Tell HV that we know how to drive the device. */
- virtio_set_status(&virtiodev, VIRTIO_STAT_ACKNOWLEDGE|VIRTIO_STAT_DRIVER);
-
- /* Device specific setup - we do not support special features right now */
- virtio_set_guest_features(&virtiodev, 0);
-
- /* Allocate memory for one transmit an multiple receive buffers */
- vq[VQ_RX].buf_mem = malloc((BUFFER_ENTRY_SIZE+sizeof(struct virtio_net_hdr))
- * RX_QUEUE_SIZE);
- if (!vq[VQ_RX].buf_mem) {
- printk("virtionet: Failed to allocate buffers!\n");
- virtio_set_status(&virtiodev, VIRTIO_STAT_FAILED);
- return -1;
- }
-
- /* Prepare receive buffer queue */
- for (i = 0; i < RX_QUEUE_SIZE; i++) {
- struct vring_desc *desc;
- /* Descriptor for net_hdr: */
- desc = &vq[VQ_RX].desc[i*2];
- desc->addr = (uint64_t)vq[VQ_RX].buf_mem
- + i * (BUFFER_ENTRY_SIZE+sizeof(struct virtio_net_hdr));
- // printk("RX buf %i addr = 0x%llx\n", i, desc->addr);
- desc->len = sizeof(struct virtio_net_hdr);
- desc->flags = VRING_DESC_F_NEXT | VRING_DESC_F_WRITE;
- desc->next = i*2+1;
-
- /* Descriptor for data: */
- desc = &vq[VQ_RX].desc[i*2+1];
- desc->addr = vq[VQ_RX].desc[i*2].addr + sizeof(struct virtio_net_hdr);
- desc->len = BUFFER_ENTRY_SIZE;
- desc->flags = VRING_DESC_F_WRITE;
- desc->next = 0;
-
- vq[VQ_RX].avail->ring[i] = i*2;
- }
- mb();
- vq[VQ_RX].avail->flags = VRING_AVAIL_F_NO_INTERRUPT;
- vq[VQ_RX].avail->idx = RX_QUEUE_SIZE;
-
- last_rx_idx = vq[VQ_RX].used->idx;
-
- vq[VQ_TX].avail->flags = VRING_AVAIL_F_NO_INTERRUPT;
- vq[VQ_TX].avail->idx = 0;
-
- /* Tell HV that setup succeeded */
- virtio_set_status(&virtiodev, VIRTIO_STAT_ACKNOWLEDGE
- |VIRTIO_STAT_DRIVER
- |VIRTIO_STAT_DRIVER_OK);
-
- /* Tell HV that RX queues are ready */
- virtio_queue_notify(&virtiodev, VQ_RX);
-
- snk_module_interface->running = 1;
-
- return 0;
-}
-
-
-/**
- * Shutdown driver.
- * We've got to make sure that the hosts stops all transfers since the buffers
- * in our main memory will become invalid after this module has been terminated.
- */
-static int virtionet_term(void)
-{
- dprintk("virtionet_term()\n");
-
- if (snk_module_interface->running == 0)
- return 0;
-
- /* Quiesce device */
- virtio_set_status(&virtiodev, VIRTIO_STAT_FAILED);
-
- /* Reset device */
- virtio_reset_device(&virtiodev);
-
- snk_module_interface->running = 0;
-
- return 0;
-}
-
-
-/**
- * Transmit a packet
- */
-static int virtionet_xmit(char *buf, int len)
-{
- struct vring_desc *desc;
- int id;
- static struct virtio_net_hdr nethdr = {
- 0, 0, sizeof(struct virtio_net_hdr),
- 0, 0, 0
- };
-
- if (len > BUFFER_ENTRY_SIZE) {
- printk("virtionet: Packet too big!\n");
- return 0;
- }
-
- dprintk("\nvirtionet_xmit(packet at %p, %d bytes)\n", buf, len);
-
- /* Determine descriptor index */
- id = (vq[VQ_TX].avail->idx * 2) % vq[VQ_TX].size;
-
- /* Set up virtqueue descriptor for header */
- desc = &vq[VQ_TX].desc[id];
- desc->addr = (uint64_t)&nethdr;
- desc->len = sizeof(struct virtio_net_hdr);
- desc->flags = VRING_DESC_F_NEXT;
- desc->next = id + 1;
-
- /* Set up virtqueue descriptor for data */
- desc = &vq[VQ_TX].desc[id+1];
- desc->addr = (uint64_t)buf;
- desc->len = len;
- desc->flags = 0;
- desc->next = 0;
-
- vq[VQ_TX].avail->ring[vq[VQ_TX].avail->idx % vq[VQ_TX].size] = id;
- mb();
- vq[VQ_TX].avail->idx += 1;
-
- /* Tell HV that TX queue is ready */
- virtio_queue_notify(&virtiodev, VQ_TX);
-
- return len;
-}
-
-
-/**
- * Receive a packet
- */
-static int virtionet_receive(char *buf, int maxlen)
-{
- int len = 0;
- int id;
-
- if (last_rx_idx == vq[VQ_RX].used->idx) {
- /* Nothing received yet */
- return 0;
- }
-
- id = (vq[VQ_RX].used->ring[last_rx_idx % vq[VQ_RX].size].id + 1)
- % vq[VQ_RX].size;
- len = vq[VQ_RX].used->ring[last_rx_idx % vq[VQ_RX].size].len
- - sizeof(struct virtio_net_hdr);
-
- dprintk("virtionet_receive() last_rx_idx=%i, vq[VQ_RX].used->idx=%i,"
- " id=%i len=%i\n", last_rx_idx, vq[VQ_RX].used->idx, id, len);
-
- if (len > maxlen) {
- printk("virtio-net: Receive buffer not big enough!\n");
- len = maxlen;
- }
-
-#if 0
- /* Dump packet */
- printk("\n");
- int i;
- for (i=0; i<64; i++) {
- printk(" %02x", *(uint8_t*)(vq[VQ_RX].desc[id].addr+i));
- if ((i%16)==15)
- printk("\n");
- }
- printk("\n");
-#endif
-
- /* Copy data to destination buffer */
- memcpy(buf, (void*)vq[VQ_RX].desc[id].addr, len);
-
- /* Move indices to next entries */
- last_rx_idx = last_rx_idx + 1;
-
- vq[VQ_RX].avail->ring[vq[VQ_RX].avail->idx % vq[VQ_RX].size] = id - 1;
- mb();
- vq[VQ_RX].avail->idx += 1;
-
- /* Tell HV that RX queue entry is ready */
- virtio_queue_notify(&virtiodev, VQ_RX);
-
- return len;
-}
-
-
-/**
- * Network IO control function - not implemented.
- */
-static int virtionet_ioctl(int request, void* data)
-{
- dprintk("virtionet_ioctl()\n");
-
- return -1;
-}
-
-
-/**
- * Module definition
- */
-snk_module_t virtionet_interface = {
- .version = 1,
- .type = MOD_TYPE_NETWORK,
- .running = 0,
- .init = virtionet_init,
- .term = virtionet_term,
- .write = virtionet_xmit,
- .read = virtionet_receive,
- .ioctl = virtionet_ioctl
-};
diff --git a/board-qemu/virtio-net/virtio-net.h b/board-qemu/virtio-net/virtio-net.h
deleted file mode 100644
index 9acb427..0000000
--- a/board-qemu/virtio-net/virtio-net.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2011 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- * IBM Corporation - initial implementation
- *****************************************************************************/
-
-#ifndef VIRTIO_NET_H
-#define VIRTIO_NET_H
-
-#define RX_QUEUE_SIZE 16
-#define BUFFER_ENTRY_SIZE 1514
-
-enum {
- VQ_RX = 0, /* Receive Queue */
- VQ_TX = 1, /* Transmit Queue */
-};
-
-struct vqs {
- uint64_t id; /* Queue ID */
- uint32_t size;
- void *buf_mem;
- struct vring_desc *desc;
- struct vring_avail *avail;
- struct vring_used *used;
-};
-
-extern struct vqs vq[2];
-extern struct virtio_device virtiodev;
-
-/* Device is identified by RX queue ID: */
-#define DEVICE_ID vq[0].id
-
-extern snk_kernel_t *snk_kernel_interface;
-extern snk_module_t *snk_module_interface;
-extern snk_module_t virtionet_interface;
-
-#define printk(fmt...) do { snk_kernel_interface->print(fmt); } while(0)
-#define malloc(args...) snk_kernel_interface->k_malloc(args)
-#define malloc_aligned(args...) snk_kernel_interface->k_malloc_aligned(args)
-#define free(args...) do { snk_kernel_interface->k_free(args); } while(0)
-
-#undef DEBUG
-#ifdef DEBUG
-# define dprintk(fmt...) printk(fmt)
-#else
-# define dprintk(fmt...)
-#endif
-
-int vn_module_init_pci(snk_kernel_t *snk_kernel_int, pci_config_t *conf);
-
-#endif
diff --git a/board-qemu/virtio-net/virtio-net.lds b/board-qemu/virtio-net/virtio-net.lds
deleted file mode 100644
index 074a5a4..0000000
--- a/board-qemu/virtio-net/virtio-net.lds
+++ /dev/null
@@ -1,37 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2011 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- * IBM Corporation - initial implementation
- *****************************************************************************/
-
-OUTPUT_FORMAT("elf64-powerpc", "elf64-powerpc", "elf64-powerpc")
-OUTPUT_ARCH(powerpc:common64)
-ENTRY(module_init)
-
-SECTIONS {
- .code 0xF800000 : {
- __module_start = .;
- module_entry.o(.opd)
- *(.text .stub .text.* .gnu.linkonce.t.*)
- *(.sfpr .glink)
- *(.rodata .rodata.* .gnu.linkonce.r.*)
- *(.data .data.* .gnu.linkonce.d.*)
- *(.opd)
- }
- .got : {
- _got = .;
- *(.got .toc)
- }
- .bss : {
- __bss_start = .;
- *(*COM* .bss .gnu.linkonce.b.*)
- __bss_end = .;
- }
- __module_end = .;
-}
diff --git a/board-qemu/virtio-net/vn-pci.c b/board-qemu/virtio-net/vn-pci.c
deleted file mode 100644
index bd20545..0000000
--- a/board-qemu/virtio-net/vn-pci.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2011 IBM Corporation
- * All rights reserved.
- * This program and the accompanying materials
- * are made available under the terms of the BSD License
- * which accompanies this distribution, and is available at
- * http://www.opensource.org/licenses/bsd-license.php
- *
- * Contributors:
- * IBM Corporation - initial implementation
- *****************************************************************************/
-
-#include <stdarg.h>
-#include <string.h>
-#include <cache.h>
-#include <byteorder.h>
-#include <netdriver_int.h>
-#include <libhvcall.h>
-#include <virtio.h>
-#include "virtio-net.h"
-
-
-#define VIRTIOHDR_DEVICE_FEATURES 0
-#define VIRTIOHDR_GUEST_FEATURES 4
-#define VIRTIOHDR_QUEUE_ADDRESS 8
-#define VIRTIOHDR_QUEUE_SIZE 12
-#define VIRTIOHDR_QUEUE_SELECT 14
-#define VIRTIOHDR_QUEUE_NOTIFY 16
-#define VIRTIOHDR_DEVICE_STATUS 18
-#define VIRTIOHDR_ISR_STATUS 19
-#define VIRTIOHDR_MAC_ADDRESS 20
-
-
-/**
- * Module init for virtio via PCI.
- * Checks whether we're responsible for the given device and set up
- * the virtqueue configuration.
- */
-int
-vn_module_init_pci(snk_kernel_t *snk_kernel_int, pci_config_t *conf)
-{
- uint64_t bar;
- int i;
-
- dprintk("virtionet: doing virtionet_module_init_pci!\n");
-
- virtiodev.type = VIRTIO_TYPE_PCI;
-
- /* Check whether the driver can handle this device by verifying vendor,
- * device id and class code. */
- if (conf->vendor_id != 0x1af4) {
- dprintk("virtionet: unsupported vendor id\n");
- return -1;
- }
- if (conf->device_id < 0x1000 || conf->device_id > 0x103f) {
- dprintk("virtionet: unsupported device id\n");
- return -1;
- }
- if (conf->class_code != 0x20000) {
- dprintk("virtionet: unsupported class code\n");
- return -1;
- }
-
- bar = snk_kernel_interface->pci_config_read(conf->puid, 4, conf->bus,
- conf->devfn, 0x10);
-
- if (!(bar & 1)) {
- printk("First BAR is not an I/O BAR!\n");
- return -1;
- }
- bar &= ~3ULL;
-
- dprintk("untranslated bar = %llx\n", bar);
-
- snk_kernel_interface->translate_addr((void *)&bar);
-
- dprintk("translated bar = %llx\n", bar);
- virtiodev.base = (void*)bar;
-
- /* Reset device */
- virtio_reset_device(&virtiodev);
-
- /* The queue information can be retrieved via the virtio header that
- * can be found in the I/O BAR. First queue is the receive queue,
- * second the transmit queue, and the forth is the control queue for
- * networking options.
- * We are only interested in the receive and transmit queue here. */
-
- for (i=VQ_RX; i<=VQ_TX; i++) {
- /* Select ring (0=RX, 1=TX): */
- vq[i].id = i-VQ_RX;
- ci_write_16(virtiodev.base+VIRTIOHDR_QUEUE_SELECT,
- cpu_to_le16(vq[i].id));
-
- vq[i].size = le16_to_cpu(ci_read_16(virtiodev.base+VIRTIOHDR_QUEUE_SIZE));
- vq[i].desc = malloc_aligned(virtio_vring_size(vq[i].size), 4096);
- if (!vq[i].desc) {
- printk("malloc failed!\n");
- return -1;
- }
- memset(vq[i].desc, 0, virtio_vring_size(vq[i].size));
- ci_write_32(virtiodev.base+VIRTIOHDR_QUEUE_ADDRESS,
- cpu_to_le32((long)vq[i].desc / 4096));
- vq[i].avail = (void*)vq[i].desc
- + vq[i].size * sizeof(struct vring_desc);
- vq[i].used = (void*)VQ_ALIGN((long)vq[i].avail
- + vq[i].size * sizeof(struct vring_avail));
-
- dprintk("%i: vq.id = %lx\nvq.size =%lx\n vq.avail =%lx\nvq.used=%lx\n",
- i, vq[i].id, vq[i].size, vq[i].avail, vq[i].used);
- }
-
- /* Copy MAC address */
- for (i = 0; i < 6; i++) {
- virtionet_interface.mac_addr[i]
- = ci_read_8(virtiodev.base+VIRTIOHDR_MAC_ADDRESS+i);
- }
-
- /* Acknowledge device. */
- virtio_set_status(&virtiodev, VIRTIO_STAT_ACKNOWLEDGE);
-
- return 0;
-}