mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 19:49:43 +00:00
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1 iQEcBAABAgAGBQJVUMoGAAoJEJykq7OBq3PI5+0H/2frhUc2rcTnsASwiVyxhpX0 nba3HkV3xnu4O8p0ASTvDjhMvZOqHqkPhQ2AJA4ma7OgzHNs79Q8C2253DBIPWFa OhrXdPdSbjnOMnKW0M+y929MIAmHUR8eZQ14EqdU4J23Xh2PrJSmLNae821z8eMN PkqV1LkVW9YVgkTykFq1lcjo1fKKaeMMHJlQKDdRVIrkt8RrWcdQWM186i1OTpJ6 Cs8sDM5TPk/dYZHJixMgNlJ+skEYrqDxbd0IkadGgthcPyUjdPANk7tMksQxNkLr 1IuXl4RYt6xinG21K0DIo+qBGd2mF/guGjnoxaOl85yf9rvTLRYqY+eD88k97RA= =AQJL -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/stefanha/tags/net-pull-request' into staging # gpg: Signature made Mon May 11 16:25:58 2015 BST using RSA key ID 81AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" * remotes/stefanha/tags/net-pull-request: rocker: timestamp on the debug logs helps correlate with events in the VM MAINTAINERS: add rocker rocker: add tests rocker: add new rocker switch device pci: add network device class 'other' for network switches pci: add rocker device ID rocker: add register programming guide virtio-net: use qemu_mac_strdup_printf net: add MAC address string printer Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
19fbe5084c
@ -760,6 +760,12 @@ S: Maintained
|
||||
F: hw/net/vmxnet*
|
||||
F: hw/scsi/vmw_pvscsi*
|
||||
|
||||
Rocker
|
||||
M: Scott Feldman <sfeldma@gmail.com>
|
||||
M: Jiri Pirko <jiri@resnulli.us>
|
||||
S: Maintained
|
||||
F: hw/net/rocker/
|
||||
|
||||
Subsystems
|
||||
----------
|
||||
Audio
|
||||
|
@ -36,3 +36,4 @@ CONFIG_EDU=y
|
||||
CONFIG_VGA=y
|
||||
CONFIG_VGA_PCI=y
|
||||
CONFIG_IVSHMEM=$(CONFIG_KVM)
|
||||
CONFIG_ROCKER=y
|
||||
|
@ -45,6 +45,7 @@ PCI devices (other than virtio):
|
||||
1b36:0003 PCI Dual-port 16550A adapter (docs/specs/pci-serial.txt)
|
||||
1b36:0004 PCI Quad-port 16550A adapter (docs/specs/pci-serial.txt)
|
||||
1b36:0005 PCI test device (docs/specs/pci-testdev.txt)
|
||||
1b36:0006 PCI Rocker Ethernet switch device
|
||||
1b36:0007 PCI SD Card Host Controller Interface (SDHCI)
|
||||
|
||||
All these devices are documented in docs/specs.
|
||||
|
1009
docs/specs/rocker.txt
Normal file
1009
docs/specs/rocker.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -35,3 +35,7 @@ obj-y += vhost_net.o
|
||||
|
||||
obj-$(CONFIG_ETSEC) += fsl_etsec/etsec.o fsl_etsec/registers.o \
|
||||
fsl_etsec/rings.o fsl_etsec/miim.o
|
||||
|
||||
common-obj-$(CONFIG_ROCKER) += rocker/rocker.o rocker/rocker_fp.o \
|
||||
rocker/rocker_desc.o rocker/rocker_world.o \
|
||||
rocker/rocker_of_dpa.o
|
||||
|
1480
hw/net/rocker/rocker.c
Normal file
1480
hw/net/rocker/rocker.c
Normal file
File diff suppressed because it is too large
Load Diff
84
hw/net/rocker/rocker.h
Normal file
84
hw/net/rocker/rocker.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
* Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
|
||||
* Copyright (c) 2014 Neil Horman <nhorman@tuxdriver.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _ROCKER_H_
|
||||
#define _ROCKER_H_
|
||||
|
||||
#include "qemu/sockets.h"
|
||||
|
||||
#if defined(DEBUG_ROCKER)
|
||||
# define DPRINTF(fmt, ...) \
|
||||
do { \
|
||||
struct timeval tv; \
|
||||
char timestr[64]; \
|
||||
time_t now; \
|
||||
gettimeofday(&tv, NULL); \
|
||||
now = tv.tv_sec; \
|
||||
strftime(timestr, sizeof(timestr), "%T", localtime(&now)); \
|
||||
fprintf(stderr, "%s.%06ld ", timestr, tv.tv_usec); \
|
||||
fprintf(stderr, "ROCKER: " fmt, ## __VA_ARGS__); \
|
||||
} while (0)
|
||||
#else
|
||||
static inline GCC_FMT_ATTR(1, 2) int DPRINTF(const char *fmt, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define __le16 uint16_t
|
||||
#define __le32 uint32_t
|
||||
#define __le64 uint64_t
|
||||
|
||||
#define __be16 uint16_t
|
||||
#define __be32 uint32_t
|
||||
#define __be64 uint64_t
|
||||
|
||||
static inline bool ipv4_addr_is_multicast(__be32 addr)
|
||||
{
|
||||
return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
|
||||
}
|
||||
|
||||
typedef struct ipv6_addr {
|
||||
union {
|
||||
uint8_t addr8[16];
|
||||
__be16 addr16[8];
|
||||
__be32 addr32[4];
|
||||
};
|
||||
} Ipv6Addr;
|
||||
|
||||
static inline bool ipv6_addr_is_multicast(const Ipv6Addr *addr)
|
||||
{
|
||||
return (addr->addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
|
||||
}
|
||||
|
||||
typedef struct rocker Rocker;
|
||||
typedef struct world World;
|
||||
typedef struct desc_info DescInfo;
|
||||
typedef struct desc_ring DescRing;
|
||||
|
||||
Rocker *rocker_find(const char *name);
|
||||
uint32_t rocker_fp_ports(Rocker *r);
|
||||
int rocker_event_link_changed(Rocker *r, uint32_t pport, bool link_up);
|
||||
int rocker_event_mac_vlan_seen(Rocker *r, uint32_t pport, uint8_t *addr,
|
||||
uint16_t vlan_id);
|
||||
int rx_produce(World *world, uint32_t pport,
|
||||
const struct iovec *iov, int iovcnt);
|
||||
int rocker_port_eg(Rocker *r, uint32_t pport,
|
||||
const struct iovec *iov, int iovcnt);
|
||||
|
||||
#endif /* _ROCKER_H_ */
|
377
hw/net/rocker/rocker_desc.c
Normal file
377
hw/net/rocker/rocker_desc.c
Normal file
@ -0,0 +1,377 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - Descriptor ring support
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "net/net.h"
|
||||
#include "hw/hw.h"
|
||||
#include "hw/pci/pci.h"
|
||||
|
||||
#include "rocker.h"
|
||||
#include "rocker_hw.h"
|
||||
#include "rocker_desc.h"
|
||||
|
||||
struct desc_ring {
|
||||
hwaddr base_addr;
|
||||
uint32_t size;
|
||||
uint32_t head;
|
||||
uint32_t tail;
|
||||
uint32_t ctrl;
|
||||
uint32_t credits;
|
||||
Rocker *r;
|
||||
DescInfo *info;
|
||||
int index;
|
||||
desc_ring_consume *consume;
|
||||
unsigned msix_vector;
|
||||
};
|
||||
|
||||
struct desc_info {
|
||||
DescRing *ring;
|
||||
RockerDesc desc;
|
||||
char *buf;
|
||||
size_t buf_size;
|
||||
};
|
||||
|
||||
uint16_t desc_buf_size(DescInfo *info)
|
||||
{
|
||||
return le16_to_cpu(info->desc.buf_size);
|
||||
}
|
||||
|
||||
uint16_t desc_tlv_size(DescInfo *info)
|
||||
{
|
||||
return le16_to_cpu(info->desc.tlv_size);
|
||||
}
|
||||
|
||||
char *desc_get_buf(DescInfo *info, bool read_only)
|
||||
{
|
||||
PCIDevice *dev = PCI_DEVICE(info->ring->r);
|
||||
size_t size = read_only ? le16_to_cpu(info->desc.tlv_size) :
|
||||
le16_to_cpu(info->desc.buf_size);
|
||||
|
||||
if (size > info->buf_size) {
|
||||
info->buf = g_realloc(info->buf, size);
|
||||
info->buf_size = size;
|
||||
}
|
||||
|
||||
if (!info->buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pci_dma_read(dev, le64_to_cpu(info->desc.buf_addr), info->buf, size)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return info->buf;
|
||||
}
|
||||
|
||||
int desc_set_buf(DescInfo *info, size_t tlv_size)
|
||||
{
|
||||
PCIDevice *dev = PCI_DEVICE(info->ring->r);
|
||||
|
||||
if (tlv_size > info->buf_size) {
|
||||
DPRINTF("ERROR: trying to write more to desc buf than it "
|
||||
"can hold buf_size %zu tlv_size %zu\n",
|
||||
info->buf_size, tlv_size);
|
||||
return -ROCKER_EMSGSIZE;
|
||||
}
|
||||
|
||||
info->desc.tlv_size = cpu_to_le16(tlv_size);
|
||||
pci_dma_write(dev, le64_to_cpu(info->desc.buf_addr), info->buf, tlv_size);
|
||||
|
||||
return ROCKER_OK;
|
||||
}
|
||||
|
||||
DescRing *desc_get_ring(DescInfo *info)
|
||||
{
|
||||
return info->ring;
|
||||
}
|
||||
|
||||
int desc_ring_index(DescRing *ring)
|
||||
{
|
||||
return ring->index;
|
||||
}
|
||||
|
||||
static bool desc_ring_empty(DescRing *ring)
|
||||
{
|
||||
return ring->head == ring->tail;
|
||||
}
|
||||
|
||||
bool desc_ring_set_base_addr(DescRing *ring, uint64_t base_addr)
|
||||
{
|
||||
if (base_addr & 0x7) {
|
||||
DPRINTF("ERROR: ring[%d] desc base addr (0x" TARGET_FMT_plx
|
||||
") not 8-byte aligned\n", ring->index, base_addr);
|
||||
return false;
|
||||
}
|
||||
|
||||
ring->base_addr = base_addr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t desc_ring_get_base_addr(DescRing *ring)
|
||||
{
|
||||
return ring->base_addr;
|
||||
}
|
||||
|
||||
bool desc_ring_set_size(DescRing *ring, uint32_t size)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (size < 2 || size > 0x10000 || (size & (size - 1))) {
|
||||
DPRINTF("ERROR: ring[%d] size (%d) not a power of 2 "
|
||||
"or in range [2, 64K]\n", ring->index, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < ring->size; i++) {
|
||||
if (ring->info[i].buf) {
|
||||
g_free(ring->info[i].buf);
|
||||
}
|
||||
}
|
||||
|
||||
ring->size = size;
|
||||
ring->head = ring->tail = 0;
|
||||
|
||||
ring->info = g_realloc(ring->info, size * sizeof(DescInfo));
|
||||
if (!ring->info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(ring->info, 0, size * sizeof(DescInfo));
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
ring->info[i].ring = ring;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t desc_ring_get_size(DescRing *ring)
|
||||
{
|
||||
return ring->size;
|
||||
}
|
||||
|
||||
static DescInfo *desc_read(DescRing *ring, uint32_t index)
|
||||
{
|
||||
PCIDevice *dev = PCI_DEVICE(ring->r);
|
||||
DescInfo *info = &ring->info[index];
|
||||
hwaddr addr = ring->base_addr + (sizeof(RockerDesc) * index);
|
||||
|
||||
pci_dma_read(dev, addr, &info->desc, sizeof(info->desc));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
static void desc_write(DescRing *ring, uint32_t index)
|
||||
{
|
||||
PCIDevice *dev = PCI_DEVICE(ring->r);
|
||||
DescInfo *info = &ring->info[index];
|
||||
hwaddr addr = ring->base_addr + (sizeof(RockerDesc) * index);
|
||||
|
||||
pci_dma_write(dev, addr, &info->desc, sizeof(info->desc));
|
||||
}
|
||||
|
||||
static bool desc_ring_base_addr_check(DescRing *ring)
|
||||
{
|
||||
if (!ring->base_addr) {
|
||||
DPRINTF("ERROR: ring[%d] not-initialized desc base address!\n",
|
||||
ring->index);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static DescInfo *__desc_ring_fetch_desc(DescRing *ring)
|
||||
{
|
||||
return desc_read(ring, ring->tail);
|
||||
}
|
||||
|
||||
DescInfo *desc_ring_fetch_desc(DescRing *ring)
|
||||
{
|
||||
if (desc_ring_empty(ring) || !desc_ring_base_addr_check(ring)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return desc_read(ring, ring->tail);
|
||||
}
|
||||
|
||||
static bool __desc_ring_post_desc(DescRing *ring, int err)
|
||||
{
|
||||
uint16_t comp_err = 0x8000 | (uint16_t)-err;
|
||||
DescInfo *info = &ring->info[ring->tail];
|
||||
|
||||
info->desc.comp_err = cpu_to_le16(comp_err);
|
||||
desc_write(ring, ring->tail);
|
||||
ring->tail = (ring->tail + 1) % ring->size;
|
||||
|
||||
/* return true if starting credit count */
|
||||
|
||||
return ring->credits++ == 0;
|
||||
}
|
||||
|
||||
bool desc_ring_post_desc(DescRing *ring, int err)
|
||||
{
|
||||
if (desc_ring_empty(ring)) {
|
||||
DPRINTF("ERROR: ring[%d] trying to post desc to empty ring\n",
|
||||
ring->index);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!desc_ring_base_addr_check(ring)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return __desc_ring_post_desc(ring, err);
|
||||
}
|
||||
|
||||
static bool ring_pump(DescRing *ring)
|
||||
{
|
||||
DescInfo *info;
|
||||
bool primed = false;
|
||||
int err;
|
||||
|
||||
/* If the ring has a consumer, call consumer for each
|
||||
* desc starting at tail and stopping when tail reaches
|
||||
* head (the empty ring condition).
|
||||
*/
|
||||
|
||||
if (ring->consume) {
|
||||
while (ring->head != ring->tail) {
|
||||
info = __desc_ring_fetch_desc(ring);
|
||||
err = ring->consume(ring->r, info);
|
||||
if (__desc_ring_post_desc(ring, err)) {
|
||||
primed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return primed;
|
||||
}
|
||||
|
||||
bool desc_ring_set_head(DescRing *ring, uint32_t new)
|
||||
{
|
||||
uint32_t tail = ring->tail;
|
||||
uint32_t head = ring->head;
|
||||
|
||||
if (!desc_ring_base_addr_check(ring)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (new >= ring->size) {
|
||||
DPRINTF("ERROR: trying to set head (%d) past ring[%d] size (%d)\n",
|
||||
new, ring->index, ring->size);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((head < tail) && ((new >= tail) || (new < head))) ||
|
||||
((head > tail) && ((new >= tail) && (new < head)))) {
|
||||
DPRINTF("ERROR: trying to wrap ring[%d] "
|
||||
"(head %d, tail %d, new head %d)\n",
|
||||
ring->index, head, tail, new);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (new == ring->head) {
|
||||
DPRINTF("WARNING: setting head (%d) to current head position\n", new);
|
||||
}
|
||||
|
||||
ring->head = new;
|
||||
|
||||
return ring_pump(ring);
|
||||
}
|
||||
|
||||
uint32_t desc_ring_get_head(DescRing *ring)
|
||||
{
|
||||
return ring->head;
|
||||
}
|
||||
|
||||
uint32_t desc_ring_get_tail(DescRing *ring)
|
||||
{
|
||||
return ring->tail;
|
||||
}
|
||||
|
||||
void desc_ring_set_ctrl(DescRing *ring, uint32_t val)
|
||||
{
|
||||
if (val & ROCKER_DMA_DESC_CTRL_RESET) {
|
||||
DPRINTF("ring[%d] resetting\n", ring->index);
|
||||
desc_ring_reset(ring);
|
||||
}
|
||||
}
|
||||
|
||||
bool desc_ring_ret_credits(DescRing *ring, uint32_t credits)
|
||||
{
|
||||
if (credits > ring->credits) {
|
||||
DPRINTF("ERROR: trying to return more credits (%d) "
|
||||
"than are outstanding (%d)\n", credits, ring->credits);
|
||||
ring->credits = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
ring->credits -= credits;
|
||||
|
||||
/* return true if credits are still outstanding */
|
||||
|
||||
return ring->credits > 0;
|
||||
}
|
||||
|
||||
uint32_t desc_ring_get_credits(DescRing *ring)
|
||||
{
|
||||
return ring->credits;
|
||||
}
|
||||
|
||||
void desc_ring_set_consume(DescRing *ring, desc_ring_consume *consume,
|
||||
unsigned vector)
|
||||
{
|
||||
ring->consume = consume;
|
||||
ring->msix_vector = vector;
|
||||
}
|
||||
|
||||
unsigned desc_ring_get_msix_vector(DescRing *ring)
|
||||
{
|
||||
return ring->msix_vector;
|
||||
}
|
||||
|
||||
DescRing *desc_ring_alloc(Rocker *r, int index)
|
||||
{
|
||||
DescRing *ring;
|
||||
|
||||
ring = g_malloc0(sizeof(DescRing));
|
||||
if (!ring) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ring->r = r;
|
||||
ring->index = index;
|
||||
|
||||
return ring;
|
||||
}
|
||||
|
||||
void desc_ring_free(DescRing *ring)
|
||||
{
|
||||
if (ring->info) {
|
||||
g_free(ring->info);
|
||||
}
|
||||
g_free(ring);
|
||||
}
|
||||
|
||||
void desc_ring_reset(DescRing *ring)
|
||||
{
|
||||
ring->base_addr = 0;
|
||||
ring->size = 0;
|
||||
ring->head = 0;
|
||||
ring->tail = 0;
|
||||
ring->ctrl = 0;
|
||||
ring->credits = 0;
|
||||
}
|
53
hw/net/rocker/rocker_desc.h
Normal file
53
hw/net/rocker/rocker_desc.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - Descriptor ring support
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ROCKER_DESC_H_
|
||||
#define _ROCKER_DESC_H_
|
||||
|
||||
#include "rocker_hw.h"
|
||||
|
||||
typedef int (desc_ring_consume)(Rocker *r, DescInfo *info);
|
||||
|
||||
uint16_t desc_buf_size(DescInfo *info);
|
||||
uint16_t desc_tlv_size(DescInfo *info);
|
||||
char *desc_get_buf(DescInfo *info, bool read_only);
|
||||
int desc_set_buf(DescInfo *info, size_t tlv_size);
|
||||
DescRing *desc_get_ring(DescInfo *info);
|
||||
|
||||
int desc_ring_index(DescRing *ring);
|
||||
bool desc_ring_set_base_addr(DescRing *ring, uint64_t base_addr);
|
||||
uint64_t desc_ring_get_base_addr(DescRing *ring);
|
||||
bool desc_ring_set_size(DescRing *ring, uint32_t size);
|
||||
uint32_t desc_ring_get_size(DescRing *ring);
|
||||
bool desc_ring_set_head(DescRing *ring, uint32_t new);
|
||||
uint32_t desc_ring_get_head(DescRing *ring);
|
||||
uint32_t desc_ring_get_tail(DescRing *ring);
|
||||
void desc_ring_set_ctrl(DescRing *ring, uint32_t val);
|
||||
bool desc_ring_ret_credits(DescRing *ring, uint32_t credits);
|
||||
uint32_t desc_ring_get_credits(DescRing *ring);
|
||||
|
||||
DescInfo *desc_ring_fetch_desc(DescRing *ring);
|
||||
bool desc_ring_post_desc(DescRing *ring, int status);
|
||||
|
||||
void desc_ring_set_consume(DescRing *ring, desc_ring_consume *consume,
|
||||
unsigned vector);
|
||||
unsigned desc_ring_get_msix_vector(DescRing *ring);
|
||||
DescRing *desc_ring_alloc(Rocker *r, int index);
|
||||
void desc_ring_free(DescRing *ring);
|
||||
void desc_ring_reset(DescRing *ring);
|
||||
|
||||
#endif
|
234
hw/net/rocker/rocker_fp.c
Normal file
234
hw/net/rocker/rocker_fp.c
Normal file
@ -0,0 +1,234 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - front-panel ports
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "net/clients.h"
|
||||
|
||||
#include "rocker.h"
|
||||
#include "rocker_hw.h"
|
||||
#include "rocker_fp.h"
|
||||
#include "rocker_world.h"
|
||||
|
||||
enum duplex {
|
||||
DUPLEX_HALF = 0,
|
||||
DUPLEX_FULL
|
||||
};
|
||||
|
||||
struct fp_port {
|
||||
Rocker *r;
|
||||
World *world;
|
||||
unsigned int index;
|
||||
char *name;
|
||||
uint32_t pport;
|
||||
bool enabled;
|
||||
uint32_t speed;
|
||||
uint8_t duplex;
|
||||
uint8_t autoneg;
|
||||
uint8_t learning;
|
||||
NICState *nic;
|
||||
NICConf conf;
|
||||
};
|
||||
|
||||
bool fp_port_get_link_up(FpPort *port)
|
||||
{
|
||||
return !qemu_get_queue(port->nic)->link_down;
|
||||
}
|
||||
|
||||
void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr)
|
||||
{
|
||||
memcpy(macaddr->a, port->conf.macaddr.a, sizeof(macaddr->a));
|
||||
}
|
||||
|
||||
void fp_port_set_macaddr(FpPort *port, MACAddr *macaddr)
|
||||
{
|
||||
/* XXX TODO implement and test setting mac addr
|
||||
* XXX memcpy(port->conf.macaddr.a, macaddr.a, sizeof(port->conf.macaddr.a));
|
||||
*/
|
||||
}
|
||||
|
||||
uint8_t fp_port_get_learning(FpPort *port)
|
||||
{
|
||||
return port->learning;
|
||||
}
|
||||
|
||||
void fp_port_set_learning(FpPort *port, uint8_t learning)
|
||||
{
|
||||
port->learning = learning;
|
||||
}
|
||||
|
||||
int fp_port_get_settings(FpPort *port, uint32_t *speed,
|
||||
uint8_t *duplex, uint8_t *autoneg)
|
||||
{
|
||||
*speed = port->speed;
|
||||
*duplex = port->duplex;
|
||||
*autoneg = port->autoneg;
|
||||
|
||||
return ROCKER_OK;
|
||||
}
|
||||
|
||||
int fp_port_set_settings(FpPort *port, uint32_t speed,
|
||||
uint8_t duplex, uint8_t autoneg)
|
||||
{
|
||||
/* XXX validate inputs */
|
||||
|
||||
port->speed = speed;
|
||||
port->duplex = duplex;
|
||||
port->autoneg = autoneg;
|
||||
|
||||
return ROCKER_OK;
|
||||
}
|
||||
|
||||
bool fp_port_from_pport(uint32_t pport, uint32_t *port)
|
||||
{
|
||||
if (pport < 1 || pport > ROCKER_FP_PORTS_MAX) {
|
||||
return false;
|
||||
}
|
||||
*port = pport - 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int fp_port_eg(FpPort *port, const struct iovec *iov, int iovcnt)
|
||||
{
|
||||
NetClientState *nc = qemu_get_queue(port->nic);
|
||||
|
||||
if (port->enabled) {
|
||||
qemu_sendv_packet(nc, iov, iovcnt);
|
||||
}
|
||||
|
||||
return ROCKER_OK;
|
||||
}
|
||||
|
||||
static int fp_port_can_receive(NetClientState *nc)
|
||||
{
|
||||
FpPort *port = qemu_get_nic_opaque(nc);
|
||||
|
||||
return port->enabled;
|
||||
}
|
||||
|
||||
static ssize_t fp_port_receive_iov(NetClientState *nc, const struct iovec *iov,
|
||||
int iovcnt)
|
||||
{
|
||||
FpPort *port = qemu_get_nic_opaque(nc);
|
||||
|
||||
return world_ingress(port->world, port->pport, iov, iovcnt);
|
||||
}
|
||||
|
||||
static ssize_t fp_port_receive(NetClientState *nc, const uint8_t *buf,
|
||||
size_t size)
|
||||
{
|
||||
const struct iovec iov = {
|
||||
.iov_base = (uint8_t *)buf,
|
||||
.iov_len = size
|
||||
};
|
||||
|
||||
return fp_port_receive_iov(nc, &iov, 1);
|
||||
}
|
||||
|
||||
static void fp_port_cleanup(NetClientState *nc)
|
||||
{
|
||||
}
|
||||
|
||||
static void fp_port_set_link_status(NetClientState *nc)
|
||||
{
|
||||
FpPort *port = qemu_get_nic_opaque(nc);
|
||||
|
||||
rocker_event_link_changed(port->r, port->pport, !nc->link_down);
|
||||
}
|
||||
|
||||
static NetClientInfo fp_port_info = {
|
||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
||||
.size = sizeof(NICState),
|
||||
.can_receive = fp_port_can_receive,
|
||||
.receive = fp_port_receive,
|
||||
.receive_iov = fp_port_receive_iov,
|
||||
.cleanup = fp_port_cleanup,
|
||||
.link_status_changed = fp_port_set_link_status,
|
||||
};
|
||||
|
||||
World *fp_port_get_world(FpPort *port)
|
||||
{
|
||||
return port->world;
|
||||
}
|
||||
|
||||
void fp_port_set_world(FpPort *port, World *world)
|
||||
{
|
||||
DPRINTF("port %d setting world \"%s\"\n", port->index, world_name(world));
|
||||
port->world = world;
|
||||
}
|
||||
|
||||
bool fp_port_enabled(FpPort *port)
|
||||
{
|
||||
return port->enabled;
|
||||
}
|
||||
|
||||
void fp_port_enable(FpPort *port)
|
||||
{
|
||||
port->enabled = true;
|
||||
DPRINTF("port %d enabled\n", port->index);
|
||||
}
|
||||
|
||||
void fp_port_disable(FpPort *port)
|
||||
{
|
||||
port->enabled = false;
|
||||
DPRINTF("port %d disabled\n", port->index);
|
||||
}
|
||||
|
||||
FpPort *fp_port_alloc(Rocker *r, char *sw_name,
|
||||
MACAddr *start_mac, unsigned int index,
|
||||
NICPeers *peers)
|
||||
{
|
||||
FpPort *port = g_malloc0(sizeof(FpPort));
|
||||
|
||||
if (!port) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
port->r = r;
|
||||
port->index = index;
|
||||
port->pport = index + 1;
|
||||
|
||||
/* front-panel switch port names are 1-based */
|
||||
|
||||
port->name = g_strdup_printf("%s.%d", sw_name, port->pport);
|
||||
|
||||
memcpy(port->conf.macaddr.a, start_mac, sizeof(port->conf.macaddr.a));
|
||||
port->conf.macaddr.a[5] += index;
|
||||
port->conf.bootindex = -1;
|
||||
port->conf.peers = *peers;
|
||||
|
||||
port->nic = qemu_new_nic(&fp_port_info, &port->conf,
|
||||
sw_name, NULL, port);
|
||||
qemu_format_nic_info_str(qemu_get_queue(port->nic),
|
||||
port->conf.macaddr.a);
|
||||
|
||||
fp_port_reset(port);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
void fp_port_free(FpPort *port)
|
||||
{
|
||||
qemu_del_nic(port->nic);
|
||||
g_free(port->name);
|
||||
g_free(port);
|
||||
}
|
||||
|
||||
void fp_port_reset(FpPort *port)
|
||||
{
|
||||
fp_port_disable(port);
|
||||
port->speed = 10000; /* 10Gbps */
|
||||
port->duplex = DUPLEX_FULL;
|
||||
port->autoneg = 0;
|
||||
}
|
51
hw/net/rocker/rocker_fp.h
Normal file
51
hw/net/rocker/rocker_fp.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - front-panel ports
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _ROCKER_FP_H_
|
||||
#define _ROCKER_FP_H_
|
||||
|
||||
#include "net/net.h"
|
||||
#include "qemu/iov.h"
|
||||
|
||||
#define ROCKER_FP_PORTS_MAX 62
|
||||
|
||||
typedef struct fp_port FpPort;
|
||||
|
||||
int fp_port_eg(FpPort *port, const struct iovec *iov, int iovcnt);
|
||||
|
||||
bool fp_port_get_link_up(FpPort *port);
|
||||
void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr);
|
||||
void fp_port_set_macaddr(FpPort *port, MACAddr *macaddr);
|
||||
uint8_t fp_port_get_learning(FpPort *port);
|
||||
void fp_port_set_learning(FpPort *port, uint8_t learning);
|
||||
int fp_port_get_settings(FpPort *port, uint32_t *speed,
|
||||
uint8_t *duplex, uint8_t *autoneg);
|
||||
int fp_port_set_settings(FpPort *port, uint32_t speed,
|
||||
uint8_t duplex, uint8_t autoneg);
|
||||
bool fp_port_from_pport(uint32_t pport, uint32_t *port);
|
||||
World *fp_port_get_world(FpPort *port);
|
||||
void fp_port_set_world(FpPort *port, World *world);
|
||||
bool fp_port_enabled(FpPort *port);
|
||||
void fp_port_enable(FpPort *port);
|
||||
void fp_port_disable(FpPort *port);
|
||||
|
||||
FpPort *fp_port_alloc(Rocker *r, char *sw_name,
|
||||
MACAddr *start_mac, unsigned int index,
|
||||
NICPeers *peers);
|
||||
void fp_port_free(FpPort *port);
|
||||
void fp_port_reset(FpPort *port);
|
||||
|
||||
#endif /* _ROCKER_FP_H_ */
|
491
hw/net/rocker/rocker_hw.h
Normal file
491
hw/net/rocker/rocker_hw.h
Normal file
@ -0,0 +1,491 @@
|
||||
/*
|
||||
* Rocker switch hardware register and descriptor definitions.
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
* Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ROCKER_HW_
|
||||
#define _ROCKER_HW_
|
||||
|
||||
#define __le16 uint16_t
|
||||
#define __le32 uint32_t
|
||||
#define __le64 uint64_t
|
||||
|
||||
/*
|
||||
* Return codes
|
||||
*/
|
||||
|
||||
enum {
|
||||
ROCKER_OK = 0,
|
||||
ROCKER_ENOENT = 2,
|
||||
ROCKER_ENXIO = 6,
|
||||
ROCKER_ENOMEM = 12,
|
||||
ROCKER_EEXIST = 17,
|
||||
ROCKER_EINVAL = 22,
|
||||
ROCKER_EMSGSIZE = 90,
|
||||
ROCKER_ENOTSUP = 95,
|
||||
ROCKER_ENOBUFS = 105,
|
||||
};
|
||||
|
||||
/*
|
||||
* PCI configuration space
|
||||
*/
|
||||
|
||||
#define ROCKER_PCI_REVISION 0x1
|
||||
#define ROCKER_PCI_BAR0_IDX 0
|
||||
#define ROCKER_PCI_BAR0_SIZE 0x2000
|
||||
#define ROCKER_PCI_MSIX_BAR_IDX 1
|
||||
#define ROCKER_PCI_MSIX_BAR_SIZE 0x2000
|
||||
#define ROCKER_PCI_MSIX_TABLE_OFFSET 0x0000
|
||||
#define ROCKER_PCI_MSIX_PBA_OFFSET 0x1000
|
||||
|
||||
/*
|
||||
* MSI-X vectors
|
||||
*/
|
||||
|
||||
enum {
|
||||
ROCKER_MSIX_VEC_CMD,
|
||||
ROCKER_MSIX_VEC_EVENT,
|
||||
ROCKER_MSIX_VEC_TEST,
|
||||
ROCKER_MSIX_VEC_RESERVED0,
|
||||
__ROCKER_MSIX_VEC_TX,
|
||||
__ROCKER_MSIX_VEC_RX,
|
||||
#define ROCKER_MSIX_VEC_TX(port) \
|
||||
(__ROCKER_MSIX_VEC_TX + ((port) * 2))
|
||||
#define ROCKER_MSIX_VEC_RX(port) \
|
||||
(__ROCKER_MSIX_VEC_RX + ((port) * 2))
|
||||
#define ROCKER_MSIX_VEC_COUNT(portcnt) \
|
||||
(ROCKER_MSIX_VEC_RX((portcnt) - 1) + 1)
|
||||
};
|
||||
|
||||
/*
|
||||
* Rocker bogus registers
|
||||
*/
|
||||
#define ROCKER_BOGUS_REG0 0x0000
|
||||
#define ROCKER_BOGUS_REG1 0x0004
|
||||
#define ROCKER_BOGUS_REG2 0x0008
|
||||
#define ROCKER_BOGUS_REG3 0x000c
|
||||
|
||||
/*
|
||||
* Rocker test registers
|
||||
*/
|
||||
#define ROCKER_TEST_REG 0x0010
|
||||
#define ROCKER_TEST_REG64 0x0018 /* 8-byte */
|
||||
#define ROCKER_TEST_IRQ 0x0020
|
||||
#define ROCKER_TEST_DMA_ADDR 0x0028 /* 8-byte */
|
||||
#define ROCKER_TEST_DMA_SIZE 0x0030
|
||||
#define ROCKER_TEST_DMA_CTRL 0x0034
|
||||
|
||||
/*
|
||||
* Rocker test register ctrl
|
||||
*/
|
||||
#define ROCKER_TEST_DMA_CTRL_CLEAR (1 << 0)
|
||||
#define ROCKER_TEST_DMA_CTRL_FILL (1 << 1)
|
||||
#define ROCKER_TEST_DMA_CTRL_INVERT (1 << 2)
|
||||
|
||||
/*
|
||||
* Rocker DMA ring register offsets
|
||||
*/
|
||||
#define ROCKER_DMA_DESC_BASE 0x1000
|
||||
#define ROCKER_DMA_DESC_SIZE 32
|
||||
#define ROCKER_DMA_DESC_MASK 0x1F
|
||||
#define ROCKER_DMA_DESC_TOTAL_SIZE \
|
||||
(ROCKER_DMA_DESC_SIZE * 64) /* 62 ports + event + cmd */
|
||||
#define ROCKER_DMA_DESC_ADDR_OFFSET 0x00 /* 8-byte */
|
||||
#define ROCKER_DMA_DESC_SIZE_OFFSET 0x08
|
||||
#define ROCKER_DMA_DESC_HEAD_OFFSET 0x0c
|
||||
#define ROCKER_DMA_DESC_TAIL_OFFSET 0x10
|
||||
#define ROCKER_DMA_DESC_CTRL_OFFSET 0x14
|
||||
#define ROCKER_DMA_DESC_CREDITS_OFFSET 0x18
|
||||
#define ROCKER_DMA_DESC_RSVD_OFFSET 0x1c
|
||||
|
||||
/*
|
||||
* Rocker dma ctrl register bits
|
||||
*/
|
||||
#define ROCKER_DMA_DESC_CTRL_RESET (1 << 0)
|
||||
|
||||
/*
|
||||
* Rocker ring indices
|
||||
*/
|
||||
#define ROCKER_RING_CMD 0
|
||||
#define ROCKER_RING_EVENT 1
|
||||
|
||||
/*
|
||||
* Helper macro to do convert a dma ring register
|
||||
* to its index. Based on the fact that the register
|
||||
* group stride is 32 bytes.
|
||||
*/
|
||||
#define ROCKER_RING_INDEX(reg) ((reg >> 5) & 0x7F)
|
||||
|
||||
/*
|
||||
* Rocker DMA Descriptor
|
||||
*/
|
||||
|
||||
typedef struct rocker_desc {
|
||||
__le64 buf_addr;
|
||||
uint64_t cookie;
|
||||
__le16 buf_size;
|
||||
__le16 tlv_size;
|
||||
__le16 rsvd[5]; /* pad to 32 bytes */
|
||||
__le16 comp_err;
|
||||
} __attribute__((packed, aligned(8))) RockerDesc;
|
||||
|
||||
/*
|
||||
* Rocker TLV type fields
|
||||
*/
|
||||
|
||||
typedef struct rocker_tlv {
|
||||
__le32 type;
|
||||
__le16 len;
|
||||
__le16 rsvd;
|
||||
} __attribute__((packed, aligned(8))) RockerTlv;
|
||||
|
||||
/* cmd msg */
|
||||
enum {
|
||||
ROCKER_TLV_CMD_UNSPEC,
|
||||
ROCKER_TLV_CMD_TYPE, /* u16 */
|
||||
ROCKER_TLV_CMD_INFO, /* nest */
|
||||
|
||||
__ROCKER_TLV_CMD_MAX,
|
||||
ROCKER_TLV_CMD_MAX = __ROCKER_TLV_CMD_MAX - 1,
|
||||
};
|
||||
|
||||
enum {
|
||||
ROCKER_TLV_CMD_TYPE_UNSPEC,
|
||||
ROCKER_TLV_CMD_TYPE_GET_PORT_SETTINGS,
|
||||
ROCKER_TLV_CMD_TYPE_SET_PORT_SETTINGS,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_ADD,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_MOD,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_DEL,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_FLOW_GET_STATS,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_ADD,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_MOD,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_DEL,
|
||||
ROCKER_TLV_CMD_TYPE_OF_DPA_GROUP_GET_STATS,
|
||||
|
||||
__ROCKER_TLV_CMD_TYPE_MAX,
|
||||
ROCKER_TLV_CMD_TYPE_MAX = __ROCKER_TLV_CMD_TYPE_MAX - 1,
|
||||
};
|
||||
|
||||
/* cmd info nested for set/get port settings */
|
||||
enum {
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_UNSPEC,
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_PPORT, /* u32 */
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_SPEED, /* u32 */
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_DUPLEX, /* u8 */
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_AUTONEG, /* u8 */
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_MACADDR, /* binary */
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_MODE, /* u8 */
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_LEARNING, /* u8 */
|
||||
|
||||
__ROCKER_TLV_CMD_PORT_SETTINGS_MAX,
|
||||
ROCKER_TLV_CMD_PORT_SETTINGS_MAX = __ROCKER_TLV_CMD_PORT_SETTINGS_MAX - 1,
|
||||
};
|
||||
|
||||
enum {
|
||||
ROCKER_PORT_MODE_OF_DPA,
|
||||
};
|
||||
|
||||
/* event msg */
|
||||
enum {
|
||||
ROCKER_TLV_EVENT_UNSPEC,
|
||||
ROCKER_TLV_EVENT_TYPE, /* u16 */
|
||||
ROCKER_TLV_EVENT_INFO, /* nest */
|
||||
|
||||
__ROCKER_TLV_EVENT_MAX,
|
||||
ROCKER_TLV_EVENT_MAX = __ROCKER_TLV_EVENT_MAX - 1,
|
||||
};
|
||||
|
||||
enum {
|
||||
ROCKER_TLV_EVENT_TYPE_UNSPEC,
|
||||
ROCKER_TLV_EVENT_TYPE_LINK_CHANGED,
|
||||
ROCKER_TLV_EVENT_TYPE_MAC_VLAN_SEEN,
|
||||
|
||||
__ROCKER_TLV_EVENT_TYPE_MAX,
|
||||
ROCKER_TLV_EVENT_TYPE_MAX = __ROCKER_TLV_EVENT_TYPE_MAX - 1,
|
||||
};
|
||||
|
||||
/* event info nested for link changed */
|
||||
enum {
|
||||
ROCKER_TLV_EVENT_LINK_CHANGED_UNSPEC,
|
||||
ROCKER_TLV_EVENT_LINK_CHANGED_PPORT, /* u32 */
|
||||
ROCKER_TLV_EVENT_LINK_CHANGED_LINKUP, /* u8 */
|
||||
|
||||
__ROCKER_TLV_EVENT_LINK_CHANGED_MAX,
|
||||
ROCKER_TLV_EVENT_LINK_CHANGED_MAX = __ROCKER_TLV_EVENT_LINK_CHANGED_MAX - 1,
|
||||
};
|
||||
|
||||
/* event info nested for MAC/VLAN */
|
||||
enum {
|
||||
ROCKER_TLV_EVENT_MAC_VLAN_UNSPEC,
|
||||
ROCKER_TLV_EVENT_MAC_VLAN_PPORT, /* u32 */
|
||||
ROCKER_TLV_EVENT_MAC_VLAN_MAC, /* binary */
|
||||
ROCKER_TLV_EVENT_MAC_VLAN_VLAN_ID, /* __be16 */
|
||||
|
||||
__ROCKER_TLV_EVENT_MAC_VLAN_MAX,
|
||||
ROCKER_TLV_EVENT_MAC_VLAN_MAX = __ROCKER_TLV_EVENT_MAC_VLAN_MAX - 1,
|
||||
};
|
||||
|
||||
/* Rx msg */
|
||||
enum {
|
||||
ROCKER_TLV_RX_UNSPEC,
|
||||
ROCKER_TLV_RX_FLAGS, /* u16, see RX_FLAGS_ */
|
||||
ROCKER_TLV_RX_CSUM, /* u16 */
|
||||
ROCKER_TLV_RX_FRAG_ADDR, /* u64 */
|
||||
ROCKER_TLV_RX_FRAG_MAX_LEN, /* u16 */
|
||||
ROCKER_TLV_RX_FRAG_LEN, /* u16 */
|
||||
|
||||
__ROCKER_TLV_RX_MAX,
|
||||
ROCKER_TLV_RX_MAX = __ROCKER_TLV_RX_MAX - 1,
|
||||
};
|
||||
|
||||
#define ROCKER_RX_FLAGS_IPV4 (1 << 0)
|
||||
#define ROCKER_RX_FLAGS_IPV6 (1 << 1)
|
||||
#define ROCKER_RX_FLAGS_CSUM_CALC (1 << 2)
|
||||
#define ROCKER_RX_FLAGS_IPV4_CSUM_GOOD (1 << 3)
|
||||
#define ROCKER_RX_FLAGS_IP_FRAG (1 << 4)
|
||||
#define ROCKER_RX_FLAGS_TCP (1 << 5)
|
||||
#define ROCKER_RX_FLAGS_UDP (1 << 6)
|
||||
#define ROCKER_RX_FLAGS_TCP_UDP_CSUM_GOOD (1 << 7)
|
||||
|
||||
/* Tx msg */
|
||||
enum {
|
||||
ROCKER_TLV_TX_UNSPEC,
|
||||
ROCKER_TLV_TX_OFFLOAD, /* u8, see TX_OFFLOAD_ */
|
||||
ROCKER_TLV_TX_L3_CSUM_OFF, /* u16 */
|
||||
ROCKER_TLV_TX_TSO_MSS, /* u16 */
|
||||
ROCKER_TLV_TX_TSO_HDR_LEN, /* u16 */
|
||||
ROCKER_TLV_TX_FRAGS, /* array */
|
||||
|
||||
__ROCKER_TLV_TX_MAX,
|
||||
ROCKER_TLV_TX_MAX = __ROCKER_TLV_TX_MAX - 1,
|
||||
};
|
||||
|
||||
#define ROCKER_TX_OFFLOAD_NONE 0
|
||||
#define ROCKER_TX_OFFLOAD_IP_CSUM 1
|
||||
#define ROCKER_TX_OFFLOAD_TCP_UDP_CSUM 2
|
||||
#define ROCKER_TX_OFFLOAD_L3_CSUM 3
|
||||
#define ROCKER_TX_OFFLOAD_TSO 4
|
||||
|
||||
#define ROCKER_TX_FRAGS_MAX 16
|
||||
|
||||
enum {
|
||||
ROCKER_TLV_TX_FRAG_UNSPEC,
|
||||
ROCKER_TLV_TX_FRAG, /* nest */
|
||||
|
||||
__ROCKER_TLV_TX_FRAG_MAX,
|
||||
ROCKER_TLV_TX_FRAG_MAX = __ROCKER_TLV_TX_FRAG_MAX - 1,
|
||||
};
|
||||
|
||||
enum {
|
||||
ROCKER_TLV_TX_FRAG_ATTR_UNSPEC,
|
||||
ROCKER_TLV_TX_FRAG_ATTR_ADDR, /* u64 */
|
||||
ROCKER_TLV_TX_FRAG_ATTR_LEN, /* u16 */
|
||||
|
||||
__ROCKER_TLV_TX_FRAG_ATTR_MAX,
|
||||
ROCKER_TLV_TX_FRAG_ATTR_MAX = __ROCKER_TLV_TX_FRAG_ATTR_MAX - 1,
|
||||
};
|
||||
|
||||
/*
|
||||
* cmd info nested for OF-DPA msgs
|
||||
*/
|
||||
|
||||
enum {
|
||||
ROCKER_TLV_OF_DPA_UNSPEC,
|
||||
ROCKER_TLV_OF_DPA_TABLE_ID, /* u16 */
|
||||
ROCKER_TLV_OF_DPA_PRIORITY, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_HARDTIME, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_IDLETIME, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_COOKIE, /* u64 */
|
||||
ROCKER_TLV_OF_DPA_IN_PPORT, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_IN_PPORT_MASK, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_OUT_PPORT, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_GOTO_TABLE_ID, /* u16 */
|
||||
ROCKER_TLV_OF_DPA_GROUP_ID, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_GROUP_ID_LOWER, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_GROUP_COUNT, /* u16 */
|
||||
ROCKER_TLV_OF_DPA_GROUP_IDS, /* u32 array */
|
||||
ROCKER_TLV_OF_DPA_VLAN_ID, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_VLAN_ID_MASK, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_VLAN_PCP, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_VLAN_PCP_MASK, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_VLAN_PCP_ACTION, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_NEW_VLAN_ID, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_NEW_VLAN_PCP, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_TUNNEL_ID, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_TUNNEL_LPORT, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_ETHERTYPE, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_DST_MAC, /* binary */
|
||||
ROCKER_TLV_OF_DPA_DST_MAC_MASK, /* binary */
|
||||
ROCKER_TLV_OF_DPA_SRC_MAC, /* binary */
|
||||
ROCKER_TLV_OF_DPA_SRC_MAC_MASK, /* binary */
|
||||
ROCKER_TLV_OF_DPA_IP_PROTO, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_IP_PROTO_MASK, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_IP_DSCP, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_IP_DSCP_MASK, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_IP_DSCP_ACTION, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_NEW_IP_DSCP, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_IP_ECN, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_IP_ECN_MASK, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_DST_IP, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_DST_IP_MASK, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_SRC_IP, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_SRC_IP_MASK, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_DST_IPV6, /* binary */
|
||||
ROCKER_TLV_OF_DPA_DST_IPV6_MASK, /* binary */
|
||||
ROCKER_TLV_OF_DPA_SRC_IPV6, /* binary */
|
||||
ROCKER_TLV_OF_DPA_SRC_IPV6_MASK, /* binary */
|
||||
ROCKER_TLV_OF_DPA_SRC_ARP_IP, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_SRC_ARP_IP_MASK, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_L4_DST_PORT, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_L4_DST_PORT_MASK, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_L4_SRC_PORT, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_L4_SRC_PORT_MASK, /* __be16 */
|
||||
ROCKER_TLV_OF_DPA_ICMP_TYPE, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_ICMP_TYPE_MASK, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_ICMP_CODE, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_ICMP_CODE_MASK, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_IPV6_LABEL, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_IPV6_LABEL_MASK, /* __be32 */
|
||||
ROCKER_TLV_OF_DPA_QUEUE_ID_ACTION, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_NEW_QUEUE_ID, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_CLEAR_ACTIONS, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_POP_VLAN, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_TTL_CHECK, /* u8 */
|
||||
ROCKER_TLV_OF_DPA_COPY_CPU_ACTION, /* u8 */
|
||||
|
||||
__ROCKER_TLV_OF_DPA_MAX,
|
||||
ROCKER_TLV_OF_DPA_MAX = __ROCKER_TLV_OF_DPA_MAX - 1,
|
||||
};
|
||||
|
||||
/*
|
||||
* OF-DPA table IDs
|
||||
*/
|
||||
|
||||
enum rocker_of_dpa_table_id {
|
||||
ROCKER_OF_DPA_TABLE_ID_INGRESS_PORT = 0,
|
||||
ROCKER_OF_DPA_TABLE_ID_VLAN = 10,
|
||||
ROCKER_OF_DPA_TABLE_ID_TERMINATION_MAC = 20,
|
||||
ROCKER_OF_DPA_TABLE_ID_UNICAST_ROUTING = 30,
|
||||
ROCKER_OF_DPA_TABLE_ID_MULTICAST_ROUTING = 40,
|
||||
ROCKER_OF_DPA_TABLE_ID_BRIDGING = 50,
|
||||
ROCKER_OF_DPA_TABLE_ID_ACL_POLICY = 60,
|
||||
};
|
||||
|
||||
/*
|
||||
* OF-DPA flow stats
|
||||
*/
|
||||
|
||||
enum {
|
||||
ROCKER_TLV_OF_DPA_FLOW_STAT_UNSPEC,
|
||||
ROCKER_TLV_OF_DPA_FLOW_STAT_DURATION, /* u32 */
|
||||
ROCKER_TLV_OF_DPA_FLOW_STAT_RX_PKTS, /* u64 */
|
||||
ROCKER_TLV_OF_DPA_FLOW_STAT_TX_PKTS, /* u64 */
|
||||
|
||||
__ROCKER_TLV_OF_DPA_FLOW_STAT_MAX,
|
||||
ROCKER_TLV_OF_DPA_FLOW_STAT_MAX = __ROCKER_TLV_OF_DPA_FLOW_STAT_MAX - 1,
|
||||
};
|
||||
|
||||
/*
|
||||
* OF-DPA group types
|
||||
*/
|
||||
|
||||
enum rocker_of_dpa_group_type {
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L2_INTERFACE = 0,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L2_REWRITE,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L3_UCAST,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L2_MCAST,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L2_FLOOD,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L3_INTERFACE,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L3_MCAST,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L3_ECMP,
|
||||
ROCKER_OF_DPA_GROUP_TYPE_L2_OVERLAY,
|
||||
};
|
||||
|
||||
/*
|
||||
* OF-DPA group L2 overlay types
|
||||
*/
|
||||
|
||||
enum rocker_of_dpa_overlay_type {
|
||||
ROCKER_OF_DPA_OVERLAY_TYPE_FLOOD_UCAST = 0,
|
||||
ROCKER_OF_DPA_OVERLAY_TYPE_FLOOD_MCAST,
|
||||
ROCKER_OF_DPA_OVERLAY_TYPE_MCAST_UCAST,
|
||||
ROCKER_OF_DPA_OVERLAY_TYPE_MCAST_MCAST,
|
||||
};
|
||||
|
||||
/*
|
||||
* OF-DPA group ID encoding
|
||||
*/
|
||||
|
||||
#define ROCKER_GROUP_TYPE_SHIFT 28
|
||||
#define ROCKER_GROUP_TYPE_MASK 0xf0000000
|
||||
#define ROCKER_GROUP_VLAN_ID_SHIFT 16
|
||||
#define ROCKER_GROUP_VLAN_ID_MASK 0x0fff0000
|
||||
#define ROCKER_GROUP_PORT_SHIFT 0
|
||||
#define ROCKER_GROUP_PORT_MASK 0x0000ffff
|
||||
#define ROCKER_GROUP_TUNNEL_ID_SHIFT 12
|
||||
#define ROCKER_GROUP_TUNNEL_ID_MASK 0x0ffff000
|
||||
#define ROCKER_GROUP_SUBTYPE_SHIFT 10
|
||||
#define ROCKER_GROUP_SUBTYPE_MASK 0x00000c00
|
||||
#define ROCKER_GROUP_INDEX_SHIFT 0
|
||||
#define ROCKER_GROUP_INDEX_MASK 0x0000ffff
|
||||
#define ROCKER_GROUP_INDEX_LONG_SHIFT 0
|
||||
#define ROCKER_GROUP_INDEX_LONG_MASK 0x0fffffff
|
||||
|
||||
#define ROCKER_GROUP_TYPE_GET(group_id) \
|
||||
(((group_id) & ROCKER_GROUP_TYPE_MASK) >> ROCKER_GROUP_TYPE_SHIFT)
|
||||
#define ROCKER_GROUP_TYPE_SET(type) \
|
||||
(((type) << ROCKER_GROUP_TYPE_SHIFT) & ROCKER_GROUP_TYPE_MASK)
|
||||
#define ROCKER_GROUP_VLAN_GET(group_id) \
|
||||
(((group_id) & ROCKER_GROUP_VLAN_ID_MASK) >> ROCKER_GROUP_VLAN_ID_SHIFT)
|
||||
#define ROCKER_GROUP_VLAN_SET(vlan_id) \
|
||||
(((vlan_id) << ROCKER_GROUP_VLAN_ID_SHIFT) & ROCKER_GROUP_VLAN_ID_MASK)
|
||||
#define ROCKER_GROUP_PORT_GET(group_id) \
|
||||
(((group_id) & ROCKER_GROUP_PORT_MASK) >> ROCKER_GROUP_PORT_SHIFT)
|
||||
#define ROCKER_GROUP_PORT_SET(port) \
|
||||
(((port) << ROCKER_GROUP_PORT_SHIFT) & ROCKER_GROUP_PORT_MASK)
|
||||
#define ROCKER_GROUP_INDEX_GET(group_id) \
|
||||
(((group_id) & ROCKER_GROUP_INDEX_MASK) >> ROCKER_GROUP_INDEX_SHIFT)
|
||||
#define ROCKER_GROUP_INDEX_SET(index) \
|
||||
(((index) << ROCKER_GROUP_INDEX_SHIFT) & ROCKER_GROUP_INDEX_MASK)
|
||||
#define ROCKER_GROUP_INDEX_LONG_GET(group_id) \
|
||||
(((group_id) & ROCKER_GROUP_INDEX_LONG_MASK) >> \
|
||||
ROCKER_GROUP_INDEX_LONG_SHIFT)
|
||||
#define ROCKER_GROUP_INDEX_LONG_SET(index) \
|
||||
(((index) << ROCKER_GROUP_INDEX_LONG_SHIFT) & \
|
||||
ROCKER_GROUP_INDEX_LONG_MASK)
|
||||
|
||||
#define ROCKER_GROUP_NONE 0
|
||||
#define ROCKER_GROUP_L2_INTERFACE(vlan_id, port) \
|
||||
(ROCKER_GROUP_TYPE_SET(ROCKER_OF_DPA_GROUP_TYPE_L2_INTERFACE) |\
|
||||
ROCKER_GROUP_VLAN_SET(ntohs(vlan_id)) | ROCKER_GROUP_PORT_SET(port))
|
||||
#define ROCKER_GROUP_L2_REWRITE(index) \
|
||||
(ROCKER_GROUP_TYPE_SET(ROCKER_OF_DPA_GROUP_TYPE_L2_REWRITE) |\
|
||||
ROCKER_GROUP_INDEX_LONG_SET(index))
|
||||
#define ROCKER_GROUP_L2_MCAST(vlan_id, index) \
|
||||
(ROCKER_GROUP_TYPE_SET(ROCKER_OF_DPA_GROUP_TYPE_L2_MCAST) |\
|
||||
ROCKER_GROUP_VLAN_SET(ntohs(vlan_id)) | ROCKER_GROUP_INDEX_SET(index))
|
||||
#define ROCKER_GROUP_L2_FLOOD(vlan_id, index) \
|
||||
(ROCKER_GROUP_TYPE_SET(ROCKER_OF_DPA_GROUP_TYPE_L2_FLOOD) |\
|
||||
ROCKER_GROUP_VLAN_SET(ntohs(vlan_id)) | ROCKER_GROUP_INDEX_SET(index))
|
||||
#define ROCKER_GROUP_L3_UNICAST(index) \
|
||||
(ROCKER_GROUP_TYPE_SET(ROCKER_OF_DPA_GROUP_TYPE_L3_UCAST) |\
|
||||
ROCKER_GROUP_INDEX_LONG_SET(index))
|
||||
|
||||
/*
|
||||
* Rocker general purpose registers
|
||||
*/
|
||||
#define ROCKER_CONTROL 0x0300
|
||||
#define ROCKER_PORT_PHYS_COUNT 0x0304
|
||||
#define ROCKER_PORT_PHYS_LINK_STATUS 0x0310 /* 8-byte */
|
||||
#define ROCKER_PORT_PHYS_ENABLE 0x0318 /* 8-byte */
|
||||
#define ROCKER_SWITCH_ID 0x0320 /* 8-byte */
|
||||
|
||||
/*
|
||||
* Rocker control bits
|
||||
*/
|
||||
#define ROCKER_CONTROL_RESET (1 << 0)
|
||||
|
||||
#endif /* _ROCKER_HW_ */
|
2315
hw/net/rocker/rocker_of_dpa.c
Normal file
2315
hw/net/rocker/rocker_of_dpa.c
Normal file
File diff suppressed because it is too large
Load Diff
22
hw/net/rocker/rocker_of_dpa.h
Normal file
22
hw/net/rocker/rocker_of_dpa.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - OF-DPA flow processing support
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _ROCKER_OF_DPA_H_
|
||||
#define _ROCKER_OF_DPA_H_
|
||||
|
||||
World *of_dpa_world_alloc(Rocker *r);
|
||||
|
||||
#endif /* _ROCKER_OF_DPA_H_ */
|
244
hw/net/rocker/rocker_tlv.h
Normal file
244
hw/net/rocker/rocker_tlv.h
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - TLV parsing and composing
|
||||
*
|
||||
* Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _ROCKER_TLV_H_
|
||||
#define _ROCKER_TLV_H_
|
||||
|
||||
#define ROCKER_TLV_ALIGNTO 8U
|
||||
#define ROCKER_TLV_ALIGN(len) \
|
||||
(((len) + ROCKER_TLV_ALIGNTO - 1) & ~(ROCKER_TLV_ALIGNTO - 1))
|
||||
#define ROCKER_TLV_HDRLEN ROCKER_TLV_ALIGN(sizeof(RockerTlv))
|
||||
|
||||
/*
|
||||
* <------- ROCKER_TLV_HDRLEN -------> <--- ROCKER_TLV_ALIGN(payload) --->
|
||||
* +-----------------------------+- - -+- - - - - - - - - - - - - - -+- - -+
|
||||
* | Header | Pad | Payload | Pad |
|
||||
* | (RockerTlv) | ing | | ing |
|
||||
* +-----------------------------+- - -+- - - - - - - - - - - - - - -+- - -+
|
||||
* <--------------------------- tlv->len -------------------------->
|
||||
*/
|
||||
|
||||
static inline RockerTlv *rocker_tlv_next(const RockerTlv *tlv, int *remaining)
|
||||
{
|
||||
int totlen = ROCKER_TLV_ALIGN(le16_to_cpu(tlv->len));
|
||||
|
||||
*remaining -= totlen;
|
||||
return (RockerTlv *) ((char *) tlv + totlen);
|
||||
}
|
||||
|
||||
static inline int rocker_tlv_ok(const RockerTlv *tlv, int remaining)
|
||||
{
|
||||
return remaining >= (int) ROCKER_TLV_HDRLEN &&
|
||||
le16_to_cpu(tlv->len) >= ROCKER_TLV_HDRLEN &&
|
||||
le16_to_cpu(tlv->len) <= remaining;
|
||||
}
|
||||
|
||||
#define rocker_tlv_for_each(pos, head, len, rem) \
|
||||
for (pos = head, rem = len; \
|
||||
rocker_tlv_ok(pos, rem); \
|
||||
pos = rocker_tlv_next(pos, &(rem)))
|
||||
|
||||
#define rocker_tlv_for_each_nested(pos, tlv, rem) \
|
||||
rocker_tlv_for_each(pos, rocker_tlv_data(tlv), rocker_tlv_len(tlv), rem)
|
||||
|
||||
static inline int rocker_tlv_size(int payload)
|
||||
{
|
||||
return ROCKER_TLV_HDRLEN + payload;
|
||||
}
|
||||
|
||||
static inline int rocker_tlv_total_size(int payload)
|
||||
{
|
||||
return ROCKER_TLV_ALIGN(rocker_tlv_size(payload));
|
||||
}
|
||||
|
||||
static inline int rocker_tlv_padlen(int payload)
|
||||
{
|
||||
return rocker_tlv_total_size(payload) - rocker_tlv_size(payload);
|
||||
}
|
||||
|
||||
static inline int rocker_tlv_type(const RockerTlv *tlv)
|
||||
{
|
||||
return le32_to_cpu(tlv->type);
|
||||
}
|
||||
|
||||
static inline void *rocker_tlv_data(const RockerTlv *tlv)
|
||||
{
|
||||
return (char *) tlv + ROCKER_TLV_HDRLEN;
|
||||
}
|
||||
|
||||
static inline int rocker_tlv_len(const RockerTlv *tlv)
|
||||
{
|
||||
return le16_to_cpu(tlv->len) - ROCKER_TLV_HDRLEN;
|
||||
}
|
||||
|
||||
static inline uint8_t rocker_tlv_get_u8(const RockerTlv *tlv)
|
||||
{
|
||||
return *(uint8_t *) rocker_tlv_data(tlv);
|
||||
}
|
||||
|
||||
static inline uint16_t rocker_tlv_get_u16(const RockerTlv *tlv)
|
||||
{
|
||||
return *(uint16_t *) rocker_tlv_data(tlv);
|
||||
}
|
||||
|
||||
static inline uint32_t rocker_tlv_get_u32(const RockerTlv *tlv)
|
||||
{
|
||||
return *(uint32_t *) rocker_tlv_data(tlv);
|
||||
}
|
||||
|
||||
static inline uint64_t rocker_tlv_get_u64(const RockerTlv *tlv)
|
||||
{
|
||||
return *(uint64_t *) rocker_tlv_data(tlv);
|
||||
}
|
||||
|
||||
static inline uint16_t rocker_tlv_get_le16(const RockerTlv *tlv)
|
||||
{
|
||||
return le16_to_cpup((uint16_t *) rocker_tlv_data(tlv));
|
||||
}
|
||||
|
||||
static inline uint32_t rocker_tlv_get_le32(const RockerTlv *tlv)
|
||||
{
|
||||
return le32_to_cpup((uint32_t *) rocker_tlv_data(tlv));
|
||||
}
|
||||
|
||||
static inline uint64_t rocker_tlv_get_le64(const RockerTlv *tlv)
|
||||
{
|
||||
return le64_to_cpup((uint64_t *) rocker_tlv_data(tlv));
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_parse(RockerTlv **tb, int maxtype,
|
||||
const char *buf, int buf_len)
|
||||
{
|
||||
const RockerTlv *tlv;
|
||||
const RockerTlv *head = (const RockerTlv *) buf;
|
||||
int rem;
|
||||
|
||||
memset(tb, 0, sizeof(RockerTlv *) * (maxtype + 1));
|
||||
|
||||
rocker_tlv_for_each(tlv, head, buf_len, rem) {
|
||||
uint32_t type = rocker_tlv_type(tlv);
|
||||
|
||||
if (type > 0 && type <= maxtype) {
|
||||
tb[type] = (RockerTlv *) tlv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_parse_nested(RockerTlv **tb, int maxtype,
|
||||
const RockerTlv *tlv)
|
||||
{
|
||||
rocker_tlv_parse(tb, maxtype, rocker_tlv_data(tlv), rocker_tlv_len(tlv));
|
||||
}
|
||||
|
||||
static inline RockerTlv *rocker_tlv_start(char *buf, int buf_pos)
|
||||
{
|
||||
return (RockerTlv *) (buf + buf_pos);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_iov(char *buf, int *buf_pos,
|
||||
int type, const struct iovec *iov,
|
||||
const unsigned int iovcnt)
|
||||
{
|
||||
size_t len = iov_size(iov, iovcnt);
|
||||
int total_size = rocker_tlv_total_size(len);
|
||||
RockerTlv *tlv;
|
||||
|
||||
tlv = rocker_tlv_start(buf, *buf_pos);
|
||||
*buf_pos += total_size;
|
||||
tlv->type = cpu_to_le32(type);
|
||||
tlv->len = cpu_to_le16(rocker_tlv_size(len));
|
||||
iov_to_buf(iov, iovcnt, 0, rocker_tlv_data(tlv), len);
|
||||
memset((char *) tlv + le16_to_cpu(tlv->len), 0, rocker_tlv_padlen(len));
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put(char *buf, int *buf_pos,
|
||||
int type, int len, void *data)
|
||||
{
|
||||
struct iovec iov = {
|
||||
.iov_base = data,
|
||||
.iov_len = len,
|
||||
};
|
||||
|
||||
rocker_tlv_put_iov(buf, buf_pos, type, &iov, 1);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_u8(char *buf, int *buf_pos,
|
||||
int type, uint8_t value)
|
||||
{
|
||||
rocker_tlv_put(buf, buf_pos, type, sizeof(uint8_t), &value);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_u16(char *buf, int *buf_pos,
|
||||
int type, uint16_t value)
|
||||
{
|
||||
rocker_tlv_put(buf, buf_pos, type, sizeof(uint16_t), &value);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_u32(char *buf, int *buf_pos,
|
||||
int type, uint32_t value)
|
||||
{
|
||||
rocker_tlv_put(buf, buf_pos, type, sizeof(uint32_t), &value);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_u64(char *buf, int *buf_pos,
|
||||
int type, uint64_t value)
|
||||
{
|
||||
rocker_tlv_put(buf, buf_pos, type, sizeof(uint64_t), &value);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_le16(char *buf, int *buf_pos,
|
||||
int type, uint16_t value)
|
||||
{
|
||||
value = cpu_to_le16(value);
|
||||
rocker_tlv_put(buf, buf_pos, type, sizeof(uint16_t), &value);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_le32(char *buf, int *buf_pos,
|
||||
int type, uint32_t value)
|
||||
{
|
||||
value = cpu_to_le32(value);
|
||||
rocker_tlv_put(buf, buf_pos, type, sizeof(uint32_t), &value);
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_put_le64(char *buf, int *buf_pos,
|
||||
int type, uint64_t value)
|
||||
{
|
||||
value = cpu_to_le64(value);
|
||||
rocker_tlv_put(buf, buf_pos, type, sizeof(uint64_t), &value);
|
||||
}
|
||||
|
||||
static inline RockerTlv *rocker_tlv_nest_start(char *buf, int *buf_pos,
|
||||
int type)
|
||||
{
|
||||
RockerTlv *start = rocker_tlv_start(buf, *buf_pos);
|
||||
|
||||
rocker_tlv_put(buf, buf_pos, type, 0, NULL);
|
||||
return start;
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_nest_end(char *buf, int *buf_pos,
|
||||
RockerTlv *start)
|
||||
{
|
||||
start->len = (char *) rocker_tlv_start(buf, *buf_pos) - (char *) start;
|
||||
}
|
||||
|
||||
static inline void rocker_tlv_nest_cancel(char *buf, int *buf_pos,
|
||||
RockerTlv *start)
|
||||
{
|
||||
*buf_pos = (char *) start - buf;
|
||||
}
|
||||
|
||||
#endif
|
106
hw/net/rocker/rocker_world.c
Normal file
106
hw/net/rocker/rocker_world.c
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - switch worlds
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "qemu/iov.h"
|
||||
|
||||
#include "rocker.h"
|
||||
#include "rocker_world.h"
|
||||
|
||||
struct world {
|
||||
Rocker *r;
|
||||
enum rocker_world_type type;
|
||||
WorldOps *ops;
|
||||
};
|
||||
|
||||
ssize_t world_ingress(World *world, uint32_t pport,
|
||||
const struct iovec *iov, int iovcnt)
|
||||
{
|
||||
if (world->ops->ig) {
|
||||
return world->ops->ig(world, pport, iov, iovcnt);
|
||||
}
|
||||
|
||||
return iov_size(iov, iovcnt);
|
||||
}
|
||||
|
||||
int world_do_cmd(World *world, DescInfo *info,
|
||||
char *buf, uint16_t cmd, RockerTlv *cmd_info_tlv)
|
||||
{
|
||||
if (world->ops->cmd) {
|
||||
return world->ops->cmd(world, info, buf, cmd, cmd_info_tlv);
|
||||
}
|
||||
|
||||
return -ROCKER_ENOTSUP;
|
||||
}
|
||||
|
||||
World *world_alloc(Rocker *r, size_t sizeof_private,
|
||||
enum rocker_world_type type, WorldOps *ops)
|
||||
{
|
||||
World *w = g_malloc0(sizeof(World) + sizeof_private);
|
||||
|
||||
if (w) {
|
||||
w->r = r;
|
||||
w->type = type;
|
||||
w->ops = ops;
|
||||
if (w->ops->init) {
|
||||
w->ops->init(w);
|
||||
}
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
void world_free(World *world)
|
||||
{
|
||||
if (world->ops->uninit) {
|
||||
world->ops->uninit(world);
|
||||
}
|
||||
g_free(world);
|
||||
}
|
||||
|
||||
void world_reset(World *world)
|
||||
{
|
||||
if (world->ops->uninit) {
|
||||
world->ops->uninit(world);
|
||||
}
|
||||
if (world->ops->init) {
|
||||
world->ops->init(world);
|
||||
}
|
||||
}
|
||||
|
||||
void *world_private(World *world)
|
||||
{
|
||||
return world + 1;
|
||||
}
|
||||
|
||||
Rocker *world_rocker(World *world)
|
||||
{
|
||||
return world->r;
|
||||
}
|
||||
|
||||
enum rocker_world_type world_type(World *world)
|
||||
{
|
||||
return world->type;
|
||||
}
|
||||
|
||||
const char *world_name(World *world)
|
||||
{
|
||||
switch (world->type) {
|
||||
case ROCKER_WORLD_TYPE_OF_DPA:
|
||||
return "OF_DPA";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
60
hw/net/rocker/rocker_world.h
Normal file
60
hw/net/rocker/rocker_world.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* QEMU rocker switch emulation - switch worlds
|
||||
*
|
||||
* Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _ROCKER_WORLD_H_
|
||||
#define _ROCKER_WORLD_H_
|
||||
|
||||
#include "rocker_hw.h"
|
||||
|
||||
enum rocker_world_type {
|
||||
ROCKER_WORLD_TYPE_OF_DPA = ROCKER_PORT_MODE_OF_DPA,
|
||||
ROCKER_WORLD_TYPE_MAX,
|
||||
};
|
||||
|
||||
typedef int (world_init)(World *world);
|
||||
typedef void (world_uninit)(World *world);
|
||||
typedef ssize_t (world_ig)(World *world, uint32_t pport,
|
||||
const struct iovec *iov, int iovcnt);
|
||||
typedef int (world_cmd)(World *world, DescInfo *info,
|
||||
char *buf, uint16_t cmd,
|
||||
RockerTlv *cmd_info_tlv);
|
||||
|
||||
typedef struct world_ops {
|
||||
world_init *init;
|
||||
world_uninit *uninit;
|
||||
world_ig *ig;
|
||||
world_cmd *cmd;
|
||||
} WorldOps;
|
||||
|
||||
ssize_t world_ingress(World *world, uint32_t pport,
|
||||
const struct iovec *iov, int iovcnt);
|
||||
int world_do_cmd(World *world, DescInfo *info,
|
||||
char *buf, uint16_t cmd, RockerTlv *cmd_info_tlv);
|
||||
|
||||
World *world_alloc(Rocker *r, size_t sizeof_private,
|
||||
enum rocker_world_type type, WorldOps *ops);
|
||||
void world_free(World *world);
|
||||
void world_reset(World *world);
|
||||
|
||||
void *world_private(World *world);
|
||||
Rocker *world_rocker(World *world);
|
||||
|
||||
enum rocker_world_type world_type(World *world);
|
||||
const char *world_name(World *world);
|
||||
|
||||
World *rocker_get_world(Rocker *r, enum rocker_world_type type);
|
||||
|
||||
#endif /* _ROCKER_WORLD_H_ */
|
@ -226,12 +226,6 @@ static void rxfilter_notify(NetClientState *nc)
|
||||
}
|
||||
}
|
||||
|
||||
static char *mac_strdup_printf(const uint8_t *mac)
|
||||
{
|
||||
return g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0],
|
||||
mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
static intList *get_vlan_table(VirtIONet *n)
|
||||
{
|
||||
intList *list, *entry;
|
||||
@ -284,12 +278,12 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
|
||||
info->multicast_overflow = n->mac_table.multi_overflow;
|
||||
info->unicast_overflow = n->mac_table.uni_overflow;
|
||||
|
||||
info->main_mac = mac_strdup_printf(n->mac);
|
||||
info->main_mac = qemu_mac_strdup_printf(n->mac);
|
||||
|
||||
str_list = NULL;
|
||||
for (i = 0; i < n->mac_table.first_multi; i++) {
|
||||
entry = g_malloc0(sizeof(*entry));
|
||||
entry->value = mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
|
||||
entry->value = qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
|
||||
entry->next = str_list;
|
||||
str_list = entry;
|
||||
}
|
||||
@ -298,7 +292,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
|
||||
str_list = NULL;
|
||||
for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) {
|
||||
entry = g_malloc0(sizeof(*entry));
|
||||
entry->value = mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
|
||||
entry->value = qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
|
||||
entry->next = str_list;
|
||||
str_list = entry;
|
||||
}
|
||||
|
@ -88,6 +88,7 @@
|
||||
#define PCI_DEVICE_ID_REDHAT_SERIAL2 0x0003
|
||||
#define PCI_DEVICE_ID_REDHAT_SERIAL4 0x0004
|
||||
#define PCI_DEVICE_ID_REDHAT_TEST 0x0005
|
||||
#define PCI_DEVICE_ID_REDHAT_ROCKER 0x0006
|
||||
#define PCI_DEVICE_ID_REDHAT_SDHCI 0x0007
|
||||
#define PCI_DEVICE_ID_REDHAT_PCIE_HOST 0x0008
|
||||
#define PCI_DEVICE_ID_REDHAT_QXL 0x0100
|
||||
|
@ -23,6 +23,7 @@
|
||||
#define PCI_CLASS_STORAGE_OTHER 0x0180
|
||||
|
||||
#define PCI_CLASS_NETWORK_ETHERNET 0x0200
|
||||
#define PCI_CLASS_NETWORK_OTHER 0x0280
|
||||
|
||||
#define PCI_CLASS_DISPLAY_VGA 0x0300
|
||||
#define PCI_CLASS_DISPLAY_OTHER 0x0380
|
||||
|
@ -97,6 +97,7 @@ typedef struct NICState {
|
||||
bool peer_deleted;
|
||||
} NICState;
|
||||
|
||||
char *qemu_mac_strdup_printf(const uint8_t *macaddr);
|
||||
NetClientState *qemu_find_netdev(const char *id);
|
||||
int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
|
||||
NetClientOptionsKind type, int max);
|
||||
|
@ -151,6 +151,13 @@ int parse_host_port(struct sockaddr_in *saddr, const char *str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *qemu_mac_strdup_printf(const uint8_t *macaddr)
|
||||
{
|
||||
return g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
|
||||
macaddr[0], macaddr[1], macaddr[2],
|
||||
macaddr[3], macaddr[4], macaddr[5]);
|
||||
}
|
||||
|
||||
void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6])
|
||||
{
|
||||
snprintf(nc->info_str, sizeof(nc->info_str),
|
||||
|
5
tests/rocker/README
Normal file
5
tests/rocker/README
Normal file
@ -0,0 +1,5 @@
|
||||
Tests require simp (simple network simulator) found here:
|
||||
|
||||
https://github.com/scottfeldman/simp
|
||||
|
||||
Run 'all' to run all tests.
|
19
tests/rocker/all
Executable file
19
tests/rocker/all
Executable file
@ -0,0 +1,19 @@
|
||||
echo -n "Running port test... "
|
||||
./port
|
||||
if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi
|
||||
|
||||
echo -n "Running bridge test... "
|
||||
./bridge
|
||||
if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi
|
||||
|
||||
echo -n "Running bridge STP test... "
|
||||
./bridge-stp
|
||||
if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi
|
||||
|
||||
echo -n "Running bridge VLAN test... "
|
||||
./bridge-vlan
|
||||
if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi
|
||||
|
||||
echo -n "Running bridge VLAN STP test... "
|
||||
./bridge-vlan-stp
|
||||
if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi
|
48
tests/rocker/bridge
Executable file
48
tests/rocker/bridge
Executable file
@ -0,0 +1,48 @@
|
||||
simp destroy ".*"
|
||||
simp create -o sw1:rocker:sw1 tut tut.dot
|
||||
simp start tut
|
||||
sleep 10
|
||||
while ! simp ssh tut sw1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h2 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
|
||||
# configure a 2-port bridge
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link add name br0 type bridge"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp1 master br0"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp2 master br0"
|
||||
|
||||
# turn off vlan default_pvid on br0
|
||||
|
||||
simp ssh tut sw1 --cmd "echo 0 | sudo dd of=/sys/class/net/br0/bridge/default_pvid 2> /dev/null"
|
||||
|
||||
# turn off learning and flooding in SW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning off"
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 flood off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 flood off"
|
||||
|
||||
# turn on learning in HW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning on self"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning on self"
|
||||
|
||||
# bring up bridge and ports
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig br0 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp2 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig br0 11.0.0.3/24"
|
||||
|
||||
# config IP on hosts
|
||||
|
||||
simp ssh tut h1 --cmd "sudo ifconfig swp1 11.0.0.1/24"
|
||||
simp ssh tut h2 --cmd "sudo ifconfig swp1 11.0.0.2/24"
|
||||
|
||||
# test...
|
||||
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
if [ $? -ne 0 ]; then exit 1; fi
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.3 >/dev/null"
|
57
tests/rocker/bridge-stp
Executable file
57
tests/rocker/bridge-stp
Executable file
@ -0,0 +1,57 @@
|
||||
simp destroy ".*"
|
||||
simp create -o sw1:rocker:sw1 tut tut.dot
|
||||
simp start tut
|
||||
sleep 10
|
||||
while ! simp ssh tut sw1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h2 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
|
||||
# configure a 2-port bridge
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link add name br0 type bridge"
|
||||
simp ssh tut sw1 --cmd "sudo brctl stp br0 on"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp1 master br0"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp2 master br0"
|
||||
|
||||
# turn off vlan default_pvid on br0
|
||||
|
||||
simp ssh tut sw1 --cmd "echo 0 | sudo dd of=/sys/class/net/br0/bridge/default_pvid 2> /dev/null"
|
||||
|
||||
# turn off learning and flooding in SW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning off"
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 flood off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 flood off"
|
||||
|
||||
# turn on learning in HW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning on self"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning on self"
|
||||
|
||||
# config IP on hosts
|
||||
|
||||
simp ssh tut h1 --cmd "sudo ifconfig swp1 11.0.0.1/24"
|
||||
simp ssh tut h2 --cmd "sudo ifconfig swp1 11.0.0.2/24"
|
||||
|
||||
# bring up bridge and ports
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig br0 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp2 up"
|
||||
|
||||
# test...
|
||||
|
||||
simp ssh tut h1 --cmd "ping -w 1 -c1 11.0.0.2 >/dev/null"
|
||||
if [ $? -eq 0 ]; then exit 1; fi
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
57
tests/rocker/bridge-vlan
Executable file
57
tests/rocker/bridge-vlan
Executable file
@ -0,0 +1,57 @@
|
||||
simp destroy ".*"
|
||||
simp create -o sw1:rocker:sw1 tut tut.dot
|
||||
simp start tut
|
||||
sleep 10
|
||||
while ! simp ssh tut sw1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h2 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
|
||||
# configure a 2-port bridge
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link add name br0 type bridge"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp1 master br0"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp2 master br0"
|
||||
|
||||
# turn off vlan default_pvid on br0
|
||||
# turn on vlan filtering on br0
|
||||
|
||||
simp ssh tut sw1 --cmd "echo 0 | sudo dd of=/sys/class/net/br0/bridge/default_pvid 2> /dev/null"
|
||||
simp ssh tut sw1 --cmd "echo 1 | sudo dd of=/sys/class/net/br0/bridge/vlan_filtering 2> /dev/null"
|
||||
|
||||
# add both ports to VLAN 57
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge vlan add vid 57 dev swp1 master"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge vlan add vid 57 dev swp2 master"
|
||||
|
||||
# turn off learning and flooding in SW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning off"
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 flood off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 flood off"
|
||||
|
||||
# turn on learning in HW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning on self"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning on self"
|
||||
|
||||
# bring up bridge and ports
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig br0 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp2 up"
|
||||
|
||||
# config IP on host VLANs
|
||||
|
||||
simp ssh tut h1 --cmd "sudo vconfig add swp1 57 >/dev/null 2>&1"
|
||||
simp ssh tut h1 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut h1 --cmd "sudo ifconfig swp1.57 11.0.0.1/24"
|
||||
|
||||
simp ssh tut h2 --cmd "sudo vconfig add swp1 57 >/dev/null 2>&1"
|
||||
simp ssh tut h2 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut h2 --cmd "sudo ifconfig swp1.57 11.0.0.2/24"
|
||||
|
||||
# test...
|
||||
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
69
tests/rocker/bridge-vlan-stp
Executable file
69
tests/rocker/bridge-vlan-stp
Executable file
@ -0,0 +1,69 @@
|
||||
simp destroy ".*"
|
||||
simp create -o sw1:rocker:sw1 tut tut.dot
|
||||
simp start tut
|
||||
sleep 10
|
||||
while ! simp ssh tut sw1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h2 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
|
||||
# configure a 2-port bridge
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link add name br0 type bridge"
|
||||
simp ssh tut sw1 --cmd "sudo brctl stp br0 on"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp1 master br0"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/ip link set dev swp2 master br0"
|
||||
|
||||
# turn off vlan default_pvid on br0
|
||||
# turn on vlan filtering on br0
|
||||
|
||||
simp ssh tut sw1 --cmd "echo 0 | sudo dd of=/sys/class/net/br0/bridge/default_pvid 2> /dev/null"
|
||||
simp ssh tut sw1 --cmd "echo 1 | sudo dd of=/sys/class/net/br0/bridge/vlan_filtering 2> /dev/null"
|
||||
|
||||
# add both ports to VLAN 57
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge vlan add vid 57 dev swp1 master"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge vlan add vid 57 dev swp2 master"
|
||||
|
||||
# turn off learning and flooding in SW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning off"
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 flood off"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 flood off"
|
||||
|
||||
# turn on learning in HW
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp1 learning on self"
|
||||
simp ssh tut sw1 --cmd "sudo /sbin/bridge link set dev swp2 learning on self"
|
||||
|
||||
# config IP on host VLANs
|
||||
|
||||
simp ssh tut h1 --cmd "sudo vconfig add swp1 57 >/dev/null 2>&1"
|
||||
simp ssh tut h1 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut h1 --cmd "sudo ifconfig swp1.57 11.0.0.1/24"
|
||||
|
||||
simp ssh tut h2 --cmd "sudo vconfig add swp1 57 >/dev/null 2>&1"
|
||||
simp ssh tut h2 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut h2 --cmd "sudo ifconfig swp1.57 11.0.0.2/24"
|
||||
|
||||
# bring up bridge and ports
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig br0 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp1 up"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp2 up"
|
||||
|
||||
# test...
|
||||
|
||||
simp ssh tut h1 --cmd "ping -w 1 -c1 11.0.0.2 >/dev/null"
|
||||
if [ $? -eq 0 ]; then exit 1; fi
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
||||
sleep 10
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.2 >/dev/null"
|
22
tests/rocker/port
Executable file
22
tests/rocker/port
Executable file
@ -0,0 +1,22 @@
|
||||
simp destroy ".*"
|
||||
simp create -o sw1:rocker:sw1 tut tut.dot
|
||||
simp start tut
|
||||
while ! simp ssh tut sw1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h1 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
while ! simp ssh tut h2 --cmd "ping -c 1 localhost >/dev/null"; do sleep 1; done
|
||||
|
||||
# bring up DUT ports
|
||||
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp1 11.0.0.1/24"
|
||||
simp ssh tut sw1 --cmd "sudo ifconfig swp2 12.0.0.1/24"
|
||||
|
||||
# config IP on hosts
|
||||
|
||||
simp ssh tut h1 --cmd "sudo ifconfig swp1 11.0.0.2/24"
|
||||
simp ssh tut h2 --cmd "sudo ifconfig swp1 12.0.0.2/24"
|
||||
|
||||
# test...
|
||||
|
||||
simp ssh tut h1 --cmd "ping -c10 11.0.0.1 >/dev/null"
|
||||
if [ $? -eq 1 ]; then exit 1; fi
|
||||
simp ssh tut h2 --cmd "ping -c10 12.0.0.1 >/dev/null"
|
8
tests/rocker/tut.dot
Normal file
8
tests/rocker/tut.dot
Normal file
@ -0,0 +1,8 @@
|
||||
graph G {
|
||||
graph [hostidtype="hostname", version="1:0", date="04/12/2013"];
|
||||
edge [dir=none, notify="log"];
|
||||
sw1:swp1 -- h1:swp1;
|
||||
sw1:swp2 -- h2:swp1;
|
||||
sw1:swp3 -- h3:swp1;
|
||||
sw1:swp4 -- h4:swp1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user