#endif
#ifdef V3_CONFIG_VNET
- palacios_init_vnet();
+ palacios_vnet_init();
#endif
#ifdef V3_CONFIG_HOST_DEVICE
printk("Set VNET Debug level to %d\n", level);
if(level >= 0){
- vnet_debug = level;
+ net_debug = level;
}
return size;
static int debug_show(struct seq_file * file, void * v){
- seq_printf(file, "Current VNET Debug Level: %d\n", vnet_debug);
+ seq_printf(file, "Current VNET Debug Level: %d\n", net_debug);
return 0;
}
memcpy(pkt.header, buf, ETHERNET_HEADER_LEN);
pkt.data = buf;
- if(vnet_debug >= 2){
+ if(net_debug >= 2){
printk("VNET Lnx Bridge: send pkt to VNET core (size: %d, src_id: %d, src_type: %d)\n",
pkt.size, pkt.src_id, pkt.src_type);
- if(vnet_debug >= 4){
+ if(net_debug >= 4){
print_hex_dump(NULL, "pkt_data: ", 0, 20, 20, pkt.data, pkt.size, 0);
}
}
void * private_data) {
struct vnet_link * link;
- if(vnet_debug >= 2){
+ if(net_debug >= 2){
printk("VNET Lnx Host Bridge: packet received from VNET Core ... pkt size: %d, link: %d\n",
pkt->size,
pkt->dst_id);
- if(vnet_debug >= 4){
+ if(net_debug >= 4){
print_hex_dump(NULL, "pkt_data: ", 0, 20, 20, pkt->data, pkt->size, 0);
}
}
}
-int palacios_init_vnet(void) {
+int palacios_init_vnet_bridge(void) {
struct v3_vnet_bridge_ops bridge_ops;
#include <vnet/vnet.h>
#include "palacios-mm.h"
+#include "palacios-vnet.h"
static void host_print(const char * fmt, ...) {
-int vnet_init( void ) {
- printk("Host init VNET\n");
-
+int palacios_vnet_init( void ) {
init_vnet(&vnet_host_hooks);
+
+ palacios_init_vnet_bridge();
+ printk("V3 VNET Inited\n");
return 0;
}
#ifndef __PALACIOS_VNET_BRIDGE_H__
#define __PALACIOS_VNET_BRIDGE_H__
-int palacios_init_vnet(void);
+int palacios_vnet_init(void);
+int palacios_init_vnet_bridge(void);
#endif
#define MAX_PACKET_LEN (ETHERNET_HEADER_LEN + MAX_MTU)
-
-extern int vnet_debug;
+#ifdef V3_CONFIG_VNET
+extern int net_debug;
+#endif
#ifdef __V3VEE__
#define V3_Net_Print(level, fmt, args...) \
do { \
- if(level <= vnet_debug) { \
+ if(level <= net_debug) { \
extern struct v3_os_hooks * os_hooks; \
if ((os_hooks) && (os_hooks)->print) { \
(os_hooks)->print((fmt), ##args); \
#define Vnet_Print(level, fmt, args...) \
do { \
- extern int vnet_debug; \
- if(level <= vnet_debug) { \
+ extern int net_debug; \
+ if(level <= net_debug) { \
extern struct vnet_host_hooks * host_hooks; \
if ((host_hooks) && (host_hooks)->print) { \
(host_hooks)->print((fmt), ##args); \
#define PrintDebug(fmt, args...)
#endif
+#ifndef V3_CONFIG_VNET
+static int net_debug = 0;
+#endif
+
#define TX_QUEUE_SIZE 4096
#define RX_QUEUE_SIZE 4096
#define CTRL_QUEUE_SIZE 64
}
V3_Net_Print(2, "Virtio-NIC: virtio_tx: size: %d\n", len);
- if(vnet_debug >= 4){
+ if(net_debug >= 4){
v3_hexdump(buf, len, NULL, 0);
}
}
static inline void enable_cb(struct virtio_queue *queue){
- queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG;
+ if(queue->used){
+ queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG;
+ }
}
static inline void disable_cb(struct virtio_queue *queue) {
- queue->used->flags |= VRING_NO_NOTIFY_FLAG;
+ if(queue->used){
+ queue->used->flags |= VRING_NO_NOTIFY_FLAG;
+ }
}
static int handle_pkt_tx(struct guest_info * core,
unsigned long flags;
V3_Net_Print(2, "Virtio-NIC: virtio_rx: size: %d\n", size);
- if(vnet_debug >= 4){
+ if(net_debug >= 4){
v3_hexdump(buf, size, NULL, 0);
}
return 0;
}
+
#define RATE_UPPER_THRESHOLD 10 /* 10000 pkts per second, around 100Mbits */
#define RATE_LOWER_THRESHOLD 1
#define PROFILE_PERIOD 10000 /*us*/
uint64_t period_us;
static int profile_ms = 0;
+ if(!net_state->status){ /* VNIC is not in working status */
+ return;
+ }
+
period_us = (1000*cpu_cycles)/cpu_freq;
net_state->past_us += period_us;
net_state->timer = v3_add_timer(&(info->cores[0]),&timer_ops,net_state);
+ PrintError("net_state 0x%p\n", (void *)net_state);
+
ops->recv = virtio_rx;
ops->frontend_data = net_state;
memcpy(ops->fnt_mac, virtio->mac, ETH_ALEN);
net_state->poll_thread = vnet_start_thread(virtio_tx_flush, (void *)net_state, "Virtio_Poll");
+ net_state->status = 1;
+
return 0;
}
V3_Net_Print(2, "VNET-NIC: send pkt (size: %d, src_id: %d, src_type: %d)\n",
pkt.size, pkt.src_id, pkt.src_type);
- if(vnet_debug >= 4){
+ if(net_debug >= 4){
v3_hexdump(buf, len, NULL, 0);
}
#define Vnet_Debug(fmt, args...)
#endif
-int vnet_debug = 0;
+int net_debug = 0;
struct eth_hdr {
uint8_t dst_mac[ETH_ALEN];
Vnet_Print(2, "VNET/P Core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n",
cpu, pkt->size, pkt->src_id,
pkt->src_type, pkt->dst_id, pkt->dst_type);
- if(vnet_debug >= 4){
+ if(net_debug >= 4){
v3_hexdump(pkt->data, pkt->size, NULL, 0);
}
struct vnet_host_hooks * host_hooks;
-
int vnet_lock_init(vnet_lock_t * lock) {
- *lock = (addr_t)(host_hooks->mutex_alloc());
-
- if (!(*lock)) {
- return -1;
+ if((host_hooks) && host_hooks->mutex_alloc){
+ *lock = (addr_t)(host_hooks->mutex_alloc());
+
+ if (*lock) {
+ return 0;
+ }
}
- return 0;
+ return -1;
}
struct vnet_thread * vnet_start_thread(int (*func)(void *), void *arg, char * name){
- struct vnet_thread * thread;
+ if((host_hooks) && host_hooks->thread_start){
+ struct vnet_thread * thread = Vnet_Malloc(sizeof(struct vnet_thread));
+ thread->host_thread = host_hooks->thread_start(func, arg, name);
- thread = Vnet_Malloc(sizeof(struct vnet_thread));
-
- thread->host_thread = host_hooks->thread_start(func, arg, name);
-
- if(thread->host_thread == NULL){
+ if(thread->host_thread){
+ return thread;
+ }
Vnet_Free(thread);
- return NULL;
}
- return thread;
+ return NULL;
}
struct vnet_timer * vnet_create_timer(unsigned long interval,
void (* timer_fun)(void * priv_data),
void * priv_data){
- struct vnet_timer * timer = NULL;
-
if((host_hooks) && host_hooks->timer_create){
- timer = Vnet_Malloc(sizeof(struct vnet_timer));
-
+ struct vnet_timer * timer = Vnet_Malloc(sizeof(struct vnet_timer));
timer->host_timer = host_hooks->timer_create(interval, timer_fun, priv_data);
+ return timer;
}
- return timer;
+ return NULL;
}