connect SimNetwork to actual network

This commit is contained in:
Howard Mao
2017-07-04 03:54:32 +00:00
parent cb6290539c
commit abef4737fa
5 changed files with 302 additions and 53 deletions

View File

@@ -2,59 +2,10 @@
#include <stdlib.h>
#include <stdio.h>
#define SIMPLENIC_BASE 0x10016000L
#define SIMPLENIC_SEND_REQ (SIMPLENIC_BASE + 0)
#define SIMPLENIC_RECV_REQ (SIMPLENIC_BASE + 8)
#define SIMPLENIC_SEND_COMP (SIMPLENIC_BASE + 16)
#define SIMPLENIC_RECV_COMP (SIMPLENIC_BASE + 18)
#define SIMPLENIC_COUNTS (SIMPLENIC_BASE + 20)
#include "nic.h"
uint64_t src[200];
uint64_t dst[201];
static inline int nic_send_req_avail(void)
{
return reg_read16(SIMPLENIC_COUNTS) & 0xf;
}
static inline int nic_recv_req_avail(void)
{
return (reg_read16(SIMPLENIC_COUNTS) >> 4) & 0xf;
}
static inline int nic_send_comp_avail(void)
{
return (reg_read16(SIMPLENIC_COUNTS) >> 8) & 0xf;
}
static inline int nic_recv_comp_avail(void)
{
return (reg_read16(SIMPLENIC_COUNTS) >> 12) & 0xf;
}
static void nic_send(void *data, unsigned long len)
{
uintptr_t addr = ((uintptr_t) data) & ((1L << 48) - 1);
unsigned long packet = (len << 48) | addr;
while (nic_send_req_avail() == 0);
reg_write64(SIMPLENIC_SEND_REQ, packet);
}
static int nic_recv(void *dest)
{
uintptr_t addr = (uintptr_t) dest;
int len;
while (nic_recv_req_avail() == 0);
reg_write64(SIMPLENIC_RECV_REQ, addr);
// Poll for completion
while (nic_recv_comp_avail() == 0);
len = reg_read16(SIMPLENIC_RECV_COMP);
return len;
}
uint64_t dst[200];
#define TEST_LEN 128