#include <palacios/vmm_sprintf.h>
#include <palacios/vmm_ethernet.h>
-#ifndef CONFIG_DEBUG_VNET
+#ifndef V3_CONFIG_DEBUG_VNET
#undef PrintDebug
#define PrintDebug(fmt, args...)
#endif
struct queue_entry{
uint8_t use;
struct v3_vnet_pkt pkt;
- uint8_t data[ETHERNET_PACKET_LEN];
+ uint8_t * data;
+ uint32_t size_alloc;
};
-#define VNET_QUEUE_SIZE 10240
+#define VNET_QUEUE_SIZE 1024
struct vnet_queue {
struct queue_entry buf[VNET_QUEUE_SIZE];
int head, tail;
} vnet_state;
-#ifdef CONFIG_DEBUG_VNET
+#ifdef V3_CONFIG_DEBUG_VNET
static inline void mac_to_string(uint8_t * mac, char * buf) {
snprintf(buf, 100, "%2x:%2x:%2x:%2x:%2x:%2x",
mac[0], mac[1], mac[2],
new_route = (struct vnet_route_info *)V3_Malloc(sizeof(struct vnet_route_info));
memset(new_route, 0, sizeof(struct vnet_route_info));
-#ifdef CONFIG_DEBUG_VNET
+#ifdef V3_CONFIG_DEBUG_VNET
PrintDebug("VNET/P Core: add_route_entry:\n");
print_route(&route);
#endif
v3_unlock_irqrestore(vnet_state.lock, flags);
-#ifdef CONFIG_DEBUG_VNET
+#ifdef V3_CONFIG_DEBUG_VNET
dump_routes();
#endif
// uint8_t src_type = pkt->src_type;
// uint32_t src_link = pkt->src_id;
-#ifdef CONFIG_DEBUG_VNET
+#ifdef V3_CONFIG_DEBUG_VNET
{
char dst_str[100];
char src_str[100];
unsigned long flags;
struct queue_entry * entry;
struct vnet_queue * q = &(vnet_state.pkt_q);
+ uint16_t num_pages;
flags = v3_lock_irqsave(q->lock);
/* this is ugly, but should happen very unlikely */
while(entry->use);
+ if(entry->size_alloc < pkt->size){
+ if(entry->data != NULL){
+ V3_FreePages(V3_PAddr(entry->data), (entry->size_alloc / PAGE_SIZE));
+ entry->data = NULL;
+ }
+
+ num_pages = 1 + (pkt->size / PAGE_SIZE);
+ entry->data = V3_VAddr(V3_AllocPages(num_pages));
+ if(entry->data == NULL){
+ return -1;
+ }
+ entry->size_alloc = PAGE_SIZE * num_pages;
+ }
+
entry->pkt.data = entry->data;
memcpy(&(entry->pkt), pkt, sizeof(struct v3_vnet_pkt));
memcpy(entry->data, pkt->data, pkt->size);
/* this is ugly, but should happen very unlikely */
while(!entry->use);
vnet_tx_one_pkt(&(entry->pkt), NULL);
+
+ /* asynchronizely release allocated memory for buffer entry here */
entry->use = 0;
V3_Net_Print(2, "vnet_tx_flush: pkt (size %d)\n", entry->pkt.size);