1/**
2 * \file
3 * \brief LWIP test/demo code
4 */
5
6/*
7 * Copyright (c) 2013, University of Washington.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <stdio.h>
16#include <assert.h>
17#include <barrelfish/barrelfish.h>
18#include <netif/e1000.h>
19
20static ether_terminate_queue ether_terminate_queue_ptr = NULL;
21static ether_get_mac_address_t ether_get_mac_address_ptr = NULL;
22static ether_transmit_pbuf_list_t ether_transmit_pbuf_list_ptr = NULL;
23static ether_get_tx_free_slots tx_free_slots_fn_ptr = NULL;
24static ether_handle_free_TX_slot handle_free_tx_slot_fn_ptr = NULL;
25static ether_rx_register_buffer rx_register_buffer_fn_ptr = NULL;
26static ether_rx_get_free_slots rx_get_free_slots_fn_ptr = NULL;
27
28void ethernetif_backend_init(char *service_name, uint64_t queueid,
29                             ether_get_mac_address_t get_mac_ptr,
30                             ether_terminate_queue terminate_queue_ptr,
31                             ether_transmit_pbuf_list_t transmit_ptr,
32                             ether_get_tx_free_slots tx_free_slots_ptr,
33                             ether_handle_free_TX_slot handle_free_tx_slot_ptr,
34                             size_t rx_bufsz,
35                             ether_rx_register_buffer rx_register_buffer_ptr,
36                             ether_rx_get_free_slots rx_get_free_slots_ptr)
37{
38    ether_terminate_queue_ptr = terminate_queue_ptr;
39    ether_get_mac_address_ptr = get_mac_ptr;
40    ether_transmit_pbuf_list_ptr = transmit_ptr;
41    tx_free_slots_fn_ptr = tx_free_slots_ptr;
42    handle_free_tx_slot_fn_ptr = handle_free_tx_slot_ptr;
43    rx_register_buffer_fn_ptr = rx_register_buffer_ptr;
44    rx_get_free_slots_fn_ptr = rx_get_free_slots_ptr;
45    /* printf("PBUF_POOL_BUFSIZE = %u, rx buffer size = %zu\n", PBUF_POOL_BUFSIZE, */
46    /*        rx_bufsz); */
47}
48
49void process_received_packet(struct driver_rx_buffer *buffer, size_t count,
50                             uint64_t flags)
51{
52#if 0
53    // Drop packets with invalid checksums
54    if(flags & NETIF_RXFLAG_IPCHECKSUM) {
55        if(!(flags & NETIF_RXFLAG_IPCHECKSUM_GOOD)) {
56            goto out;
57        }
58    }
59
60    if(flags & NETIF_RXFLAG_L4CHECKSUM) {
61        if(!(flags & NETIF_RXFLAG_L4CHECKSUM_GOOD)) {
62            goto out;
63        }
64    }
65
66    // TODO: Do something with the packet
67
68 out:
69    //now we have consumed the preregistered pbuf containing a received packet
70    //which was processed in this function. Therefore we have to register a new
71    //free buffer for receiving packets.
72    errval_t err;
73    do {
74        err = rx_register_buffer_fn_ptr(p->pa, p->payload, p);
75    } while(err_is_ok(err));
76#endif
77}
78
79bool handle_tx_done(void *opaque)
80{
81    return true;
82}
83
84int main(int argc, char *argv[])
85{
86    uint8_t mac[6];
87
88    printf("Starting e10k control plane...\n");
89
90    e1000n_driver_init(argc, argv);
91
92    ether_get_mac_address_ptr(mac);
93    printf("Control plane MAC address %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
94           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
95
96    // TODO: Add buffers to RX ring for packet reception
97
98    for(;;) {
99        e1000n_polling_loop(get_default_waitset());
100    }
101
102    return 0;
103}
104