]> git.proxmox.com Git - qemu.git/blobdiff - hw/mcf_fec.c
xen: fix build problem introduced from per-queue peers
[qemu.git] / hw / mcf_fec.c
index 413c5694db4e1df603f1c5db0f15c2bede96a6af..8e60f09fbbf371ac1615681cb912556f37852d0b 100644 (file)
@@ -3,28 +3,32 @@
  *
  * Copyright (c) 2007 CodeSourcery.
  *
- * This code is licenced under the GPL
+ * This code is licensed under the GPL
  */
 #include "hw.h"
-#include "net.h"
+#include "net/net.h"
 #include "mcf.h"
 /* For crc32 */
 #include <zlib.h>
+#include "exec/address-spaces.h"
 
 //#define DEBUG_FEC 1
 
 #ifdef DEBUG_FEC
-#define DPRINTF(fmt, args...) \
-do { printf("mcf_fec: " fmt , ##args); } while (0)
+#define DPRINTF(fmt, ...) \
+do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0)
 #else
-#define DPRINTF(fmt, args...) do {} while(0)
+#define DPRINTF(fmt, ...) do {} while(0)
 #endif
 
 #define FEC_MAX_FRAME_SIZE 2032
 
 typedef struct {
+    MemoryRegion *sysmem;
+    MemoryRegion iomem;
     qemu_irq *irq;
-    VLANClientState *vc;
+    NICState *nic;
+    NICConf conf;
     uint32_t irq_state;
     uint32_t eir;
     uint32_t eimr;
@@ -41,7 +45,6 @@ typedef struct {
     uint32_t erdsr;
     uint32_t etdsr;
     uint32_t emrbr;
-    uint8_t macaddr[6];
 } mcf_fec_state;
 
 #define FEC_INT_HB   0x80000000
@@ -171,7 +174,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
         if (bd.flags & FEC_BD_L) {
             /* Last buffer in frame.  */
             DPRINTF("Sending packet\n");
-            qemu_send_packet(s->vc, frame, len);
+            qemu_send_packet(qemu_get_queue(s->nic), frame, len);
             ptr = frame;
             frame_size = 0;
             s->eir |= FEC_INT_TXF;
@@ -213,7 +216,8 @@ static void mcf_fec_reset(mcf_fec_state *s)
     s->rfsr = 0x500;
 }
 
-static uint32_t mcf_fec_read(void *opaque, target_phys_addr_t addr)
+static uint64_t mcf_fec_read(void *opaque, hwaddr addr,
+                             unsigned size)
 {
     mcf_fec_state *s = (mcf_fec_state *)opaque;
     switch (addr & 0x3ff) {
@@ -228,11 +232,11 @@ static uint32_t mcf_fec_read(void *opaque, target_phys_addr_t addr)
     case 0x084: return s->rcr;
     case 0x0c4: return s->tcr;
     case 0x0e4: /* PALR */
-        return (s->macaddr[0] << 24) | (s->macaddr[1] << 16)
-              | (s->macaddr[2] << 8) | s->macaddr[3];
+        return (s->conf.macaddr.a[0] << 24) | (s->conf.macaddr.a[1] << 16)
+              | (s->conf.macaddr.a[2] << 8) | s->conf.macaddr.a[3];
         break;
     case 0x0e8: /* PAUR */
-        return (s->macaddr[4] << 24) | (s->macaddr[5] << 16) | 0x8808;
+        return (s->conf.macaddr.a[4] << 24) | (s->conf.macaddr.a[5] << 16) | 0x8808;
     case 0x0ec: return 0x10000; /* OPD */
     case 0x118: return 0;
     case 0x11c: return 0;
@@ -245,13 +249,13 @@ static uint32_t mcf_fec_read(void *opaque, target_phys_addr_t addr)
     case 0x184: return s->etdsr;
     case 0x188: return s->emrbr;
     default:
-        cpu_abort(cpu_single_env, "mcf_fec_read: Bad address 0x%x\n",
-                  (int)addr);
+        hw_error("mcf_fec_read: Bad address 0x%x\n", (int)addr);
         return 0;
     }
 }
 
-static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value)
+static void mcf_fec_write(void *opaque, hwaddr addr,
+                          uint64_t value, unsigned size)
 {
     mcf_fec_state *s = (mcf_fec_state *)opaque;
     switch (addr & 0x3ff) {
@@ -303,14 +307,14 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value)
             s->eir |= FEC_INT_GRA;
         break;
     case 0x0e4: /* PALR */
-        s->macaddr[0] = value >> 24;
-        s->macaddr[1] = value >> 16;
-        s->macaddr[2] = value >> 8;
-        s->macaddr[3] = value;
+        s->conf.macaddr.a[0] = value >> 24;
+        s->conf.macaddr.a[1] = value >> 16;
+        s->conf.macaddr.a[2] = value >> 8;
+        s->conf.macaddr.a[3] = value;
         break;
     case 0x0e8: /* PAUR */
-        s->macaddr[4] = value >> 24;
-        s->macaddr[5] = value >> 16;
+        s->conf.macaddr.a[4] = value >> 24;
+        s->conf.macaddr.a[5] = value >> 16;
         break;
     case 0x0ec:
         /* OPD */
@@ -342,21 +346,20 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value)
         s->emrbr = value & 0x7f0;
         break;
     default:
-        cpu_abort(cpu_single_env, "mcf_fec_write Bad address 0x%x\n",
-                  (int)addr);
+        hw_error("mcf_fec_write Bad address 0x%x\n", (int)addr);
     }
     mcf_fec_update(s);
 }
 
