#include <barrelfish/deferred.h>
#include <devif/queue_interface.h>
#include <devif/backends/net/sfn5122f_devif.h>
-//#include <devif/backends/net/e10k_devif.h>
+#include <devif/backends/net/e10k_devif.h>
#include <devif/backends/descq.h>
#include <bench/bench.h>
#include <net_interfaces/flags.h>
+
+//#define DEBUG(x...) printf("devif_test: " x)
+#define DEBUG(x...) do {} while (0)
+
#define BUF_SIZE 2048
#define NUM_ENQ 512
#define NUM_RX_BUF 1024
#define NUM_ROUNDS_RX 128
#define MEMORY_SIZE BASE_PAGE_SIZE*512
+static char* card;
+
static struct capref memory_rx;
static struct capref memory_tx;
static regionid_t regid_rx;
0x00, 0x80, 0x00, 0x00,
};
-/*
static void print_buffer(size_t len, bufferid_t bid)
{
+ /*
uint8_t* buf = (uint8_t*) va_rx+bid;
- printf("Packet in region %p at address %p len %zu \n",
+ DEBUG("Packet in region %p at address %p len %zu \n",
va_rx, buf, len);
for (int i = 0; i < len; i++) {
if (((i % 10) == 0) && i > 0) {
printf("%2X ", buf[i]);
}
printf("\n");
+ */
}
-*/
+
static void wait_for_interrupt(void)
{
errval_t err = event_dispatch(&card_ws);
}
}
-static void sfn5122f_event_cb(void* queue)
+static void event_cb(void* queue)
{
struct devq* q = (struct devq*) queue;
}
if (flags & NETIF_TXFLAG) {
+ DEBUG("Received TX buffer back \n");
num_tx++;
} else if (flags & NETIF_RXFLAG) {
num_rx++;
- //print_buffer(len, bid);
+ DEBUG("Received RX buffer \n");
+ print_buffer(len, bid);
} else {
- printf("Unknown flags \n");
+ printf("Unknown flags %lx \n", flags);
}
}
- // MSIX is not working on sfn5122f yet so we have to "simulate interrupts"
+ // MSIX is not working on so we have to "simulate interrupts"
err = waitset_chan_register(&card_ws, chan,
- MKCLOSURE(sfn5122f_event_cb, queue));
+ MKCLOSURE(event_cb, queue));
if (err_is_fail(err) && err_no(err) == LIB_ERR_CHAN_ALREADY_REGISTERED) {
printf("Got actual interrupt?\n");
}
}
}
-static void test_sfn5122f_tx(void)
+static struct devq* create_net_queue(char* card_name)
+{
+ errval_t err;
+ if (strcmp(card_name, "sfn5122f") == 0) {
+ struct sfn5122f_queue* q;
+
+ err = sfn5122f_queue_create(&q, event_cb, /* userlevel*/ true,
+ /*MSIX interrupts*/ false);
+ if (err_is_fail(err)){
+ USER_PANIC("Allocating devq failed \n");
+ }
+ return (struct devq*) q;
+ }
+
+ if (strcmp(card_name, "e10k") == 0) {
+ struct e10k_queue* q;
+
+ err = e10k_queue_create(&q, event_cb, /*VFs */ false,
+ /*MSIX interrupts*/ false);
+ if (err_is_fail(err)){
+ USER_PANIC("Allocating devq failed \n");
+ }
+ return (struct devq*) q;
+ }
+
+ USER_PANIC("Unknown card name\n");
+
+ return NULL;
+}
+
+static errval_t destroy_net_queue(struct devq* q, char* card_name)
+{
+ errval_t err;
+ if (strcmp(card_name, "sfn5122f") == 0) {
+ err = sfn5122f_queue_destroy((struct sfn5122f_queue*)q);
+ if (err_is_fail(err)){
+ USER_PANIC("Destroying devq failed \n");
+ }
+ return err;
+ }
+
+ if (strcmp(card_name, "e10k") == 0) {
+ err = e10k_queue_destroy((struct e10k_queue*)q);
+ if (err_is_fail(err)){
+ USER_PANIC("Destroying devq failed \n");
+ }
+ return err;
+ }
+
+ USER_PANIC("Unknown card name\n");
+
+ return SYS_ERR_OK;
+}
+
+static void test_net_tx(void)
{
num_tx = 0;
num_rx = 0;
errval_t err;
struct devq* q;
- struct sfn5122f_queue* queue;
-
- printf("SFN5122F direct device test started \n");
- err = sfn5122f_queue_create(&queue, sfn5122f_event_cb, true, false);
- if (err_is_fail(err)){
- USER_PANIC("Allocating devq failed \n");
- }
-
- q = (struct devq*) queue;
+ q = create_net_queue(card);
+ assert(q != NULL);
+
waitset_init(&card_ws);
// MSIX is not working on sfn5122f yet so we have to "simulate interrupts"
chan = malloc(sizeof(struct waitset_chanstate));
waitset_chanstate_init(chan, CHANTYPE_AHCI);
- err = waitset_chan_register(&card_ws, chan, MKCLOSURE(sfn5122f_event_cb, q));
+ err = waitset_chan_register(&card_ws, chan, MKCLOSURE(event_cb, q));
if (err_is_fail(err)) {
USER_PANIC_ERR(err, "waitset_chan_regster failed.");
}
// write something into the buffers
char* write = NULL;
- uint16_t rest = 4096 -BUF_SIZE;
for (int i = 0; i < NUM_ENQ; i++) {
- write = va_tx + i*(BUF_SIZE+rest);
+ write = va_tx + i*(BUF_SIZE);
for (int j = 0; j < 8; j++) {
write[j] = udp_header[j];
}
USER_PANIC("Devq deregister tx failed \n");
}
- err = sfn5122f_queue_destroy((struct sfn5122f_queue*) q);
+ err = destroy_net_queue(q, card);
+ if (err_is_fail(err)){
+ printf("%s \n", err_getstring(err));
+ USER_PANIC("Destroying %s queue failed \n", card);
+ }
- printf("SUCCESS: SFN5122F tx test ended\n");
+ printf("SUCCESS: %s tx test ended\n", card);
}
-static void test_sfn5122f_rx(void)
+static void test_net_rx(void)
{
+
num_tx = 0;
num_rx = 0;
errval_t err;
struct devq* q;
- struct sfn5122f_queue* queue;
-
- printf("SFN5122F direct device test started \n");
- err = sfn5122f_queue_create(&queue, sfn5122f_event_cb, /* userlevel*/ true,
- /*MSIX interrupts*/ false);
- if (err_is_fail(err)){
- USER_PANIC("Allocating devq failed \n");
- }
-
- q = (struct devq*) queue;
-
+
+ q = create_net_queue(card);
+ assert(q != NULL);
waitset_init(&card_ws);
chan = malloc(sizeof(struct waitset_chanstate));
waitset_chanstate_init(chan, CHANTYPE_AHCI);
- err = waitset_chan_register(&card_ws, chan, MKCLOSURE(sfn5122f_event_cb, q));
+ err = waitset_chan_register(&card_ws, chan, MKCLOSURE(event_cb, q));
if (err_is_fail(err)) {
USER_PANIC_ERR(err, "waitset_chan_regster failed.");
}
USER_PANIC("Devq deregister rx failed \n");
}
- err = sfn5122f_queue_destroy((struct sfn5122f_queue*) q);
+ err = destroy_net_queue(q, card);
+ if (err_is_fail(err)){
+ printf("%s \n", err_getstring(err));
+ USER_PANIC("Destroying %s queue failed \n", card);
+ }
- printf("SUCCESS: SFN5122F rx test ended\n");
+ printf("SUCCESS: %s rx test ended\n", card);
}
printf("SUCCESS: IDC queue\n");
}
-
-#if 0
-static void e10k_event_cb(void* queue)
-{
- return;
-}
-
-static void test_e10k_queue(void)
-{
- num_tx = 0;
- num_rx = 0;
-
- errval_t err;
- struct devq* q;
- struct e10k_queue* queue;
-
- printf("e10k test started \n");
- err = e10k_queue_create(&queue, e10k_event_cb, /* interrupts*/ false,
- /* RSC*/false);
- if (err_is_fail(err)){
- USER_PANIC("Allocating devq failed \n");
- }
-
- q = (struct devq*) queue;
-
-
- printf("e10k test endned \n");
-}
-#endif
-
int main(int argc, char *argv[])
-{
+{
errval_t err;
// Allocate memory
err = frame_alloc(&memory_rx, MEMORY_SIZE, NULL);
USER_PANIC("Frame identify failed \n");
}
- err = vspace_map_one_frame_attr(&va_rx, MEMORY_SIZE, memory_rx,
+ err = vspace_map_one_frame_attr(&va_rx, id.bytes, memory_rx,
VREGION_FLAGS_READ, NULL, NULL);
if (err_is_fail(err)) {
USER_PANIC("Frame mapping failed \n");
USER_PANIC("Frame identify failed \n");
}
- err = vspace_map_one_frame_attr(&va_tx, MEMORY_SIZE, memory_tx,
+ err = vspace_map_one_frame_attr(&va_tx, id.bytes, memory_tx,
VREGION_FLAGS_WRITE, NULL, NULL);
if (err_is_fail(err)) {
USER_PANIC("Frame mapping failed \n");
phys_tx = id.base;
+ if (argc > 2) {
+ card = argv[2];
+ printf("Card =%s \n", card);
+ } else {
+ card = "e10k";
+ }
+
if (strcmp(argv[1], "net_tx") == 0) {
- test_sfn5122f_tx();
+ test_net_tx();
}
if (strcmp(argv[1], "net_rx") == 0) {
- test_sfn5122f_rx();
+ test_net_rx();
}
if (strcmp(argv[1], "idc") == 0) {
test_idc_queue();
}
-
- /*
- if (strcmp(argv[1], "e10k") == 0) {
- test_e10k_queue();
- }
- */
+
barrelfish_usleep(1000*1000*5);
}