1/*
2 * Copyright (c) 2007-12 ETH Zurich.
3 * All rights reserved.
4 *
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, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <barrelfish/barrelfish.h>
11//#include <barrelfish/nameservice_client.h>
12//#include <barrelfish/net_constants.h>
13#include <stdio.h>
14#include <string.h>
15#include <net_device_manager/net_ports_service.h>
16#include <net_device_manager/net_device_manager.h>
17
18#include "port_management_support.h"
19#include "device_manager_debug.h"
20
21
22/****************************************************************
23* Global datastructure
24*****************************************************************/
25
26/*****************************************************************
27* Prototypes
28*****************************************************************/
29
30// find out the proper filter manager based on requested type
31static struct filters_tx_vtbl *lookup_filt_mng(uint8_t filt_mng_type)
32{
33    switch(filt_mng_type) {
34        case 0: // software filter manager
35                return get_soft_filt_mng_sign();
36                break;
37
38        case 1: // e10K hardware filter manager
39                return get_e10k_filt_mng_sign();
40                break;
41
42        case 2: // Solarflare filter manager
43                return get_sfn5122f_filt_mng_sign();
44                break;
45
46        default: // Unknown filter manager
47                USER_PANIC("Filter Manager type %"PRIu8" not supported\n",
48                            filt_mng_type);
49                abort();
50                return NULL;
51                break;
52
53    } // end switch : for filter type
54    return NULL;
55} // end function: lookup_filt_mng
56
57
58// initializes the hardware independent part of device manager
59errval_t init_device_manager(char *dev_name, uint64_t valid_queues,
60        uint8_t filt_mng_type)
61{
62    // making sure that parameters passed are sensible
63    assert(dev_name != NULL);
64    assert(valid_queues > 0);
65    NDM_DEBUG("init_device_manager: called for dev[%s] with %"PRIu64" queues\n",
66            dev_name, valid_queues);
67
68    // making sure that this is the first call to this function
69    assert(qlist == NULL);
70    assert(total_queues == 0);
71
72    // set the total queues
73    total_queues = valid_queues;
74
75    // TODO: memory from local NUMA domain
76    qlist = (struct NIC_q_closure *)malloc (sizeof(struct NIC_q_closure) *
77                total_queues );
78    if (qlist == NULL) {
79        USER_PANIC("init_dev_mng: Not enough memory (malloc failed)\n");
80        return PORT_ERR_NOT_ENOUGH_MEMORY;
81    }
82
83
84    // Based on what device it is, choose proper filter_manager
85    struct filters_tx_vtbl *filt_mng_ptr = lookup_filt_mng(filt_mng_type);
86
87
88    // initialize closures for all queues
89    memset(qlist, 0, (sizeof(struct NIC_q_closure) * total_queues));
90    for (qid_t i = 0; i < total_queues; ++i) {
91        qlist[i].qid = i;
92        qlist[i].filt_mng = filt_mng_ptr;
93    } // for each queue
94
95    // Also, for shared queue (qid = 0), use soft_filt_mng
96    qlist[0].filt_mng = lookup_filt_mng(0);
97
98    return init_ports_service(dev_name);
99//    return SYS_ERR_OK;
100} // end function: init_device_manager
101
102