2 * Copyright (c) 2017, ETH Zurich.
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
10 #include <barrelfish/barrelfish.h>
11 #include <net/net_queue.h>
12 #include "networking_internal.h"
13 #include "net_queue_internal.h"
15 static errval_t create_loopback_queue(const char* cardname, inthandler_t interrupt, uint64_t *queueid,
16 bool default_q, bool poll, struct devq **retqueue)
20 debug_printf("net: creating loopback queue.\n");
23 err = loopback_queue_create((struct loopback_queue **)retqueue);
24 if (err_is_fail(err)) {
31 static errval_t create_driver_queue(const char* cardname, inthandler_t interrupt, uint64_t *queueid,
32 bool default_q, bool poll, struct devq **retqueue)
38 // cardname - "e1000:vendor:deviceid:bus:device:function"
39 static errval_t create_e1000_queue(const char* cardname, inthandler_t interrupt, uint64_t *queueid,
40 bool default_q, bool poll, struct devq **retqueue)
42 if (cardname[5] != ':') {
45 uint32_t vendor, deviceid, bus, device, function;
46 unsigned parsed = sscanf(cardname + 6, "%x:%x:%x:%x:%x", &vendor,
47 &deviceid, &bus, &device, &function);
51 return e1000_queue_create((struct e1000_queue**)retqueue, vendor, deviceid,
52 bus, device, function, 1, interrupt);
55 static errval_t create_e10k_queue(const char* cardname, inthandler_t interrupt, uint64_t *queueid,
56 bool default_q, bool poll, struct devq **retqueue)
60 printf("Default Q %d Interrupt %d \n", default_q, !poll);
62 err = e10k_queue_create((struct e10k_queue**)retqueue, interrupt,
63 false /*virtual functions*/,
64 !poll, /* user interrupts*/
66 *queueid = e10k_queue_get_id((struct e10k_queue*)*retqueue);
67 assert(retqueue != NULL);
71 static errval_t create_sfn5122f_queue(const char* cardname, inthandler_t interrupt, uint64_t *queueid,
72 bool default_q, bool poll, struct devq **retqueue)
75 err = sfn5122f_queue_create((struct sfn5122f_queue**)retqueue, interrupt,
76 false /*userlevel network feature*/,
77 !poll /* user interrupts*/,
79 *queueid = sfn5122f_queue_get_id((struct sfn5122f_queue*)*retqueue);
84 typedef errval_t (*queue_create_fn)(const char*, inthandler_t, uint64_t*, bool, bool, struct devq **);
85 struct networking_card
88 queue_create_fn createfn;
89 } networking_cards [] = {
90 { "loopback", create_loopback_queue},
91 { "driver", create_driver_queue},
92 { "e1000", create_e1000_queue},
93 { "e10k", create_e10k_queue},
94 { "sfn5122f", create_sfn5122f_queue},
100 * @brief creates a queue to the given card and the queueid
102 * @param interrupt interrupt handler
103 * @param cardname network card to create the queue for
104 * @param queueid queueid of the network card
105 * @param default_q get the default queue (most of the time queue 0)
106 * @param poll Is the queue polled or are interrupts used
107 * @param retqueue returns the pointer to the queue
109 * @return SYS_ERR_OK on success, errval on failure
111 errval_t net_queue_internal_create(inthandler_t interrupt, const char *cardname,
112 uint64_t* queueid, bool default_q, bool poll, struct devq **retqueue)
114 struct networking_card *nc = networking_cards;
115 while(nc->cardname != NULL) {
116 if (strncmp(cardname, nc->cardname, strlen(nc->cardname)) == 0) {
117 return nc->createfn(cardname, interrupt, queueid, default_q,
123 debug_printf("net: ERROR unknown queue. card='%s', queueid=%" PRIu64 "\n",
131 * @brief creates a queue to the given card and the queueid
133 * @param interrupt interrupt handler
134 * @param cardname network card to create the queue for
135 * @param queueid queueid of the network card
136 * @param poll Is the queue polled or are interrupts used
137 * @param retqueue returns the pointer to the queue
139 * @return SYS_ERR_OK on success, errval on failure
141 errval_t net_queue_create(inthandler_t interrupt, const char *cardname,
142 uint64_t* queueid, bool poll, struct devq **retqueue)
144 return net_queue_internal_create(interrupt, cardname, queueid, false, poll, retqueue);