From: Roni Häcki Date: Tue, 11 Apr 2017 15:20:38 +0000 (+0200) Subject: solarflare: removed old management interface code X-Git-Tag: release2017-07-26~64^2~19 X-Git-Url: http://git.barrelfish.org/?p=barrelfish;a=commitdiff_plain;h=dbf9738cd8ecb180c7a8083b337911f210b7c33e solarflare: removed old management interface code Signed-off-by: Roni Häcki --- diff --git a/usr/drivers/solarflare/Hakefile b/usr/drivers/solarflare/Hakefile index 6048d20..86b38d3 100644 --- a/usr/drivers/solarflare/Hakefile +++ b/usr/drivers/solarflare/Hakefile @@ -13,18 +13,17 @@ [ build application { target = "sfn5122f", cFiles = [ "sfn5122f_cdriver.c", "mcdi_rpc.c", "helper.c", - "buffer_tbl.c", "sfn5122f_qdriver.c"], - flounderBindings = [ "sfn5122f", "net_ARP", "sfn5122f_devif", "net_filter"], + "buffer_tbl.c" ], + flounderBindings = [ "sfn5122f_devif", "net_filter"], flounderExtraBindings = [ ("sfn5122f_devif", ["rpcclient"]), ("net_filter", ["rpcclient"])], - flounderDefs = [ "sfn5122f", "sfn5122f_devif", "net_filter"], + flounderDefs = [ "sfn5122f_devif", "net_filter"], flounderExtraDefs = [ - ("net_ARP",["rpcclient"]), ("sfn5122f_devif",["rpcclient"]), ("net_filter",["rpcclient"]) - ], + ], mackerelDevices = [ "sfn5122f"], - addIncludes = [ "include", "/lib/net/include/" ], + addIncludes = [ "/lib/net/include/", "/lib/lwip-2.0.2/src/include/" ], addLibraries = libDeps["netQmng", "pci", "contmng", "net_device_manager", "bench", "trace", "skb", "spawndomain", "netd" , "net"] diff --git a/usr/drivers/solarflare/sfn5122f_cdriver.c b/usr/drivers/solarflare/sfn5122f_cdriver.c index 1626b5f..63728d1 100644 --- a/usr/drivers/solarflare/sfn5122f_cdriver.c +++ b/usr/drivers/solarflare/sfn5122f_cdriver.c @@ -11,16 +11,16 @@ #include #include -#include +#include #include -#include #include -#include +#include #include -#include #include -#include -#include + +// TODO only required for htonl +#include + #include #include #include @@ -28,8 +28,6 @@ #include "sfn5122f.h" #include "sfn5122f_debug.h" #include "buffer_tbl.h" -#include "sfn5122f_qdriver.h" - struct queue_state { uint64_t qid; @@ -37,7 +35,6 @@ struct queue_state { bool userspace; bool use_irq; - struct sfn5122f_binding *binding; struct sfn5122f_devif_binding *devif; struct capref tx_frame; struct capref rx_frame; @@ -93,10 +90,6 @@ static uint32_t phy_loopback_mode = 0; //WoL Filter id static uint32_t wol_filter_id = 0; -// ARP rpc client -//static struct net_ARP_binding *arp_binding; -//static bool net_arp_connected = false; - static bool csum_offload = 1; // TX / RX static uint32_t rx_indir_tbl[128]; @@ -189,28 +182,6 @@ static struct sfn5122f_filter_mac filters_tx_ip[NUM_FILTERS_MAC]; /******************************************************************************/ /* Prototypes */ -void qd_main(void) __attribute__((weak)); -void qd_argument(const char *arg) __attribute__((weak)); -void qd_interrupt(void) __attribute__((weak)); -void qd_queue_init_data(struct sfn5122f_binding *b, struct capref registers, - uint64_t macaddr) __attribute__((weak)); -void qd_queue_memory_registered(struct sfn5122f_binding *b) __attribute__((weak)); -void qd_write_queue_tails(struct sfn5122f_binding *b) __attribute__((weak)); - - -void cd_request_device_info(struct sfn5122f_binding *b); -void cd_register_queue_memory(struct sfn5122f_binding *b, - uint16_t queue, - struct capref tx, - struct capref rx, - struct capref ev, - uint32_t rxbufsz, - bool use_interrupts, - bool userspace, - uint8_t vector, - uint16_t core); - -static void idc_write_queue_tails(struct sfn5122f_binding *b); static void device_init(void); static void start_all(void); @@ -223,10 +194,6 @@ static void queue_hw_stop(uint16_t n); static void setup_interrupt(size_t *msix_index, uint8_t core, uint8_t vector); static void global_interrupt_handler(void* arg); -/* -static void bind_arp(struct waitset *ws); -static errval_t arp_ip_info(void); -*/ /***************************************************************************/ /* Filters */ @@ -289,7 +256,7 @@ static uint32_t build_key(struct sfn5122f_filter_ip* f) host1 = f->src_ip; host2 = f->dst_ip; - if (f->type_ip == sfn5122f_PORT_UDP) { + if (f->type_ip == net_filter_PORT_UDP) { port1 = f->dst_port; port2 = f->src_port; data[3] = 1; @@ -1189,134 +1156,6 @@ static void global_interrupt_handler(void* arg) /******************************************************************************/ /* Management interface implemetation */ -static void idc_queue_init_data(struct sfn5122f_binding *b, - struct capref registers, - uint64_t macaddr) -{ - errval_t r; - - r = sfn5122f_queue_init_data__tx(b, NOP_CONT, registers, macaddr); - // TODO: handle busy - assert(err_is_ok(r)); -} - -/** Tell queue driver that we are done initializing the queue. */ -static void idc_queue_memory_registered(struct sfn5122f_binding *b) -{ - errval_t r; - r = sfn5122f_queue_memory_registered__tx(b, NOP_CONT); - // TODO: handle busy - assert(err_is_ok(r)); -} - -/** Send request to queue driver to rewrite the tail pointers of its queues. */ -static void idc_write_queue_tails(struct sfn5122f_binding *b) -{ - errval_t r; - if (b == NULL) { - qd_write_queue_tails(b); - return; - } - - r = sfn5122f_write_queue_tails__tx(b, NOP_CONT); - // TODO: handle busy - assert(err_is_ok(r)); -} - -/** Request from queue driver for register memory cap */ -void cd_request_device_info(struct sfn5122f_binding *b) -{ - if (b == NULL) { - qd_queue_init_data(b, *regframe, d_mac[pci_function]); - return; - } - idc_queue_init_data(b, *regframe, d_mac[pci_function]); -} - -/** Request from queue driver to initialize hardware queue. */ -void cd_register_queue_memory(struct sfn5122f_binding *b, - uint16_t n, - struct capref tx_frame, - struct capref rx_frame, - struct capref ev_frame, - uint32_t rxbufsz, - bool use_irq, - bool userspace, - uint8_t vector, - uint16_t core) -{ - // Save state so we can restore the configuration in case we need to do a - // reset - errval_t err; - - bool failed = 0; - queues[n].enabled = false; - queues[n].tx_frame = tx_frame; - queues[n].rx_frame = rx_frame; - queues[n].ev_frame = ev_frame; - queues[n].tx_head = 0; - queues[n].rx_head = 0; - queues[n].ev_head = 0; - queues[n].rxbufsz = rxbufsz; - queues[n].binding = b; - queues[n].use_irq = use_irq; - queues[n].userspace = userspace; - queues[n].msix_index = -1; - queues[n].msix_intvec = vector; - queues[n].msix_intdest = core; - queues[n].qid = n; - - struct frame_identity id; - err = invoke_frame_identify(ev_frame, &id); - assert(err_is_ok(err)); - queues[n].ev_buf_tbl = init_evq(n, id.base, use_irq); - - - // enable checksums - err = invoke_frame_identify(tx_frame, &id); - assert(err_is_ok(err)); - queues[n].tx_buf_tbl = init_txq(n, id.base, csum_offload, userspace); - - err = invoke_frame_identify(rx_frame, &id); - assert(err_is_ok(err)); - queues[n].rx_buf_tbl = init_rxq(n, id.base, userspace); - - - if(queues[n].ev_buf_tbl == -1 || - queues[n].tx_buf_tbl == -1 || - queues[n].rx_buf_tbl == -1){ - failed = 1; - DEBUG("Allocating queue failed \n"); - return; - } - - queues[n].enabled = true; - - if (queues[n].use_irq) { - if (queues[n].msix_intvec != 0) { - if (queues[n].msix_index == -1) { - setup_interrupt(&queues[n].msix_index, queues[n].msix_intdest, - queues[n].msix_intvec); - } - } - } - - idc_write_queue_tails(queues[n].binding); - - if (b == NULL) { - qd_queue_memory_registered(b); - return; - } - - idc_queue_memory_registered(b); - - if (first){ - start_all(); - first = 0; - } -} - - static errval_t cd_create_queue_rpc(struct sfn5122f_devif_binding *b, struct capref frame, bool user, bool interrupt, bool qzero, uint8_t core, uint8_t msix_vector, @@ -1423,7 +1262,8 @@ static void cd_create_queue(struct sfn5122f_devif_binding *b, struct capref fram struct capref regs; - cd_create_queue_rpc(b, frame, user, interrupt, false, core, msix_vector, &mac, &queueid, ®s, &err); + cd_create_queue_rpc(b, frame, user, interrupt, false, core, + msix_vector, &mac, &queueid, ®s, &err); err = b->tx_vtbl.create_queue_response(b, NOP_CONT, mac, queueid, regs, err); assert(err_is_ok(err)); @@ -1488,7 +1328,7 @@ static void cd_destroy_queue(struct sfn5122f_devif_binding *b, uint16_t qid) queue_hw_stop(qid); queues[qid].enabled = false; - queues[qid].binding = NULL; + queues[qid].devif = NULL; err = b->tx_vtbl.destroy_queue_response(b, NOP_CONT, SYS_ERR_OK); assert(err_is_ok(err)); @@ -1502,7 +1342,7 @@ static void cd_control(struct sfn5122f_devif_binding *b, uint64_t request, struct queue_state *q = b->st; assert(q); - debug_printf("control arg=0x%lx\n", arg); + DEBUG("control arg=0x%lx\n", arg); struct sfn5122f_filter_ip f = { .dst_port = ((uint32_t)arg >> 16), @@ -1516,8 +1356,8 @@ static void cd_control(struct sfn5122f_devif_binding *b, uint64_t request, uint64_t fid; err = reg_port_filter(&f, &fid); - debug_printf("register filter: 0x%x:%u UDP=%u -> q=%u @ index=%lu %s\n",f.dst_ip, f.dst_port, - f.type_ip, f.queue, fid, err_getstring(err)); + DEBUG("register filter: 0x%x:%u UDP=%u -> q=%u @ index=%lu %s\n",f.dst_ip, + f.dst_port, f.type_ip, f.queue, fid, err_getstring(err)); err = b->tx_vtbl.control_response(b, NOP_CONT, fid, err); diff --git a/usr/drivers/solarflare/sfn5122f_qdriver.c b/usr/drivers/solarflare/sfn5122f_qdriver.c deleted file mode 100644 index 9b2486a..0000000 --- a/usr/drivers/solarflare/sfn5122f_qdriver.c +++ /dev/null @@ -1,378 +0,0 @@ -/* Copyright (c) 2017, ETH Zurich. - * All rights reserved. - * - * This file is distributed under the terms in the attached LICENSE file. - * If you do not find this file, copies can be found by writing to: - * ETH Zurich D-INFK, Universitätstrasse 6, CH-8092 Zurich. Attn: Systems Group. - */ -#include -#include -#include - -#include - -#include -#include - -#include "helper.h" -#include "sfn5122f.h" -#include "sfn5122f_queue.h" -#include "sfn5122f_debug.h" -#include "buffer_tbl.h" -#include "sfn5122f_qdriver.h" - -/** Queue index for this manager instance */ -static int qi = 0; - -/** Mackerel handle for device */ -static sfn5122f_t *d = NULL; - -/** Queue handle for queue management library */ -static sfn5122f_queue_t *q; - -/** MAC address to be used */ -static uint64_t mac_address = 0; - -/** Indicates if the initialization is done */ -static bool initialized = false; - -/** - * Indicates whether we should rely on cache coherence for the descriptor - * rings. - */ -static bool cache_coherence = true; - -/** Indicates whether Interrupts should be used */ -static bool use_interrupts = true; - -/** Capability for hardware TX ring */ -static struct capref tx_frame; - -/** Capability for hardware RX ring */ -static struct capref rx_frame; - -/** Capability for hardware EV ring */ -static struct capref ev_frame; - -//static void* mac_virt; -uint64_t mac_stats_array[NUM_MAC_STATS]; - - -/******************************************************************************/ -/* Transmit path */ -static uint64_t find_tx_free_slot_count_fn(void) -{ - return sfn5122f_queue_free_txslots(q); -} - -static errval_t transmit_pbuf_list_fn(struct driver_buffer *buffers, - size_t count) -{ - size_t i; - - if (find_tx_free_slot_count_fn() < count) { - return ETHERSRV_ERR_CANT_TRANSMIT; - } - - for (i = 0; i < count; i++) { - sfn5122f_queue_add_txbuf(q, buffers[i].pa, - buffers[i].len, buffers[i].opaque, - (i == count - 1)); - } - - sfn5122f_queue_bump_txtail(q); - - return SYS_ERR_OK; -} - -static bool handle_free_tx_slot_fn(void) -{ - return false; -} - - - -/******************************************************************************/ -/* Receive path */ - -static uint64_t find_rx_free_slot_count_fn(void) -{ - return sfn5122f_queue_free_rxslots(q); -} - -static errval_t register_rx_buffer_fn(uint64_t paddr, void *vaddr, void *opaque) -{ - if (find_rx_free_slot_count_fn() == 0) { - printf("SFN5122F_%d: Not enough space in RX ring, not adding buffer\n", - qi); - return ETHERSRV_ERR_TOO_MANY_BUFFERS; - } - - sfn5122f_queue_add_rxbuf(q, paddr, opaque); - sfn5122f_queue_bump_rxtail(q); - - return SYS_ERR_OK; -} - - -/* polling event queue for new events */ -static size_t check_for_new_events(void) -{ - size_t len = 0; - size_t count = 0; - uint8_t ev_code; - // TODO add constant - struct driver_rx_buffer buf[16]; - - // need to block until initalized - if (!initialized) { - return NIC_ERR_QDRIVER; - } - - ev_code = sfn5122f_get_event_code(q); - while (ev_code != 15 && count < 100){ - void *op = NULL; - ev_code = sfn5122f_get_event_code(q); - switch(ev_code){ - - case EV_CODE_RX: - // TODO multiple packets - if (sfn5122f_queue_handle_rx_ev(q, &op, &len) == SYS_ERR_OK) { - buf[0].len = len; - buf[0].opaque = op; - process_received_packet(buf, 1, 0); - } else { - DEBUG_QUEUE("Failed receiveing \n"); - // TODO how to tell the the upper layer that it can reuse - // the rx buffer - } - - DEBUG_QUEUE(" RX_EV Q_ID: %d len %ld \n", qi, len); - sfn5122f_queue_bump_evhead(q); - break; - case EV_CODE_TX: - if (sfn5122f_queue_handle_tx_ev(q) == SYS_ERR_OK) { - DEBUG_QUEUE("TX EVENT OK %d \n", qi); - uint8_t index = 0; - while (q->num_left > 0) { - handle_tx_done(q->bufs[index]); - index++; - q->num_left--; - } - } else { - DEBUG_QUEUE("TX EVENT ERR %d \n", qi); - } - sfn5122f_queue_bump_evhead(q); - break; - case EV_CODE_DRV: - DEBUG_QUEUE("DRIVER EVENT %d\n", qi); - sfn5122f_handle_drv_ev(q, qi); - sfn5122f_queue_bump_evhead(q); - break; - case EV_CODE_DRV_GEN: - DEBUG_QUEUE("DRIVER GENERATED EVENT \n"); - sfn5122f_queue_bump_evhead(q); - break; - case EV_CODE_USER: - DEBUG_QUEUE("USER EVENT \n"); - sfn5122f_queue_bump_evhead(q); - break; - case EV_CODE_MCDI: - DEBUG_QUEUE("MCDI EVENT \n"); - sfn5122f_queue_handle_mcdi_event(q); - sfn5122f_queue_bump_evhead(q); - break; - case EV_CODE_GLOBAL: - DEBUG_QUEUE("GLOBAL EVENT \n"); - sfn5122f_queue_bump_evhead(q); - break; - } - count++; - } - /* update event queue tail */ - //if (count > 0) { - sfn5122f_evq_rptr_reg_wr(d, qi, q->ev_head); - //} - - return count-1; -} - -/** Misc */ -static errval_t update_rxtail(struct sfn5122f_queue* que, void *opaque, size_t tail) -{ - assert(d != NULL); - uint64_t reg = 0; - - reg = sfn5122f_rx_desc_upd_reg_hi_rx_desc_wptr_insert(reg, tail); - /* don't want to push an additional rx descriptor with the write pointer */ - reg = sfn5122f_rx_desc_upd_reg_hi_rx_desc_push_cmd_insert(reg, 0); - /* the lower register will be ignored */ - sfn5122f_rx_desc_upd_reg_lo_wr(d, qi, 0); - sfn5122f_rx_desc_upd_reg_hi_wr(d, qi, reg); - - return SYS_ERR_OK; -} - -static errval_t update_txtail(struct sfn5122f_queue* que, void *opaque, size_t tail) -{ - assert(d != NULL); - uint64_t reg = 0; - reg = sfn5122f_tx_desc_upd_reg_hi_tx_desc_wptr_insert(reg, tail); - /* don't want to push an additional tx descriptor with the write pointer */ - reg = sfn5122f_tx_desc_upd_reg_hi_tx_desc_push_cmd_insert(reg, 0); - reg = sfn5122f_tx_desc_upd_reg_hi_tx_desc_insert(reg, 0); - - /* the lower register will be ignored */ - sfn5122f_tx_desc_upd_reg_lo_wr(d, qi, 0); - sfn5122f_tx_desc_upd_reg_hi_wr(d, qi, reg); - return SYS_ERR_OK; -} - -/** Callback to get card's MAC address */ -static void get_mac_address_fn(uint8_t* mac) -{ - memcpy(mac, &mac_address, 6); -} - -/******************************************************************************/ -/* Device/queue initialization */ - -/** Allocate queue n and return handle for queue manager */ - -static void setup_queue(struct capref* ev, struct capref* tx, struct capref* rx) -{ - size_t tx_size, rx_size, ev_size; - void *tx_virt, *rx_virt, *ev_virt; - vregion_flags_t flags_vreg; - - struct sfn5122f_queue_ops ops = { - .update_txtail = update_txtail, - .update_rxtail = update_rxtail - }; - - // Decide on which flags to use for the mappings - flags_vreg = (cache_coherence ? VREGION_FLAGS_READ_WRITE : - VREGION_FLAGS_READ_WRITE_NOCACHE); - - - /* Allocate memory for descriptor rings - No difference for userspace networking*/ - tx_size = sfn5122f_q_tx_ker_desc_size * TX_ENTRIES; - tx_virt = alloc_map_frame(flags_vreg, tx_size, tx); - - assert(tx_virt != NULL); - - rx_size = sfn5122f_q_rx_ker_desc_size * RX_ENTRIES; - - rx_virt = alloc_map_frame(flags_vreg, rx_size, rx); - assert(rx_virt != NULL); - - ev_size = sfn5122f_q_event_entry_size * EV_ENTRIES; - ev_virt = alloc_map_frame(flags_vreg, ev_size, ev); - assert(ev_virt != NULL); - - // Initialize queue manager - q = sfn5122f_queue_init(tx_virt, TX_ENTRIES, rx_virt, RX_ENTRIES, - ev_virt, EV_ENTRIES, &ops, NULL, false); -} - - - -void write_queue_tails(void) -{ - DEBUG_QUEUE("idc_write_queue_tails()\n"); - - sfn5122f_queue_bump_rxtail(q); - sfn5122f_queue_bump_txtail(q); -} - -size_t check_queue_0(void) -{ - do_pending_work_for_all(); - return check_for_new_events(); -} - -static void terminate_queue_fn(void) -{ - errval_t err; - err = terminate_queue_0(); - assert(err_is_ok(err)); -} - -// Callback from device manager -errval_t terminate_queue_0(void) -{ - errval_t err; - - DEBUG_QUEUE("idc_queue_terminated()\n"); - - // Free memory for hardware ring buffers - if (q->userspace) { - err = vspace_unmap(q->tx_ring.user); - if (err_is_fail(err)) { - return err; - } - err = vspace_unmap(q->rx_ring.user); - if (err_is_fail(err)) { - return err; - } - } else { - err = vspace_unmap(q->tx_ring.ker); - if (err_is_fail(err)) { - return err; - } - err = vspace_unmap(q->rx_ring.ker); - if (err_is_fail(err)) { - return err; - } - } - - err = vspace_unmap(q->ev_ring); - if (err_is_fail(err)) { - return err; - } - err = cap_delete(tx_frame); - if (err_is_fail(err)) { - return err; - } - err = cap_delete(rx_frame); - if (err_is_fail(err)) { - return err; - } - err = cap_delete(ev_frame); - if (err_is_fail(err)) { - return err; - } - return SYS_ERR_OK; -} - -errval_t init_queue_0(char* cname, uint64_t mac_addr, void* device, - bool interrupts, bool userspace, struct capref* ev, - struct capref* tx, struct capref* rx) -{ - use_interrupts = interrupts; - mac_address = mac_addr; - - d = malloc(sizeof(*d)); - sfn5122f_initialize(d, device); - // Initialize queue - setup_queue(ev, tx, rx); - - ethersrv_init((char*) cname, 0, - get_mac_address_fn, - terminate_queue_fn, - transmit_pbuf_list_fn, - find_tx_free_slot_count_fn, - handle_free_tx_slot_fn, - MTU_MAX, - register_rx_buffer_fn, - find_rx_free_slot_count_fn); - - tx_frame = *tx; - rx_frame = *tx; - ev_frame = *tx; - - initialized = true; - - return SYS_ERR_OK; -} diff --git a/usr/drivers/solarflare/sfn5122f_qdriver.h b/usr/drivers/solarflare/sfn5122f_qdriver.h deleted file mode 100644 index 8ebca81..0000000 --- a/usr/drivers/solarflare/sfn5122f_qdriver.h +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (c) 2017, ETH Zurich. - * All rights reserved. - * - * This file is distributed under the terms in the attached LICENSE file. - * If you do not find this file, copies can be found by writing to: - * ETH Zurich D-INFK, Universitätstrasse 6, CH-8092 Zurich. Attn: Systems Group. - */ - -#ifndef LIBQDRIVER_H_ -#define LIBQDRIVER_H_ - -void write_queue_tails(void); -size_t check_queue_0(void); -errval_t terminate_queue_0(void); -errval_t init_queue_0(char* cname, uint64_t mac_addr, void* device, - bool interrupts, bool userspace, struct capref* ev, - struct capref* tx, struct capref* rx); - -#endif