Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump/net/lib/libshmif * include a magic number in the bu...
details: https://anonhg.NetBSD.org/src/rev/fd922d48e1ce
branches: trunk
changeset: 757063:fd922d48e1ce
user: pooka <pooka%NetBSD.org@localhost>
date: Thu Aug 12 18:17:23 2010 +0000
description:
* include a magic number in the bus format
* simplify offset calculations by making them start from beginning of data
diffstat:
sys/rump/net/lib/libshmif/dumpbus.c | 12 +++++++-----
sys/rump/net/lib/libshmif/if_shmem.c | 32 ++++++++++++++++----------------
sys/rump/net/lib/libshmif/shmifvar.h | 15 ++++++++++++---
3 files changed, 35 insertions(+), 24 deletions(-)
diffs (166 lines):
diff -r 72f81b8d6148 -r fd922d48e1ce sys/rump/net/lib/libshmif/dumpbus.c
--- a/sys/rump/net/lib/libshmif/dumpbus.c Thu Aug 12 17:33:55 2010 +0000
+++ b/sys/rump/net/lib/libshmif/dumpbus.c Thu Aug 12 18:17:23 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dumpbus.c,v 1.3 2010/08/12 17:33:55 pooka Exp $ */
+/* $NetBSD: dumpbus.c,v 1.4 2010/08/12 18:17:23 pooka Exp $ */
/*
* Little utility to convert shmif bus traffic to a pcap file
@@ -67,8 +67,11 @@
err(1, "mmap");
bmem = busmem;
- if (bmem->shm_version != 1)
- errx(1, "cannot handle bus version %d", bmem->shm_version);
+ if (bmem->shm_magic != SHMIF_MAGIC)
+ errx(1, "%s not a shmif bus", argv[0]);
+ if (bmem->shm_version != SHMIF_VERSION)
+ errx(1, "bus vesrsion %d, program %d",
+ bmem->shm_version, SHMIF_VERSION);
printf("bus version %d, lock: %d, generation: %d, lastoff: 0x%x\n",
bmem->shm_version, bmem->shm_lock, bmem->shm_gen, bmem->shm_last);
@@ -106,12 +109,11 @@
pktlen = *(uint32_t *)curbus;
curbus += sizeof(pktlen);
- /* quirk */
if (pktlen == 0)
continue;
printf("packet %d, offset 0x%x, length 0x%x\n",
- i++, curbus - (uint8_t *)(bmem + 1), pktlen);
+ i++, curbus - bmem->shm_data, pktlen);
if (!pcapfile || pktlen == 0) {
curbus += pktlen;
diff -r 72f81b8d6148 -r fd922d48e1ce sys/rump/net/lib/libshmif/if_shmem.c
--- a/sys/rump/net/lib/libshmif/if_shmem.c Thu Aug 12 17:33:55 2010 +0000
+++ b/sys/rump/net/lib/libshmif/if_shmem.c Thu Aug 12 18:17:23 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_shmem.c,v 1.16 2010/08/12 17:33:55 pooka Exp $ */
+/* $NetBSD: if_shmem.c,v 1.17 2010/08/12 18:17:23 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.16 2010/08/12 17:33:55 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.17 2010/08/12 18:17:23 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -81,8 +81,7 @@
#define BUSMEM_SIZE (1024*1024) /* need write throttling? */
-/* just in case ... */
-static const uint32_t busversion = 1;
+static const uint32_t busversion = SHMIF_VERSION;
static void shmif_rcv(void *);
@@ -123,18 +122,18 @@
KASSERT(len < (BUSMEM_SIZE - IFMEM_DATA) && off <= BUSMEM_SIZE);
chunk = MIN(len, BUSMEM_SIZE - off);
- memcpy(dest, (uint8_t *)sc->sc_busmem + off, chunk);
+ memcpy(dest, sc->sc_busmem->shm_data + off, chunk);
len -= chunk;
if (len == 0)
return off + chunk;
/* else, wraps around */
- off = IFMEM_DATA;
+ off = 0;
sc->sc_prevgen = sc->sc_busmem->shm_gen;
/* finish reading */
- memcpy((uint8_t *)dest + chunk, (uint8_t *)sc->sc_busmem + off, len);
+ memcpy((uint8_t *)dest + chunk, sc->sc_busmem->shm_data + off, len);
return off + len;
}
@@ -143,26 +142,25 @@
{
size_t chunk;
- KASSERT(len < (BUSMEM_SIZE - IFMEM_DATA) && off <= BUSMEM_SIZE
- && off >= IFMEM_DATA);
+ KASSERT(len < (BUSMEM_SIZE - IFMEM_DATA) && off <= BUSMEM_SIZE);
chunk = MIN(len, BUSMEM_SIZE - off);
- memcpy((uint8_t *)sc->sc_busmem + off, data, chunk);
+ memcpy(sc->sc_busmem->shm_data + off, data, chunk);
len -= chunk;
if (len == 0)
return off + chunk;
- DPRINTF(("buswrite wrap: wrote %d bytes to %d, left %d to %d",
- chunk, off, len, IFMEM_DATA));
+ DPRINTF(("buswrite wrap: wrote %d bytes to %d, left %d to 0",
+ chunk, off, len));
/* else, wraps around */
- off = IFMEM_DATA;
+ off = 0;
sc->sc_prevgen = sc->sc_busmem->shm_gen;
sc->sc_busmem->shm_gen++;
/* finish writing */
- memcpy((uint8_t *)sc->sc_busmem + off, (uint8_t *)data + chunk, len);
+ memcpy(sc->sc_busmem->shm_data + off, (uint8_t *)data + chunk, len);
return off + len;
}
@@ -216,9 +214,11 @@
if (error)
goto fail;
+ if (sc->sc_busmem->shm_magic && sc->sc_busmem->shm_magic != SHMIF_MAGIC)
+ panic("bus is not magical");
+ sc->sc_busmem->shm_magic = SHMIF_MAGIC;
+
lockbus(sc);
- if (sc->sc_busmem->shm_last == 0)
- sc->sc_busmem->shm_last = IFMEM_DATA;
sc->sc_nextpacket = sc->sc_busmem->shm_last;
sc->sc_prevgen = sc->sc_busmem->shm_gen;
unlockbus(sc);
diff -r 72f81b8d6148 -r fd922d48e1ce sys/rump/net/lib/libshmif/shmifvar.h
--- a/sys/rump/net/lib/libshmif/shmifvar.h Thu Aug 12 17:33:55 2010 +0000
+++ b/sys/rump/net/lib/libshmif/shmifvar.h Thu Aug 12 18:17:23 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: shmifvar.h,v 1.1 2010/08/12 17:33:55 pooka Exp $ */
+/* $NetBSD: shmifvar.h,v 1.2 2010/08/12 18:17:23 pooka Exp $ */
/*-
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -30,11 +30,20 @@
#ifndef _RUMP_NET_SHMIFVAR_H_
#define _RUMP_NET_SHMIFVAR_H_
+#define SHMIF_MAGIC 0xca11d054
+#define SHMIF_VERSION 1
+
struct shmif_mem {
- uint32_t shm_lock;
+ uint32_t shm_magic;
+ uint32_t shm_version;
+
uint32_t shm_gen;
+ uint32_t shm_first;
uint32_t shm_last;
- uint32_t shm_version;
+
+ uint32_t shm_lock;
+ uint32_t shm_spare[2];
+
uint8_t shm_data[0];
};
Home |
Main Index |
Thread Index |
Old Index