-static int mcf_fec_can_receive(void *opaque)
+static int mcf_fec_can_receive(NetClientState *nc)
 {
-    mcf_fec_state *s = (mcf_fec_state *)opaque;
+    mcf_fec_state *s = qemu_get_nic_opaque(nc);
     return s->rx_enabled;
 }
 
-static void mcf_fec_receive(void *opaque, const uint8_t *buf, int size)
+static ssize_t mcf_fec_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 {
-    mcf_fec_state *s = (mcf_fec_state *)opaque;
+    mcf_fec_state *s = qemu_get_nic_opaque(nc);
     mcf_fec_bd bd;
     uint32_t flags = 0;
     uint32_t addr;
@@ -427,35 +430,51 @@ static void mcf_fec_receive(void *opaque, const uint8_t *buf, int size)
     s->rx_descriptor = addr;
     mcf_fec_enable_rx(s);
     mcf_fec_update(s);
+    return size;
 }
 
-static CPUReadMemoryFunc *mcf_fec_readfn[] = {
-   mcf_fec_read,
-   mcf_fec_read,
-   mcf_fec_read
+static const MemoryRegionOps mcf_fec_ops = {
+    .read = mcf_fec_read,
+    .write = mcf_fec_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static CPUWriteMemoryFunc *mcf_fec_writefn[] = {
-   mcf_fec_write,
-   mcf_fec_write,
-   mcf_fec_write
+static void mcf_fec_cleanup(NetClientState *nc)
+{
+    mcf_fec_state *s = qemu_get_nic_opaque(nc);
+
+    memory_region_del_subregion(s->sysmem, &s->iomem);
+    memory_region_destroy(&s->iomem);
+
+    g_free(s);
+}
+
+static NetClientInfo net_mcf_fec_info = {
+    .type = NET_CLIENT_OPTIONS_KIND_NIC,
+    .size = sizeof(NICState),
+    .can_receive = mcf_fec_can_receive,
+    .receive = mcf_fec_receive,
+    .cleanup = mcf_fec_cleanup,
 };
 
-void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
+void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd,
+                  hwaddr base, qemu_irq *irq)
 {
     mcf_fec_state *s;
-    int iomemtype;
 
     qemu_check_nic_model(nd, "mcf_fec");
 
-    s = (mcf_fec_state *)qemu_mallocz(sizeof(mcf_fec_state));
+    s = (mcf_fec_state *)g_malloc0(sizeof(mcf_fec_state));
+    s->sysmem = sysmem;
     s->irq = irq;
-    iomemtype = cpu_register_io_memory(0, mcf_fec_readfn,
-                                       mcf_fec_writefn, s);
-    cpu_register_physical_memory(base, 0x400, iomemtype);
-
-    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
-                                 mcf_fec_receive, mcf_fec_can_receive, s);
-    memcpy(s->macaddr, nd->macaddr, 6);
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+
+    memory_region_init_io(&s->iomem, &mcf_fec_ops, s, "fec", 0x400);
+    memory_region_add_subregion(sysmem, base, &s->iomem);
+
+    s->conf.macaddr = nd->macaddr;
+    s->conf.peers.ncs[0] = nd->netdev;
+
+    s->nic = qemu_new_nic(&net_mcf_fec_info, &s->conf, nd->model, nd->name, s);
+
+    qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
 }